我不能用百分比移动div

时间:2013-06-07 18:55:23

标签: css html percentage

我想将div移到底部,但如果我用百分比写,它就不会移动,但以像素为单位可以工作。

这是css:

 <style type="text/css">
  html
 {
 width:100%;
 height:100%;
  overflow-x:hidden;
  overflow-y:auto;
   }
  div#container
   {
position:relative;
width: 100%;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
text-align:left; 
  }
  #g_image3
  {
  width: 100%;
  }
  body {text-align:center;margin:0}
   </style>`

这是html:

 <body bgColor="#000000">
 <div id="container">
  <div id="g_image3" style="position:absolute; overflow:hidden; left:0px; top:0px; z-   
 index:1"><img src="images/top_bg.jpg" alt="" title="" border=0 width="100%"   
 heigth="100%"></div>
  <div id="g_image4" style="position:absolute; overflow:hidden; left:0px; top: 10%;       
  width:265px; height:400px; z-index:1"><img src="images/content1.png" alt="" title=""   
  border=0 width=265 height=400></div>
 </div>
 </body>

Here is a link with the picture of a page

我想将g_image4移到底部,但它仍然保持不变 如果我用百分比写它,坚持g_image3。在像素中它可以工作但我需要它以百分比nto为单位。 我在哪里弄错了?我不明白为什么它不动......

1 个答案:

答案 0 :(得分:1)

您在height: 100%元素上设置了html,但在body#container元素上忽略了这一点。这会导致body#container元素的高度为0,因为它们中没有静态或相对定位的内容来为它们提供高度。

相关问题