完全中心图像和DIV

问题描述:

正如你可以在这里看到http://dekkro.no-ip.org/完全中心图像和DIV

我有两个div,一个在另一个之上。我希望他们成为100%死人中心。与顶部div,留在页面调整大小的中心。他们以我为中心,但对于很多人来说他们并不是。

我已经尝试使用边距和使用百分比,但仍然不完美。有没有解决这个问题?

我目前使用

position:absolute; left:32%; top:24%;margin: auto;z-index:-1; 

谢谢!

+0

你能告诉你正在谈论哪些div吗? – sinelaw

早在一天,我也像在这里描述:http://www.wpdfd.com/editorial/thebox/deadcentre4.html

也许现在有一个更好的更现代的方式,否则,你可以用它...

如果宽度和高度的股利已修复,您可以使用负边距将其居中。

例如,如果您有安全工程师一个div你可以居中这样说:

div { 
    position: absolute; 
    width: 300px; 
    height: 200px; 
    left: 50%; 
    top: 50%; 
    margin-left: -150px; 
    margin-top: -100px; 
} 
+0

我按照你的指示,现在图像是这样的 http://dekkro.no-ip.org/ 巅峰 – dekkytsh

+0

Ì检查了你的CSS,你在'margin-left'有正值, '保证金right'。他们需要消极。 –

+0

尝试更改:'margin-left:345px; margin-top:212.5px;'to-margin-left:-345px; margin-top:-212.5px;'并在image元素的style属性中删除'margin:auto'。 – Ackar

就瞎搞迅速对萤火虫:

<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%;"> 
+0

我用这个,它的工作原理,但是当我用另一个水库检查我的另一台计算机时,他们不再适用,例如... 请参阅图像:http://dekkro.no-ip.org /problem.png 我该如何解决这个问题? – dekkytsh

+0

我猜我必须把它放在一个div里面? – dekkytsh

+0

问题是第二个div的垂直对齐问题?我只显示了第一个div的解决方案... – Stobor