博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
清除浮动的几种方法
阅读量:7114 次
发布时间:2019-06-28

本文共 1054 字,大约阅读时间需要 3 分钟。

浮动是布局中经常采用的手段,但是浮动带来的高度塌陷却为布局带来麻烦,所以我们经常需要清除浮动,下文记录几种常用的清除浮动手段

高度塌陷:

clear属性

第一种运用clear的方式在需要清浮动的元素下放一个div,并加上clear:both

html

some text

复制代码

css

.float{			width:300px;height:300px;			float:left;			background: green;			opacity: .5;		}		p{			background:red;		}		.clear{		    clear:both;		}复制代码

第二种方式是用伪元素:before:after

html

some text

复制代码

css

.content:after{                   content:'';                   display:'block';                   clear:both;               }              float{			width:300px;height:300px;			float:left;			background: green;			opacity: .5;		}		p{			background:red;		}复制代码

overflow:hidden

该方法利用了BFC的特性,当元素有以下特性时,触发BFC

  • html根元素
  • float的值不为none
  • overflow的值为hidden、auto或scroll
  • position的值不为staticrelative
  • display的值为table-celltable-caption、或inline-block

html

some text

复制代码

css

.content{			overflow: hidden;		}		.float{			float:left;			width:100px;height:100px;			background: green;			opacity: .5;		}		p{			background:red;		}复制代码

清除浮动效果图:

转载地址:http://qfwel.baihongyu.com/

你可能感兴趣的文章
简单程序实现100以内加减乘除
查看>>
第148天:js+rem动态计算font-size的大小,适配各种手机设备
查看>>
input checkbod 全选 反选
查看>>
httpclient,java跨系统调用,第三接口调用实例
查看>>
Objective-C征途:BOOL Party
查看>>
mysql c-api 预处理语句
查看>>
functions 示例
查看>>
C#编译基础知识(三)
查看>>
插入订单并且输出订单号的sql存储过程
查看>>
虚拟Ip技术如何实现备机容灾
查看>>
windows快捷启动命令
查看>>
Python几个算法实现
查看>>
about selection and range
查看>>
linux性能系列--内存
查看>>
php开发中的一些常用统计的日期
查看>>
洛谷 3951 小凯的疑惑——找规律/数学
查看>>
bzoj 4300 绝世好题——DP
查看>>
Jquery小记
查看>>
SQL Server 2008连接字符串写法大全
查看>>
序列模型(4)----门控循环单元(GRU)
查看>>