简体   繁体   中英

Styling images with CSS in ul li list

I'm stuck with a problem and hope stackoverfolw community can help me.

I want to put images with texts in listed order, so I'm using ul>li list. My problem begins when I write a paragraph that has less text than the image height, the next paragraph comes just next to it which I don't want. I know it is not well described so I'm attaching a image of it. 在此处输入图片说明 Here is the HTML of that screenshot

<ul><li>
<h2>title</h2>
<img src="" class="alignleft" width="200px"/> My text content
</li>
repeat the same again
</ul>

css for alignleft is

.alignleft{float:left;}

If I set the CSS to .alignleft{float:left;clear:both} then this problem solves but another problem rises.

Here is a screenshot of listed items styled with .alignleft{float:left;clear:both;} 在此处输入图片说明 The ad on the right has .alignright{float:right;} style. Because of the clear:both style there is no content with the ads.

Is there any option so that I can achieve both? Like the images below 在此处输入图片说明在此处输入图片说明

Use .alignleft{float:left;clear:left} to clear only the left directed floats.

See also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM