【发布时间】:2014-04-18 00:51:04
【问题描述】:
我正在尝试在 DIV 的末尾添加两个图像 (ul,li)。我使用位置 ABSOLUTE、RELATIVE 和 left:0, bottom:0,它确实做到了,但它不会保留在 div 上。
图像出现在“MainDiv”中,而不是“容器”中。
css:
#MainDiv{
background:url(../img/background.jpg) no-repeat;
background-size:cover;
width:100%;
height:600px;
}
#container{
width:980px;
height:600px;
margin:0 auto;
position:relative;
}
#list{
width:260px;
height:40px;
position:absolute;
left:0;
bottom:0;
}
#list li{
width:130px;
height:40px;
border:1px solid white;
}
HTML:
<div id="MainDiv">
<div id="container">
<ul id="list">
<li id="image1">Example1</li>
<li id="image2">Example2</li>
</ul>
</div>
</div>
【问题讨论】:
-
我认为您的代码没有问题,除了 #container 根本没有高度,因为内容不流畅
-
因为
<li>的绝对定位在技术上你的 div 是 0px 高。尝试为其设置高度。 -
谢谢大家,但我实际上在“容器”中有一个高度。代码太长,无法在此处复制粘贴。 “MainDiv”是width:100% and height:600px,“container”是width:980px and height:600px