在一篇博文中(对于Cooking Stackexchange blog,所以一个普通的WordPress实例只有几个插件),我插入了三个图像,对齐到“左”,并希望它们占用自己的行。我希望文本从它们下面开始。
无论我尝试什么,(我手动插入了您在代码中看到的<p>
,<br>
和<div>
标签),文字都会在与图片相同的行上显示,可怕。我能做什么?
产生上述屏幕截图的代码:
<p> I expected a bigger difference between these 3 methods. The silicone mat browned the cookies a bit
less than the other methods – so it can provide a little insurance if
you’re afraid of burnt cookies. </p>
<div><img class="wp-image-870 alignleft" style="margin-left: 2px; margin-right: 2px;" title="baking sheet cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3784-225x300.jpg" alt="Cookies baked on baking sheet" width="225" height="300" /><img class="wp-image-869 alignleft" style="margin-left: 2px; margin-right: 2px;" title="silpat cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3787-225x300.jpg" alt="" width="225" height="300" /><img class="alignleft size-medium wp-image-868" style="margin-left: 2px; margin-right: 2px;" title="parchment paper cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3790-225x300.jpg" alt="" width="225" height="300" /><br/></div>
<p>I’m going to stick with parchment paper, because it offers one big
advantage over the bare sheet and silicone mat:
答案 0 :(得分:4)
您需要在<img />
之后清除浮动,以强制<div />
正确计算身高。
为此,请将style="overflow:hidden;
添加到开始<div>
标记中,以便更新的代码如下所示:
<p> I expected a bigger difference between these 3 methods. The silicone mat browned the cookies a bit less than the other methods – so it can provide a little insurance if you're afraid of burnt cookies. </p>
<div style="overflow:hidden;">
<img class="wp-image-870 alignleft" style="margin-left: 2px; margin-right: 2px;" title="baking sheet cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3784-225x300.jpg" alt="Cookies baked on baking sheet" width="225" height="300" />
<img class="wp-image-869 alignleft" style="margin-left: 2px; margin-right: 2px;" title="silpat cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3787-225x300.jpg" alt="" width="225" height="300" />
<img class="alignleft size-medium wp-image-868" style="margin-left: 2px; margin-right: 2px;" title="parchment paper cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3790-225x300.jpg" alt="" width="225" height="300" />
</div>
<p>I'm going to stick with parchment paper, because it offers one big advantage over the bare sheet and silicone mat:</p>
您可以在此处找到有关浮动的更多详细信息:http://css-tricks.com/all-about-floats/
答案 1 :(得分:1)
将clear:both
添加到该部门的CSS样式。
另外,为什么不为该分区中的图像添加一个类,那么你不必使用style=""
内联样式,如果你决定将来需要3px的余量,你只需在样式表中更改它而不是必须回顾所有以前的帖子。
答案 2 :(得分:1)
请尝试这样做 - 不需要清除,图像也会水平对齐:
<p>I expected a bigger difference between these 3 methods. The silicone mat browned the cookies a bit less than the other methods – so it can provide a little insurance if you’re afraid of burnt cookies.</p>
<p style="text-align: center;"><img class="wp-image-870 alignleft" title="baking sheet cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3784-225x300.jpg" alt="Cookies baked on baking sheet" width="225" height="300" /><img class="size-medium wp-image-868 alignright" title="parchment paper cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3790-225x300.jpg" alt="" width="225" height="300" /><img class="wp-image-869" title="silpat cookies" src="http://cooking.blogoverflow.com/files/2012/08/IMG_3787-225x300.jpg" alt="" width="225" height="300" /></p>
<p>I’m going to stick with parchment paper, because it offers one big advantage over the bare sheet and silicone mat:</p>
答案 3 :(得分:0)
Giv p
a min-width
以避免非常短的孤儿:
p {
min-width: 10em;
}