完全中心图像和DIV
问题描述:
正如你可以在这里看到http://dekkro.no-ip.org/完全中心图像和DIV
我有两个div,一个在另一个之上。我希望他们成为100%死人中心。与顶部div,留在页面调整大小的中心。他们以我为中心,但对于很多人来说他们并不是。
我已经尝试使用边距和使用百分比,但仍然不完美。有没有解决这个问题?
我目前使用
position:absolute; left:32%; top:24%;margin: auto;z-index:-1;
谢谢!
答
如果宽度和高度的股利已修复,您可以使用负边距将其居中。
例如,如果您有安全工程师一个div你可以居中这样说:
div {
position: absolute;
width: 300px;
height: 200px;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
答
就瞎搞迅速对萤火虫:
<div class="my_img"
style="position: absolute; top:50%; width: 100%;">
<img width="690"
height="425"
style=" margin: auto;z-index:-1; margin-top: -212px;"
src="http://dekkro.no-ip.org/images/testimage.png">
</div>
<div id="container"
style="position : absolute;
top : 0;
width : 100%;
margin-left : auto;
margin-right : auto;
height : 600px;
z-index : 5;">
如果你需要它保持居中时滚动,然后使第一行:
<div class="my_img"
style="position: fixed; top:50%; width: 100%;">
你能告诉你正在谈论哪些div吗? – sinelaw