我对为什么文本没有浮动浮动div有点困惑。这是一个例子:
#placeholder {
float: left;
width: 12.5%;
height: 113px;
background: #000;
}

<p>DIRECTIONS<br> Preheat oven to 400°F. Line a muffin tin. Set aside. In a stand mixer fitted with a paddle attachment, cream together butter and sugar until light and fluffy. Meanwhile, using a blender, puree the diced pears, milk, and almond extract until
smooth.</p>
<div id="placeholder"></div>
&#13;
是因为浮动div是最后一个元素吗?我可以以某种方式实现这一点,但保留浮动div作为最后一个元素?谢谢!
答案 0 :(得分:1)
p
在浮动元素出现之前已经占据了整个宽度
#placeholder {
float: left;
width: 12.5%;
height: 113px;
background: #000;
}
<div id="placeholder"></div>
<p>DIRECTIONS<br> Preheat oven to 400°F. Line a muffin tin. Set aside. In a stand mixer fitted with a paddle attachment, cream together butter and sugar until light and fluffy. Meanwhile, using a blender, puree the diced pears, milk, and almond extract until
smooth.</p>
或者,如果您确实要保留订单,请将float:right
和width:87.5%
添加到p
元素。 87.5%
来自将浮动div的宽度减去p
元素的默认宽度(100%
)
p {
float: right;
width:87.5%;
}
#placeholder {
float: left;
width: 12.5%;
height: 113px;
background: #000;
}
<div id="placeholder"></div>
<p>DIRECTIONS<br> Preheat oven to 400°F. Line a muffin tin. Set aside. In a stand mixer fitted with a paddle attachment, cream together butter and sugar until light and fluffy. Meanwhile, using a blender, puree the diced pears, milk, and almond extract until
smooth.
</p>
注意:最好将clear:both
添加到浮动div之后的下一个元素,以避免放置并发症