<i id='tVe05'><tr id='tVe05'><dt id='tVe05'><q id='tVe05'><span id='tVe05'><b id='tVe05'><form id='tVe05'><ins id='tVe05'></ins><ul id='tVe05'></ul><sub id='tVe05'></sub></form><legend id='tVe05'></legend><bdo id='tVe05'><pre id='tVe05'><center id='tVe05'></center></pre></bdo></b><th id='tVe05'></th></span></q></dt></tr></i><div id='tVe05'><tfoot id='tVe05'></tfoot><dl id='tVe05'><fieldset id='tVe05'></fieldset></dl></div>

      <legend id='tVe05'><style id='tVe05'><dir id='tVe05'><q id='tVe05'></q></dir></style></legend>
      <tfoot id='tVe05'></tfoot>
        <bdo id='tVe05'></bdo><ul id='tVe05'></ul>

      <small id='tVe05'></small><noframes id='tVe05'>

    1. 无论屏幕分辨率如何,我如何居中 javascript css popup div?

      时间:2023-10-01
      • <small id='XJEu6'></small><noframes id='XJEu6'>

          <tbody id='XJEu6'></tbody>

      • <tfoot id='XJEu6'></tfoot>

          <i id='XJEu6'><tr id='XJEu6'><dt id='XJEu6'><q id='XJEu6'><span id='XJEu6'><b id='XJEu6'><form id='XJEu6'><ins id='XJEu6'></ins><ul id='XJEu6'></ul><sub id='XJEu6'></sub></form><legend id='XJEu6'></legend><bdo id='XJEu6'><pre id='XJEu6'><center id='XJEu6'></center></pre></bdo></b><th id='XJEu6'></th></span></q></dt></tr></i><div id='XJEu6'><tfoot id='XJEu6'></tfoot><dl id='XJEu6'><fieldset id='XJEu6'></fieldset></dl></div>
            <bdo id='XJEu6'></bdo><ul id='XJEu6'></ul>

          • <legend id='XJEu6'><style id='XJEu6'><dir id='XJEu6'><q id='XJEu6'></q></dir></style></legend>

                本文介绍了无论屏幕分辨率如何,我如何居中 javascript css popup div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有以下代码在禁用背景的同时打开一个新的弹出窗口,问题是我必须定位它,使其距离顶部 100px(已经通过 CSS #dialog 得到)并且也在中心屏幕,不管用户的分辨率是多少?

                I have the following code that opens a new popup window while disabling the background, the problem is that I have to position this so that it's 100px from the top (already got that through the CSS #dialog) and also in the center of the screen, no matter what the user's resolution is?

                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                <html>
                <head>
                    <script type="text/javascript">
                        function showPopUp(el) {
                            var cvr = document.getElementById("cover")
                            var dlg = document.getElementById(el)
                            cvr.style.display = "block"
                            dlg.style.display = "block"
                            if (document.body.style.overflow = "hidden") {
                                cvr.style.width = "1024"
                                cvr.style.height = "100%"
                            }
                        }
                        function closePopUp(el) {
                            var cvr = document.getElementById("cover")
                            var dlg = document.getElementById(el)
                            cvr.style.display = "none"
                            dlg.style.display = "none"
                            document.body.style.overflowY = "scroll"
                        }
                    </script>
                    <style type="text/css">
                        #cover {
                            display:        none;
                            position:       absolute;
                            left:           0px;
                            top:            0px;
                            width:          100%;
                            height:         100%;
                            background:     gray;
                            filter:         alpha(Opacity = 50);
                            opacity:        0.5;
                            -moz-opacity:   0.5;
                            -khtml-opacity: 0.5
                        }
                
                        #dialog {
                            display:    none;
                            left:       100px;
                            top:        100px;
                            width:      300px;
                            height:     300px;
                            position:   absolute;
                            z-index:    100;
                            background: white;
                            padding:    2px;
                            font:       10pt tahoma;
                            border:     1px solid gray
                        }
                    </style>
                </head>
                <body>
                <div id="cover"></div>
                <div id="dialog">
                    My Dialog Content
                    <br><input type="text">
                    <br><input type="button" value="Submit">
                    <br><a href="#" onclick="closePopUp('dialog');">[Close]</a>
                </div>
                <a href="#" onclick="showPopUp('dialog');">Show</a>
                
                </body>
                </html>
                

                推荐答案

                基于CSS的解决方案居中:

                您需要使用这些样式来使其显得死心:

                You need to use these styles to make it appear dead-center:

                position:absolute;
                top:50%;
                left:50%;
                width:400px;  /* adjust as per your needs */
                height:400px;   /* adjust as per your needs */
                margin-left:-200px;   /* negative half of width above */
                margin-top:-200px;   /* negative half of height above */
                

                所以应该指定position.topleft 应该是 50%.margin-leftmargin-top 应该分别是盒子宽度和高度的负值的一半.

                So position should be specified. The top and left should be 50%. The margin-left and margin-top should be negative one half of the width and height of the box respectively.

                请注意,如果您希望您的弹出窗口即使在页面滚动时也显示在中心,您将不得不使用 position:fixed 来代替它在 IE6 中不起作用的缺点.

                Notice that if you want your popup to appear on center even when page is scrolled you will have to use position:fixed instead with the draw back that it doesn't work in IE6.

                这篇关于无论屏幕分辨率如何,我如何居中 javascript css popup div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:执行 oauth 时如何创建弹出窗口? 下一篇:如何通过弹出窗口获取输入并通过 javascript/jquery 将文本放入变量中

                相关文章

                <tfoot id='O7byj'></tfoot>

              1. <i id='O7byj'><tr id='O7byj'><dt id='O7byj'><q id='O7byj'><span id='O7byj'><b id='O7byj'><form id='O7byj'><ins id='O7byj'></ins><ul id='O7byj'></ul><sub id='O7byj'></sub></form><legend id='O7byj'></legend><bdo id='O7byj'><pre id='O7byj'><center id='O7byj'></center></pre></bdo></b><th id='O7byj'></th></span></q></dt></tr></i><div id='O7byj'><tfoot id='O7byj'></tfoot><dl id='O7byj'><fieldset id='O7byj'></fieldset></dl></div>
              2. <legend id='O7byj'><style id='O7byj'><dir id='O7byj'><q id='O7byj'></q></dir></style></legend>

                    <bdo id='O7byj'></bdo><ul id='O7byj'></ul>

                  <small id='O7byj'></small><noframes id='O7byj'>