我理解,如果我浮动一个元素,下面的元素最终将消失在该元素的后面,如果它们本身没有浮点数集,或者至少清除浮点数。就像这个例子中的方框3一样。但是为什么方框3的内容跳出了div呢?该框的数字3或任何可能的内容不应该是Isn3吗?
<div class="box one">1</div>
<div class="box two">2</div>
<div class="box three">3</div>
.box {
text-align: center;
font-size: 30px;
color: red;
margin: 5px;
width: 200px;
height: 100px;
background: grey;
}
.two {
border: 2px solid red;
float: left;
opacity: 0.66;
}
.three {
opacity: 0.33
}*编辑:
这里还有一个例子来解释我不明白的问题。@Terry:好的,如果我缩小了第一个框的宽度,内容就跳上一行,进入div。但为什么一开始就没有呢?盒子完全是空的,难道没有足够的空间吗?
<div class="box one">1</div>
<div class="box two">2</div>
.box {
font-size: 40px;
margin: 5px;
width: 300px;
height: 150px;
}
.one{
float: left;
border: 5px solid rgba(255, 154, 188, 0.9);
background-color: rgba(255, 165, 0, 0.25);
}
.two {
position: relative;
top: 170px;
border: 5px solid rgba(35, 154, 255, 0.5);
background-color: rgba(100, 165, 255, 0.25);
}发布于 2015-09-01 20:10:02
尝尝这个。
.box {
text-align: center;
font-size: 30px;
display:block;
color: red;
margin: 5px;
width: 200px;
height: 100px;
line-height:100px;
background: grey;
}
.one{
border:1px solid green;
display:block;
}
.two {
border: 1px solid red;
opacity: 0.66;
}
.three {
border: 1px solid yellow;
opacity: 0.66;
}<div class="box one">1</div>
<div class="box two">2</div>
<div class="box three">3</div>
发布于 2015-09-01 20:12:08
是的,内容应该在方框3内,但是由于您已经设置了所有宽度相同的框,这意味着框3中的内容不能推到一边,而只能推到底部--如果缩小了框3的宽度,您可以看到浮点与方框3的内容是如何交互的:
.box {
text-align: center;
font-size: 30px;
color: red;
margin: 5px;
width: 200px;
height: 100px;
background: grey;
}
.two {
border: 2px solid red;
float: left;
opacity: 0.66;
width: 25px;
}
.three {
opacity: 0.3;
}<div class="box one">1</div>
<div class="box two">2</div>
<div class="box three">3 random content here</div>
https://stackoverflow.com/questions/32340004
复制相似问题