将图像插入文本并使用 CSS 保持文本换行
我刚刚遇到了一个我目前(几乎等于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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将
标记放在文本中间,则默认情况下,除非您覆盖图像的
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'sdisplay
property. You may also want to experiment with the image'svertical-align
property to make it line up nicely with the surrounding text.