- CSS 教程
- CSS - 首页
- CSS - 路线图
- CSS - 简介
- CSS - 语法
- CSS - 选择器
- CSS - 包含
- CSS - 测量单位
- CSS - 颜色
- CSS - 背景
- CSS - 字体
- CSS - 文本
- CSS - 图片
- CSS - 链接
- CSS - 表格
- CSS - 边框
- CSS - 块级边框
- CSS - 行内边框
- CSS - 外边距
- CSS - 列表
- CSS - 内边距
- CSS - 光标
- CSS - 轮廓
- CSS - 尺寸
- CSS - 滚动条
- CSS - 行内块
- CSS - 下拉菜单
- CSS - 可见性
- CSS - 溢出
- CSS - Clearfix
- CSS - 浮动
- CSS - 箭头
- CSS - 调整大小
- CSS - 引号
- CSS - 顺序
- CSS - 定位
- CSS - 连字符
- CSS - 悬停
- CSS - 显示
- CSS - 焦点
- CSS - 缩放
- CSS - 转换
- CSS - 高度
- CSS - 连字符字符
- CSS - 宽度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 导航栏
- CSS - 覆盖层
- CSS - 表单
- CSS - 对齐
- CSS - 图标
- CSS - 图片库
- CSS - 注释
- CSS - 加载器
- CSS - 属性选择器
- CSS - 组合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 计数器
- CSS - 剪裁
- CSS - 书写模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 内嵌
- CSS - 隔离
- CSS - 滚动溢出
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指针事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大块级尺寸
- CSS - 最小块级尺寸
- CSS - 混合模式
- CSS - 最大内联尺寸
- CSS - 最小内联尺寸
- CSS - 偏移
- CSS - 强调色
- CSS - 用户选择
- CSS 高级
- CSS - 网格
- CSS - 网格布局
- CSS - Flexbox
- CSS - 可见性
- CSS - 定位
- CSS - 层
- CSS - 伪类
- CSS - 伪元素
- CSS - @规则
- CSS - 文字效果
- CSS - 分页媒体
- CSS - 打印
- CSS - 布局
- CSS - 验证
- CSS - 图片精灵
- CSS - !important
- CSS - 数据类型
- CSS3 教程
- CSS3 - 教程
- CSS - 圆角
- CSS - 边框图片
- CSS - 多重背景
- CSS - 颜色
- CSS - 渐变
- CSS - 盒阴影
- CSS - 盒装饰中断
- CSS - 光标颜色
- CSS - 文本阴影
- CSS - 文本
- CSS - 2D 变换
- CSS - 3D 变换
- CSS - 过渡
- CSS - 动画
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按钮
- CSS - 分页
- CSS - 变量
- CSS - 媒体查询
- CSS - 函数
- CSS - 数学函数
- CSS - 遮罩
- CSS - 形状
- CSS - 图片样式
- CSS - 特异性
- CSS - 自定义属性
- CSS 响应式
- CSS RWD - 简介
- CSS RWD - 视口
- CSS RWD - 网格视图
- CSS RWD - 媒体查询
- CSS RWD - 图片
- CSS RWD - 视频
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 转换器
- CSS - 颜色选择器和动画
- CSS 资源
- CSS - 有用资源
- CSS - 讨论
CSS - clear 属性
CSS 的**clear**属性决定了元素相对于前面浮动元素的流动方式。它决定了元素应该显示在浮动元素旁边还是下面。
语法
clear: none | left | right | both | initial | inherit;
属性值
| 值 | 描述 |
|---|---|
| none | 元素不会被推到左侧或右侧浮动元素的下方。默认值 |
| left | 元素被推到左侧浮动元素的下方。 |
| right | 元素被推到右侧浮动元素的下方。 |
| both | 元素被推到左侧和右侧浮动元素的下方。 |
| initial | 将属性设置为其默认值。 |
| inherit | 从父元素继承属性。 |
CSS clear 属性示例
以下示例说明了具有不同值的**clear**属性。
带有 none 值的 clear 属性
要让元素放置在浮动元素(左浮动或右浮动)旁边,我们使用**none**值。如果存在空间,则元素将放置在浮动元素旁边。以下示例显示了这一点。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.common {
width: 150px;
height: 100px;
text-align: center;
}
.float-left {
float: left;
background-color: lightblue;
margin-right: 10px;
}
.float-right {
float: right;
background-color: lightcoral;
}
.element {
clear: none;
background-color: lightgreen;
height: 100px;
}
</style>
</head>
<body>
<h2>
CSS clear property
</h2>
<p>
Clear: None, it places the element
alongside the floating element if
space exists.
</p>
<div>
<div class=" common float-left">
Left Float
</div>
<div class="element">
<p>
See this element is placed alongside the left
floating element due to the using of clear with
none value.
</p>
</div>
</div>
<br/>
<div>
<div class="common float-right">
Right Float
</div>
<div class="element">
<p>
See this element is placed alongside
the right floating element due to the
using of clear with none value.
</p>
</div>
</div>
</body>
</html>
带有 left 值的 clear 属性
要让元素放置在左侧浮动元素下方,我们使用**left**值。以下示例显示了这一点。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.float-left {
width: 150px;
height: 100px;
text-align: center;
float: left;
background-color: lightblue;
}
.element {
clear: left;
background-color: lightgreen;
height: 100px;
}
</style>
</head>
<body>
<h2>
CSS clear property
</h2>
<p>
Clear: Left, it places the element below the
left floating element.
</p>
<div>
<div class="common float-left">
Left Float
</div>
<div class="element">
<p>
See this element is placed below the
left floating element due to the using
of clear with left value.
</p>
</div>
</div>
<br/>
</body>
</html>
带有 right 值的 clear 属性
要让元素放置在右侧浮动元素下方,我们使用**right**值。以下示例显示了这一点。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.float-right {
width: 150px;
height: 100px;
text-align: center;
float: right;
background-color: lightcoral;
}
.element {
clear: right;
background-color: lightgreen;
height: 100px;
}
</style>
</head>
<body>
<h2>
CSS clear property
</h2>
<p>
Clear: Right, it places the element below the
right floating element.
</p>
<div>
<div class="common float-right">
Right Float
</div>
<div class="element">
<p>
See this element is placed below the
right floating element due to the using
of clear with right value.
</p>
</div>
</div>
<br/>
</body>
</html>
带有 both 值的 clear 属性
要让元素放置在左侧和右侧浮动元素下方,我们使用**both**值。以下示例显示了这一点。
示例
<!DOCTYPE html>
<html>
<head>
<style>
.common {
width: 150px;
height: 100px;
text-align: center;
}
.float-left {
float: left;
background-color: lightblue;
margin-right: 10px;
}
.float-right {
float: right;
background-color: lightcoral;
}
.element {
clear: both;
background-color: lightgreen;
height: 100px;
}
</style>
</head>
<body>
<h2>
CSS clear property
</h2>
<p>
Clear: Both, it places the element below both
the left and right floating elements.
</p>
<div>
<div class=" common float-left">
Left Float
</div>
<div class="common float-right">
Right Float
</div>
<div class="element">
<p>
See this element is placed below both
the left and right floating elements
due to the using of clear with both value.
</p>
</div>
</div>
</body>
</html>
支持的浏览器
| 属性 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| clear | 1.0 | 5.0 | 1.0 | 1.0 | 6.0 |
css_properties_reference.htm
广告




