开发者

HTML's "<img align=top>" in CSS?

How do I emulate

<im开发者_开发问答g align='top' src='huge_image.jpg'>
<span>I start at the top right corner of the image!</span>

in CSS?

Maybe it's embarrassingly simple, but I really don't know.


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;"


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


I think you're looking for the vertical-align CSS property.

<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.


<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.


edit:

I think you want the span to be inline with the image. So display:inline should do move the span to the right.

and

vertical-align:text-top should move the image to the top.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜