【问题标题】:pop up to make it centre弹出使其居中
【发布时间】:2013-03-12 21:51:14
【问题描述】:

当我点击注册按钮时,弹出窗口打开...... 它在桌面上运行良好,但是当我缩小浏览器窗口时,弹出窗口会移动到浏览器的左下角.....\ iphone如何让弹窗居中.... 如何解决它....

在下面提供我的代码....

<div class="modal hide fade" id="signup-modal">
    <a class="close" data-dismiss="modal">&times;</a>
    <h1>Sign up </h1>
    <form method="POST" autocomplete="off" id="id_registerForm">
        <input type="hidden" name="usertype" value="3" readonly />
        <fieldset>      
        <input type="text" placeholder="Name" name="fullname" maxlength="30" required="required" id="id_username" />
        <input type="text" placeholder="Company" name="company" maxlength="30" required="required" id="id_company" />       
        <input type="email" placeholder="Email" name="email" maxlength="75" required="required" id="id_email" />
        <input type="password" placeholder="Password" name="password" required="required" id="id_password" />
        <input type="password" placeholder="Retype Password" name="repassword" required="required" id="id_repassword" />
        <textarea name="inquiry" placeholder="Inquiry" rows="3" required="required" id="id_inquiryForm" style="width:290px;"></textarea>
        <input id="id_signUp" type="button" value="Sign Up" class="btn">
        </fieldset>
        <!-- <a href="#myModal" role="button" data-toggle="modal"><span>Already have an account?</span> Log in</a> -->
    </form>
</div>

【问题讨论】:

  • 请提供相关的javascript和CSS。
  • 请删除所有不需要重现问题的代码;然后添加您使用的类的定义。否则真的很难回答你的问题!
  • 应用“margin:auto;”查询@media(最大宽度:767px)上的“myModal”div元素已经使用chrome开发工具在您的页面上进行了测试......

标签: javascript jquery css jquery-ui javascript-events


【解决方案1】:

您的模态窗口需要不同的样式

我在我的项目中使用它

@media screen and (max-width: 650px){
   /* my styles goes here */
}

现在你有了模态样式:

#signup-modal, #login-modal {
width: 300px;
padding: 0 40px;
background: #fff;
border: 5px solid rgba(0,0,0,0.2);
margin-left: -190px;
border-radius: 10px;
overflow: hidden;
margin-bottom: 40px;
box-shadow: 0 1px 0 white inset;
margin-top: -306px;}

这就是它出窗外的原因,您必须为smaller screens写其他styles

我尝试删除 margins 并将其设置为 margin: auto,我在 chrome 的检查元素中进行了此操作,但在调整大小时效果不佳,但如果您在本地计算机上执行此操作,则可以使用,也试试这个。如果没有,请转到@media screen。

这是一个很好的链接

http://css-tricks.com/snippets/css/media-queries-for-standard-devices/

【讨论】:

    【解决方案2】:

    我知道这一直是通过使用@media-screen 来解决的,但是当您在问题中标记 jQuery 时,我想我会提供一个替代解决方案。对于你所追求的可能有点OTT......但嘿,我喜欢它并且它有效。此外,它还不必为屏幕尺寸添加多个媒体查询。

    var sBox = $('#signup-modal');
    var uPos = function(){
       //Get sign-up box height and width
       sBoxHeight = parseInt(sBox.css('height'));
       sBoxWidth = parseInt(sBox.css('width'));
    
       //Get window height and width
       wHeight = window.innerHeight;
       wWidth = window.innerWidth;
    
       //Work out the position for the sign-up box
       sBoxTop = (wHeight/2) - (sBoxHeight/2);
       sBoxLeft = (wWidth/2) - (sBoxWidth/2);
    
       //Apply to the sign-up box
       sBox.css({
          margin:'0px',
          left:sBoxLeft - 55,
          top:sBoxTop
       });
    }
    
    //Apply on page load
    uPos();
    
    //Apply when window is resized
    $(window).resize(function(){
       uPos();
    });
    

    【讨论】:

    • 你能分享你的小提琴链接吗
    • @user2045025 我没有在 Fiddle 中执行此操作,而是在您的网站上进行了尝试,只需将我的脚本中的整个内容复制到您的 Web 控制台中,它就会起作用并覆盖您的所有 css 样式。给我 2 分钟,我会好好练习一下
    • 谢谢你能帮我解决这个问题stackoverflow.com/questions/15370619/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2015-05-04
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多