CSS 中 HTML 的“<img align=top>”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1726243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML's "<img align=top>" in CSS?
提问by Pekka
How do I emulate
我如何模仿
<img align='top' src='huge_image.jpg'>
<span>I start at the top right corner of the image!</span>
in CSS?
在 CSS 中?
Maybe it's embarrassingly simple, but I really don't know.
也许这很简单,但我真的不知道。
采纳答案by Chris
It depends on the container of your elements. The vertical-align
CSS property doesn't exactly map to the valign
attribute. I recommend checking this link out for an explanation on how to achieve this with CSS. http://phrogz.net/CSS/vertical-align/index.html
这取决于元素的容器。该vertical-align
CSS属性并不完全映射到valign
属性。我建议查看此链接以获取有关如何使用 CSS 实现此目的的说明。http://phrogz.net/CSS/vertical-align/index.html
回答by ddango
float: left
will position it such that the img element will be to the left of the span, but if you are wanting to replicate align="top"
because of the vertical alignment issue (span at bottom right vs. top right), then try style="vertical-align: top;"
float: left
将其定位,使 img 元素位于跨度的左侧,但如果您align="top"
因为垂直对齐问题(跨度在右下角与右上角)而想要复制,那么请尝试style="vertical-align: top;"
回答by Zack The Human
I think you're looking for the vertical-alignCSS property.
我认为您正在寻找垂直对齐的CSS 属性。
<img style="vertical-align: top;" alt="blah" src="blah.jpg" />
Ideally you wouldn't just slap it directly on the <img>
tag, but instead use a CSS class.
理想情况下,您不会直接将其贴在<img>
标签上,而是使用 CSS 类。
回答by David says reinstate Monica
<style="text/css">
.top_aligned_image {vertical-align: top; /* or text-top, I can't remember for sure which works better */}
</style>
<img class="top_aligned_image" src='huge_image.jpg' /><span>I start at the top right corner of the image!</span>
Should do it.
应该做。
回答by Mark
edit:
编辑:
I think you want the span to be inline with the image. So display:inline should do move the span to the right.
我认为您希望跨度与图像一致。所以 display:inline 应该将跨度向右移动。
and
和
vertical-align:text-topshould move the image to the top.
vertical-align:text-top应该将图像移动到顶部。