使用:之后清除浮动元素 [英] Using :after to clear floating elements

查看:97
本文介绍了使用:之后清除浮动元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,li的有 float:left; < ul> 后的内容应正确对齐。因此,我可以建立以下内容:

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/

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

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

但示例不起作用:

http://jsfiddle.net/EyNnk/

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

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/

这篇关于使用:之后清除浮动元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆