请考虑下面的例子:定位的div位置:绝对元素
正如你可以看到两个箱子重叠,而不是被定位为紧挨彼此float:left
财产。当我删除小孩.text
DIV时,这些框显示为他们应该。我认为这种行为来自.text
的position:absolute
属性,但为什么这会影响父DIV的外观?
HTML
<div class="box">
<div class='text'><span>Some text</span><div>
</div>
<div class="box">
<div class='text'><span>Some text</span><div>
</div>
CSS
.box {
position: relative;
display:inline-block;
width:100px;
height:100px;
background-color:#0000FF;
float:left;
}
.box:before {
content:'';
position: absolute;
left: 1%;
top: 1%;
width: 98%;
height: 98%;
border: 1px solid white;
}
.text {
position: absolute;
bottom:9px;
left:5px;
width: 95%;
text-align:left;
}
.text span {
color: white;
font: bold 12px/16px Helvetica, Sans-Serif;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 1px;
padding-left:3px;
padding-right:1px;
}
编辑:
我傻了,忘了关闭div标签。道歉。
Voopsy,傻我!如果你连续两天没有睡觉,情况就会如此。道歉。 – astralmaster