css - 使用 float 时文本对齐问题

标签 css

<style>
.floatright { float: right;margin: 0 0 10px 10px; }
p {float: left;}
</style>
<img class="floatright" src="computer.png" alt="" width="60" height="60">
<img class="floatright" src="computer.png" alt="" width="60" height="60">
<img class="floatright" src="computer.png" alt="" width="60" height="60">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>

问题:

为什么段落:<p>Lorem ipsum...</p>没有和imgs显示在同一行?它从 imgs 下面的行开始。

最佳答案

解决方案

删除 p 元素的 float 属性,如下所示:demo

解释

当将 p 元素的 float 属性设置为不同于 none 的值时,p 元素如果可用,将扩展到最大宽度,并且不接受任何其他 float 元素重叠在其区域上。

通过使用默认值(无 float ),p 元素将允许其他 float 元素占据一个区域,文本将填充其他空白。

关于css - 使用 float 时文本对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17802955/

相关文章:

html - 具有动态背景位置的微光效果?

css - 如何在行中显示 Highcharts(5)

html - 如何在此表中将边框设置为 0

html - 如何使用html打开电子邮件附件

html - CSS IE7 背景

css - IE 8 中的 HTML5 和 CSS 内联无序列表

html - Polymer 1.x 使用纸张输入插入图像

javascript - 互联网浏览器 : Issue with Overlay/opacity

html - 如何显示鼠标悬停时隐藏的文本?

javascript - jQuery 复制和粘贴使用 document.execCommand ("copy") 和 ("paste")