-
外邊距
外邊距是元素邊框與周圍元素相距的空間聘萨。
使用margin屬性可以設(shè)置外邊距坠陈。
使用margin-top/right/left/bottom為元素設(shè)置四個方向梁厉。
使用margin:0 auto 可以使元素居中咬荷。.box1{ width: 200px; height: 200px; background-color: #bfa; border: 10px solid red; margin:10px 20px 30px 40px; } .box2{ width: 200px; height: 200px; background-color: yellow; }
-
display
通過display來修改元素的性質(zhì)刽射。
--block:設(shè)置元素為塊元素
--inline:設(shè)置元素為行內(nèi)元素
--inline-block:設(shè)置元素為行內(nèi)塊元素
--none: 隱藏元素
visibility
visibility屬性主要用于元素是否可見
-visible:可見的
-hidden: 隱藏的
overflow
當(dāng)相關(guān)標(biāo)簽里面的內(nèi)容超出了樣式的寬度和高度使,就會發(fā)生一些奇怪的事情补鼻,瀏覽器會讓內(nèi)容溢出盒子哄啄。
可以通過overflow來控制內(nèi)容溢出的情況。
可選值:
*--visible:默認(rèn)值
--scroll:添加滾動條
--auto:根據(jù)需要添加滾動條
--hidden:隱藏超出盒子的內(nèi)容
文檔流
文檔流指的是文檔中可實現(xiàn)的對象在排列時所占用的位置风范,
將窗體自上而下分為一行行咨跌,并在每行中按從左至右的順序排放元素,即為文檔流硼婿。
也就是說在文檔流中元素默認(rèn)會緊貼到上一個元素的右邊锌半,如果右邊不足以放下元素,元素則會另起一行加酵,在新的一行中繼續(xù)從左至右擺放拳喻。
這樣一來每一個塊元素都會另起一行,那么我們?nèi)绻朐谖臋n流中進(jìn)行布局就會變得比較麻煩猪腕。
浮動
所謂浮動指的就是使元素脫離原來的文本流冗澈,在父元素中浮動起來。--none: 不浮動
--left:向左浮動
--right: 向右浮動
clear: 清除浮動<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>浮動</title> <style type="text/css"> .box1{ width: 600px; height: 200px; background-color: red; float: left; } .box2{ width: 200px; height: 200px; background-color: yellow; float: left; } .box3{ width: 200px; height: 200px; background-color: green; float: left; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </body> </html>
-
內(nèi)聯(lián)素浮動
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>內(nèi)聯(lián)素的浮動</title> <style type="text/css"> .box1{ background-color: #bfa; } .s1{ float: left; width: 100px; height: 100px; background-color: yellow; } </style> </head> <body> <div class="box1">a</div> <span class="s1">hello</span> </body> </html>
-
簡單布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>簡單布局</title> <style type="text/css"> *{ margin: 0; padding: 0; } .header{ width: 1000px; height: 150px; background-color: yellowgreen; margin: 0 auto; } .content{ width: 1000px; height: 400px; background-color: orange; margin: 10px auto; } .left{ width: 200px; height: 100%; background-color: skyblue; float: left; } .center{ width: 580px; height: 100%; background-color: yellow; float: left; margin: 0 10px; } .right{ width: 200px; height: 100%; background-color: pink; float: left; } .footer{ width: 1000px; height: 150px; background-color: silver; margin: 0 auto; } </style> </head> <body> <div class="header"></div> <div class="content"> <div class="left"></div> <div class="center"></div> <div class="right"></div> </div> <div class="footer"></div> </body> </html>
-
相對定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>相對定位</title> <style type="text/css"> .box1{ height: 200px; background-color: red; position: relative; } .box2{ width: 200px; height: 200px; background-color: yellow; position: relative; left: 100px; top: 200px; } .box3{ width: 200px; height: 200px; background-color: yellowgreen; } .s1{ position: relative; width: 200px; height: 200px; background-color: yellow; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <span class="s1">我是一個span</span> </body> </html>
-
絕對定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>絕對定位</title> <style type="text/css"> .box1{ width: 200px; height: 200px; background-color: red; } .box2{ width: 200px; height: 200px; background-color: yellow; position: absolute; } .box3{ width: 300px; height: 300px; background-color: yellowgreen; } .box4{ width: 300px; height: 300px; background-color: orange; } .s1{ width: 100px; height: 100px; background-color: yellow; position: absolute; } </style> </head> <body> <div class="box1"></div> <div class="box5"> <div class="box4"> <div class="box2"></div> </div> </div> <div class="box3"></div> <span class="s1">我是一個span</span> </body> </html>
-
固定定位
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>固定定位</title> <style type="text/css"> .box1{ width: 200px; height: 200px; background-color: red; } .box2{ width: 200px; height: 200px; background-color: yellow; position: fixed; left: 0px; top: 0px; } .box3{ width: 200px; height: 200px; background-color: yellowgreen; } </style> </head> <body style="height: 5000px;"> <div class="box1"></div> <div class="box4" style="width: 300px; height: 300px; background- color: orange; position: relative;"> <div class="box2"></div> </div> <div class="box3"></div> </body>
盒子模型簡單布局
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門剃浇,熙熙樓的掌柜王于貴愁眉苦臉地迎上來巾兆,“玉大人,你說我怎么就攤上這事虎囚〗撬埽” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵淘讥,是天一觀的道長圃伶。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么窒朋? 我笑而不...
- 正文 為了忘掉前任搀罢,我火速辦了婚禮,結(jié)果婚禮上炼邀,老公的妹妹穿的比我還像新娘魄揉。我一直安慰自己,他們只是感情好拭宁,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著瓣俯,像睡著了一般杰标。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上彩匕,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼奠货!你這毒婦竟也來了介褥?” 一聲冷哼從身側(cè)響起,我...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡睛廊,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 年R本政府宣布见咒,位于F島的核電站,受9級特大地震影響挂疆,放射性物質(zhì)發(fā)生泄漏改览。R本人自食惡果不足惜下翎,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望宝当。 院中可真熱鬧视事,春花似錦、人聲如沸庆揩。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽订晌。三九已至虏辫,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間锈拨,已是汗流浹背砌庄。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 本文是針對剛學(xué)編程的小白,都是一些基礎(chǔ)知識,如果想了解更多深層一點的東西,歡迎移步本人博客!! 博客地址 點擊跳轉(zhuǎn)...
- 一陵珍、在什么場景下會出現(xiàn)外邊距合并?如何合并违施?如何不讓相鄰元素外邊距合并互纯?給個父子外邊距合并的范例 在CSS當(dāng)中,相...