這篇文章主要介紹了css如何使用clear屬性,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
css clear屬性指定元素的左側或右側上不允許出現浮動元素??捎糜趯崿F浮動的清除,解決浮動布局帶來的一些問題。
css clear屬性怎么用?
clear 屬性規定元素的哪一側不允許其他浮動元素。
語法:
clear:left|right|both|none|inherit;
屬性值:
● left:在左側不允許浮動元素。
● right:在右側不允許浮動元素。
● both:在左右兩側均不允許浮動元素。
● none:默認值。允許浮動元素出現在兩側。
● inherit:規定應該從父元素繼承 clear 屬性的值。
說明:
clear 屬性定義了元素的哪邊上不允許出現浮動元素。在 CSS1 和 CSS2 中,這是通過自動為清除元素(即設置了 clear 屬性的元素)增加上外邊距實現的。在 CSS2.1 中,會在元素上外邊距之上增加清除空間,而外邊距本身并不改變。
不論哪一種改變,最終結果都一樣,如果聲明為左邊或右邊清除,會使元素的上外邊框邊界剛好在該邊上浮動元素的下外邊距邊界之下。
注釋:所有主流瀏覽器都支持 clear 屬性。任何版本的 Internet Explorer (包括 IE8)都不支持屬性值 "inherit"。
css clear屬性 示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
img
{
float:left;
}
p.clear
{
clear:both;
}
</style>
</head>
<body>
<img src="logocss.gif" width="95" height="84" />
<p>This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
<p>This is also some text. This is also some text. This is also some text. This is also some text. This is also some text.</p>
<br>
<p>使用clear:both清除浮動:</p>
<img src="logocss.gif" width="95" height="84" />
<p>This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</p>
<p class="clear">This is also some text. This is also some text. This is also some text. This is also some text. This is also some text. </p>
</body>
</html>效果圖:

感謝你能夠認真閱讀完這篇文章,希望小編分享css如何使用clear屬性內容對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,遇到問題就找億速云,詳細的解決方法等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。