- 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
廣告




