[英]how to resolve popup center screen Div class?
I have a div
with class .popup
. 我有一个div
类.popup
。 I have an iFrame used to open another image gallery, but when I show the popup using jQuery it isn't centered and the top most page element. 我有一个iFrame用于打开另一个图库,但是当我使用jQuery显示弹出窗口时,它不是居中和最顶层的页面元素。
CSS CSS
.popup {
border: 1px solid #ccc;
width:inherit;
border-radius: 7px;
margin-right: auto;
margin-left:auto;
padding: 20px;
position:absolute;
z-index: 1000;
background-color: #f0f0f0;
height:400px;
}
HTML HTML
<div class="popup " style="display: none">
<div class="col-lg-12" style="padding-bottom: 10px;">
<input onclick='SelectImage(inputImage)' class="btn btn-xs btn-success pull-left" type="button" value=" بازگشت " />
<input id="btnImageSelect" onclick='SelectImage(inputImage)' class="btn btn-xs btn-success" type="button" value="تایید عکس" />
</div>
<iframe id="iframeImage" src="../filemanager/ImagePicker.aspx" width="100%" height="320" frameborder="1"></iframe>
</div>
How do I fix this problem and where is my lost code? 如何解决此问题以及丢失的代码在哪里?
$(document).ready(function(){
var width = $(.popup).width();
var height = $(.popup).height();
$(".popup").css({"top":"50%", "left":"50%", "margin-top":height/2+"px", margin-left:width/2+"px"});
});
This will move the div
in center. 这会将div
移动到中心位置。
I'm not sure what you're looking for with width: inherit
. 我不确定你在寻找width: inherit
。 This will always make your popup as wide as its parent element, so there's no need for centering. 这将始终使您的弹出窗口与其父元素一样宽,因此不需要居中。 With position: absolute
, however, your popup will be positioned according to either the body
element of your page, or a parent element with position: relative
. 但是,对于position: absolute
,您的弹出窗口将根据页面的body
元素或position: relative
的父元素进行position: relative
。
Here's what I'd do if I understand your problem correctly: 如果我正确理解你的问题,这就是我要做的事情:
I'm assuming width
is unknown here. 我假设width
在这里是未知的。
.popup {
...
position: absolute;
margin: 0;
left: 50%;
transform: translateX(-50%);
}
Here's a fiddle: http://jsfiddle.net/ugys4znt/ 这是一个小提琴: http : //jsfiddle.net/ugys4znt/
If you want the popup to stay on screen even when the user scrolls, use position: fixed
. 如果您希望弹出窗口即使在用户滚动时仍保持在屏幕上,请使用position: fixed
。
Please specify some more what you're trying to achieve with width: inherit
, and I'll get back to you. 请详细说明您尝试使用width: inherit
实现的内容width: inherit
,我会回复您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.