我正在创建叠加层。有一个div用50%透明的黑色涂在整个页面上。另一个div必须居中,垂直和水平的屏幕。它必须绝对定位。无论如何不知道高度/宽度来做到这一点?它将根据屏幕资源改变。当你知道高度和宽度(即左:50%;左:-150px;上:50%; margin-top:-300px;)时,我熟悉绝对定位定心技术......但是,我能否在不知道高度/宽度的情况下做到这一点? 这里是代码:以绝对定位为中心不知道宽度或高度
.hiddenBg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: black;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
z-index: 10000;
/*display: none;*/
}
.hiddenBox {
position: absolute;
left: 50%;
margin-left: -200px;
top: 50%;
margin-top: -100px;
width: auto;
height: auto;
background-color: #FF7F00;
border: solid 10px white;
z-index: 10001;
text-align: center;
/*display: none;*/
}
是那些数字的动态?你可以使用JS来获得宽度和高度吗? –
查看* [以未知为中心](http://css-tricks.com/centering-in-the-unknown/)*。 –
看起来像一个新的[CSS灵活框](https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_flexible_boxes)规范的工作,但它们远远没有完成或支持。 – thirdender