一、浮動
left 元素向左浮動
right 元素向右浮動
none 元素不浮動
inherit 從父級繼承浮動屬性
#fd{ width: 100px; height: 100px; background-color: red; float: left; } #sd{ width: 100px; height: 100px; background-color: blue; float: left; } #td{ width: 100px; height: 100px; background-color: green; float: left; } #container{ width: 400px; height: 500px; background-color: darkgray; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>浮動</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="container"> <div id="fd"></div> <div id="sd"></div> <div id="td"></div> </div> </body> </html>
二、clear屬性
去掉浮動屬性(包括繼承來的屬性)
left、right 去掉元素向左、向右浮動
both 左右兩側均去掉浮動
inherit 從父級繼承來clear的值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>浮動</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="container"> <div id="fd"></div> <div id="sd"></div> <div id="td"></div> <div id="text">HelloWorld!</div> </div> </body> </html>
#fd{ width: 100px; height: 100px; background-color: red; float: left; } #sd{ width: 100px; height: 100px; background-color: blue; float: left; } #td{ width: 100px; height: 100px; background-color: green; float: left; } #container{ width: 280px; height: 500px; background-color: darkgray; } #text{ clear: left; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。