CSS 将图像浮动到标题左侧
如果我想将图像浮动到标题的左侧,我通常这样做的方式是这样的:
<img src="html5_connectivity.svg" width="90" height="90" alt="[HTML5 Connectivity Logo]" class="FloatLeft" />
<h3 data-anchorid="sockets">Connectivity</h3>
我想要的是相同的视觉效果,将图像浮动到标题的左侧,但将图像标签放在后面文档中的标题如下:
<h3 data-anchorid="sockets">Connectivity</h3>
<img src="html5_connectivity.svg" width="90" height="90" alt="[HTML5 Connectivity Logo]" class="FloatLeft" />
我无法弄清楚哪些 CSS 技巧(最好是 CSS Level 2.1)可以实现这一点。有什么建议吗?
If I want to float an image to the left of a heading, the way I typically do it is something this:
<img src="html5_connectivity.svg" width="90" height="90" alt="[HTML5 Connectivity Logo]" class="FloatLeft" />
<h3 data-anchorid="sockets">Connectivity</h3>
Want I want is the same visual effect, float the image to the left of the heading, but have the image tag come after the heading in the document, like this:
<h3 data-anchorid="sockets">Connectivity</h3>
<img src="html5_connectivity.svg" width="90" height="90" alt="[HTML5 Connectivity Logo]" class="FloatLeft" />
I can not figure out what CSS tricks (preferably CSS Level 2.1) will accomplish that. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会在
h3
上放置左边距或填充,并在img
上放置负上边距。I would put a left margin or padding on the
h3
and a negative top margin on theimg
.您可以为标题设置页边距,然后图像将一直显示到末尾,标题将在其之后。
You can set margin-left for your header then your image will go till the end and header will be after it.
如果您知道图像的确切尺寸,这将起作用:
澄清一下:这只是使用默认文档流并相对地重新定位图像。不过,只有当您确切知道尺寸时,这才有效。在你的 CSS 中,你必须考虑填充和边距。
If you know the exact dimensions of the image, this will work:
To clarify: This just uses the default document flow and repositions the image relatively. This will only work when you know the sizes exactly, though. In your css you would have to take padding and margin into account.