方法一、

这个方法来源于positioniseverything ,通过after伪类实现,完全兼容当前主流浏览器。

 1 <style type="text/css">
2 .clearfix:after {
3 content: ".";
4 display: block;
5 height: 0;
6 clear: both;
7 visibility: hidden;
8 }
9 .clearfix {display: inline-block;} /* for IE/Mac */
10 </style>
11 <!-- main stylesheet ends, CC with new stylesheet below... -->
12 <!--[if IE]>
13 <style type="text/css">
14 .clearfix {
15 zoom: 1; /* triggers hasLayout */
16 display: block; /* resets display for IE/Win */
17 }
18 /* Only IE can see inside the conditional comment
19 and read this CSS rule. Don't ever use a normal HTML
20 comment inside the CC or it will close prematurely. */
21 </style>
22 <![endif]-->

方法二、

还有一个无敌的清除浮动的样式,这个是通过独立的代码来清除的。

 1 html body div.clear,
2 html body span.clear
3 {
4 background: none;
5 border: 0;
6 clear: both;
7 display: block;
8 float: none;
9 font-size: 0;
10 margin: 0;
11 padding: 0;
12 overflow: hidden;
13 visibility: hidden;
14 width: 0;
15 height: 0;
16 }

可以通过在页面div中添加clear样式来清除页面中的浮动。

1 <div class=”clear”>
2 </div>
3 或
4 <span class=”clear”>
5 </span>

方法三、

实际项目中常用如下代码:

1 .clear:after {
2 clear: both;
3 content: " ";
4 display: block;
5 height: 0;
6 overflow: hidden;
7 visibility: hidden;
8 }

使用方法如下:

1 <div class="clear">
2 <div class="title">标题<div>
3 <div class="content">内容</div>
4 </div>

div标签清除float浮动样式方法的更多相关文章

  1. 【转】CSS清除浮动_清除float浮动

    CSS清除浮动方法集合 一.浮动产生原因 一般浮动是什么情况呢?一般是一个盒子里使用了CSS float浮动属性,导致父级对象盒子不能被撑开,这样CSS float浮动就产生了. 浮动产生样式效果截图 ...

  2. CSS 之 清除 float 常用的方法

    大多数前端使用.clearfix:after{ .....}  和 .clearit{....}的组合来清除浮动. 前端开发经常用到浮动 float:left; float:right; 有浮动就需要 ...

  3. CSS清除浮动_清除float浮动

    2.clear:both清除浮动为了统一样式,我们新建一个样式选择器CSS命名为“.clear”,并且对应选择器样式为“clear:both”,然后我们在父级“</div>”结束前加此di ...

  4. CSS清除float浮动

    一.浮动产生原因   -   TOP 一般浮动是什么情况呢?一般是一个盒子里使用了CSS float浮动属性,导致父级对象盒子不能被撑开,这样CSS float浮动就产生了. 本来两个黑色对象盒子是在 ...

  5. 清除float浮动造成影响的几种解决方案

    1. “清除浮动” ??准确的描述应该是“清除浮动造成的影响”  学习浮动推荐的视频教程<CSS深入理解之float浮动> 2.如何清除浮动造成的影响??? 栗子 块级div元素包含一个内 ...

  6. 清除float浮动三种方式

    Float的作用? w3c的官方解释: Content flows down the right side of a left-floated box and down the left side o ...

  7. 子div用了float浮动之后,如何撑开父元素,让父元素div自动适应高度的问题

    方法一: html: <div id="all1"> <div id="left1">1</div> <div id= ...

  8. 关于css清除元素浮动的方法总结(overflow clear floatfix)

    在前两天的一个面试中考官问我web中清除浮动的一些css常用方法,我很轻松的答出了: 1.overflow:hidden 2.clear:both 3.floatfix类 然后问题就来了,考官接着问' ...

  9. DIV CSS float浮动

    一.浮动? #CSS样式的float浮动属性,用于设置标签对象(如:<div>标签盒子.<span>.<a>.等html标签)的浮动布局. #通过定义浮动(floa ...

随机推荐

  1. SpringMVC学习资料

    一.SpringMVC 1.helloworld 1.导包 <dependency> <groupId>org.springframework</groupId> ...

  2. ORA-00245问题总结

    (1)问题描述 在进行数据库归档备份时(备份归档日志文件和控制文件),有时成功,有时失败,失败报错如下: RMAN-00571: =================================== ...

  3. cesium自定义气泡窗口infoWindow后续优化篇

    http://www.cnblogs.com/giserhome/p/6248858.html该篇文章实现的自定义气泡窗口是基于修改cesium源代码基础上,这种做法只是援兵之计,凑合应付的,投机取巧 ...

  4. 开源Inno Setup官网下载、安装、打包教程(官网安装向导中文语言包)

    安装Inno Setup篇 1.搜索Inno Setup 2.下载Inno Setup 3.选择下载最新 innosetup-5.5.9-unicode.exe 版本(innosetup-5.5.9. ...

  5. [leetcode-593-Valid Square]

    Given the coordinates of four points in 2D space, return whether the four points could construct a s ...

  6. Chapter 3. Video Coding Concepts

    本章主要介绍一些有关视频编码的概念 时域模型(Temporal Model) 时域模型的作用是去除帧间冗余.如:将第二帧减去第一帧,得到的剩余信息,其能量会远小于第二帧本身. 基于块的运动估计和补偿 ...

  7. 【Android Developers Training】 30. 允许其它应用启动你的Activity

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  8. C++基础之引用与指针的区别与联系、常引用使用时应注意的问题

    什么是引用? 引用就是对变量起一个别名,而变量还是原来的变量,并没有重新定义一个变量.例如下面的例子:   #include<iostream> using namespace std; ...

  9. 一个简单的python选课系统

    下面介绍一下自己写的python程序,主要是的知识点为sys.os.json.pickle的模块应用,python程序包的的使用,以及关于类的使用. 下面是我的程序目录: bin是存放一些执行文件co ...

  10. c# ActiveMQ 类

    using System;using System.Collections.Generic;using System.Text; using Apache.NMS;using Apache.NMS.A ...