gpt4 book ai didi

html - 如何将文本与图像顶部对齐?

转载 作者:太空宇宙 更新时间:2023-11-03 22:35:41 24 4
gpt4 key购买 nike

我的左边有一张图片,我想将文字排到图片的顶部。

我在 this 中有以下代码jsfiddle:

<div>
<img src... >
<span>hello hello hello hello hello hello...</span>
</div>

但它会将文本沿图像底部对齐,如下所示:

enter image description here

如何让文本从顶部围绕图像排列?

最佳答案

这是使用 float 的典型案例:

The float CSS property specifies that an element should be placed along the left or right side of its container, allowing text and inline elements to wrap around it.

只需添加 float: left;给你的<img>元素和文本将从图像的顶部开始。

img {
float: left;
margin-right: 1em;
}
<div>
<img src="http://placehold.it/100x100/E8117F/000.png">
<span style="vertical-align:text-top">hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello</span>
</div>

关于html - 如何将文本与图像顶部对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46615177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com