CSS 是否有可能阻止文本块围绕浮动块换行?

4
我的问题是,我有一个页面上有很多段落,每个段落的高度在2到20行之间。
可以有任意数量的段落,每个段落的高度也不同。
使用HTML5,CSS3,
我的最初目标是将图像添加到这种格式中并向左和右浮动,文本围绕其周围包裹,这很容易实现。
但是现在,客户希望环绕图像底部的段落保持一致,试举例如下:
(参考下面的键:### = 图像空间/形状/内容)
所以: 发生的情况是:
####### <p>text text here for this paragraph
###I### text here for this paragraph line 2
###M### text here for this paragraph line 3</p>
###A### 
###G### <p>text here for paragraph 2
###E### text here for paragraph 2, line 2, etc</p>
####### 
####### <p>text here for paragraph 3 line 1
text here for paragraph 3 line 2,
etc etc. </p>

...

但是,我想实现的是一种动态的CSS方式,如下所示:
####### <p>text text here for this paragraph
###I### text here for this paragraph line 2
###M### text here for this paragraph line 3</p>
###A### 
###G### <p>text here for paragraph 2
###E### text here for paragraph 2, line 2, etc</p>
####### 
####### <p>text here for paragraph 3 line 1
        text here for paragraph 3 line 2,
        etc etc.</p>

<p>text here for Paragraph 4 states not indented to 
make room text for the image floated left. text.
text text text text</p>

....

因为第三段中的P标签在图像仍然存在时开始,所以整个段落都应该缩进。有没有比较动态的方法来实现这一点?
如果我在CSS中为段落标签应用任何缩进规则,它们也会缩进像第4段这样没有左侧图像的段落。
如果我将段落标签设置为inline-Block,这是我在SO上读到的另一个类似问题的解决方案,那么整个段落直到图像后才出现,打破了页面流程。
如果我不浮动图像,最好的内联方式是什么?我无法保证页面上的图像数量。
我不能在图像figure元素的底部添加像填充或边距这样的空格,因为我不知道段落会持续多长时间。
进一步澄清:我的图像目前是浮动的,并且工作得非常好。
免责声明:我有点累了。现在很晚了。但是我想如果这个问题有一个相对简单的答案,它可能对其他人和我自己都有用,并且可以节省我明天早上的几个小时...
PS-> 我找不到解决方案可能是我无法简洁地描述我的问题,如果有关于此问题的简洁描述,请让我知道!干杯。

将图像放入一个容器中,并将其向左浮动。将文本放入另一个容器中,并将其向右浮动。 - emerson.marini
尝试了那个建议,将段落标签放在一个浮动的div右侧,MelanciaUK,现在文本出现在图像下方。很抱歉,这不是一个解决方案。 - Martin
创建一个 jsFiddle 来展示一些例子。 - emerson.marini
我会在早上添加一个 Fiddle。 - Martin
看到@MarcAudet的答案,我现在明白你想要什么了。 - emerson.marini
好的好的,这样可以省去我折腾的时间!;) - Martin
1个回答

6

如果您在 p 元素上添加 overflow: auto,它们将形成新的块级格式化上下文,并且其内容将被限制在段落边框的范围内。

img {
  float: left;
}
p {
  width: 170px;
  overflow: auto;
  }
<img src="http://placehold.it/100x180">
 <p>text here for paragraph 3 line 1
    text here for paragraph 3 line 2,
    etc etc. </p>
 <p>text here for paragraph 3 line 1
    text here for paragraph 3 line 2,
    etc etc. </p>
 <p>text here for paragraph 3 line 1
    text here for paragraph 3 line 2,
    etc etc. </p>
 <p>text here for paragraph 3 line 1
    text here for paragraph 3 line 2,
    etc etc. </p>


1
太好了!Overflow Auto 完美地解决了它,谢谢 Marc! - Martin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接