开发者

CSS flow justified text around an image

开发者 https://www.devze.com 2022-12-13 05:23 出处:网络
tring to flow text around an image: HTML <div> <span id=\"photo\"><img src=\"photo.png\"</span>

tring to flow text around an image:

HTML

<div>
  <span id="photo"><img src="photo.png"</span>
  <span id="text">Lorem Ipsum, blah, blah, blah ...</span>
</div>

CSS

#photo {float:left;margin:0px 8px 5px 0px;}
#text {text-align:justify;}**

The text flows around the image, but it is not justi开发者_开发技巧fied (alignment is left). If I float the text element left, then the alignment is correct (justified, as I want), but then the text does not flow around the image, rather it flows below the image - how can I fix this?


The text-align property actually belongs on the enclosing block element not the inline element. So move it to the enclosing block:

div { text-align: justify; }

See 16.2 Alignment: the 'text-align' property of the Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification:

This property describes how inline content of a block is aligned. Values have the following meanings:

(emphasis added)


You need to either take the image out of the span, or float the span left.

0

精彩评论

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