阻止文字环绕图像

阻止文字环绕图像

我想阻止文字环绕图像。有没有不使用margin的方法?

img {
  margin-bottom: 2.5em;
}
<strong><img style="float: left;" src="https://www.google.com/images/srpr/logo11w.png" width="100" height="67" />Text here. Text here. Text here. Text here.
    <br />Text here. Text here. Text here. Text here. Text here. Text here.
    <br />Text here. Text here. Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.
    <br />Text here. Text here.Text here. Text here.Text here. Text here.


JSFiddle Demo

最佳答案

您必须将文本包装在其自己的容器中。

由于<img> float 在左侧,因此可以在新添加的容器上使用overflow: hidden来实现文本不换行。

但是,块元素不应该是<strong>元素的后代,您可能需要重新考虑此标记。

img {
    width:100px;
    height:67px;
    float:left;
}
div {
    overflow:hidden;
}
<article>
    <img src="https://www.google.com/images/srpr/logo11w.png" />
    <div>
        Text here. Text here. Text here. Text here.<br />
        Text here. Text here. Text here. Text here. Text here. Text here.<br />
        Text here. Text here. Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.<br />
        Text here. Text here.Text here. Text here.Text here. Text here.
        Text here. Text here. Text here. Text here.<br />
        Text here. Text here. Text here. Text here. Text here. Text here.<br />
        Text here. Text here. Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.Text here. Text here.<br />
        Text here. Text here.Text here. Text here.Text here. Text here.
    </div>
</article>


JSFiddle

关于html - 阻止文字环绕图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26510738/

10-09 16:51