使用:清除浮动元素后(Using :after to clear floating elements)

系统教程 行业动态 更新时间:2024-06-14 17:03:52
使用:清除浮动元素后(Using :after to clear floating elements)

我有一个清单,李的有一个float:left; 。 <ul>之后的内容应正确对齐。 所以我可以建立以下内容:

http://jsfiddle.net/8unU8/

我想,我可以通过使用伪选择器来删除<div class="clear"> ,如:after。

但这个例子是不行的:

http://jsfiddle.net/EyNnk/

我总是要创建一个单独的div来清除浮动元素?

I have a list and the li's have a float:left;. The contents after the <ul> should be aligned correctly. Therefore i can build the following:

http://jsfiddle.net/8unU8/

I thought, that I can remove the <div class="clear"> by using pseudo selectors like :after.

But the example is not working:

http://jsfiddle.net/EyNnk/

Do I always have to create a separate div to clear floating elements?

最满意答案

这样写:

.wrapper:after { content: ''; display: block; clear: both; }

检查这个http://jsfiddle.net/EyNnk/1/

Write like this:

.wrapper:after { content: ''; display: block; clear: both; }

Check this http://jsfiddle.net/EyNnk/1/

更多推荐

http,jsfiddle,clear,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-04-24 12:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/5a8e297a24c8ed6cc0181957328ff4e8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   clear   elements   floating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!