将图像插入文本并使用 CSS 保持文本换行

发布于 2024-09-13 14:25:10 字数 435 浏览 10 评论 0原文

我刚刚遇到了一个我目前(几乎等于0)CSS知识无法处理的问题。事情是这样的:

我在 div 元素中有一些文本;这个 div 元素(我们称其为容器)具有固定宽度和动态高度(无限制)。我想在容器内放入一些文本;在文本的第二个单词之后,我想放置一个图像,以便整个事情看起来或多或少像这样:

+---------------------+
| I was [x] on my way |
| to the city in the  |
| sun                 |
+---------------------+

其中 [x] 是图像。文本的第二部分必须换行,以便所有内容都像上面的示例中那样。

容器中的文字可能会有所不同;尽管如此,我总是知道文本的哪一部分在图像之前,文本的哪一部分在图像之后。

我如何使用 CSS 做到这一点?

I've just encountered a problem that my current (almost equal to 0) CSS knowledge cannot deal with. Here's the thing:

I have some text inside of a div element; this div element (let's call it a container) has a fixed width and dynamic height (no constraints). I'd like to put some text inside of the container; after the second word of the text, I'd like to put an image so that the whole things looks more or less like that:

+---------------------+
| I was [x] on my way |
| to the city in the  |
| sun                 |
+---------------------+

where [x] is the image. It's important for the second part of the text to wrap so that everything looks like in the above example.

The text in the container may vary; nevertheless I always know which part of the text goes before and which part of the text goes after the image.

How do I do that with CSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-09-20 14:25:10

如果您将 标记放在文本中间,则默认情况下,除非您覆盖图像的 display 属性,否则情况应如此。您可能还想尝试使用图像的 vertical-align 属性,使其与周围的文本完美对齐。

If you put the <img> tag in the middle of your text, things should behave like that by default, unless you override the image's display property. You may also want to experiment with the image's vertical-align property to make it line up nicely with the surrounding text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文