一、文本屬性
1.text-align:cnter 文本居中
2.line heigth 垂直居中 :行高,和高度對應
3.設置圖片與文本的距離:vertical-align
4.text-decoration:none 去掉超鏈接下划線
5.要是給a標簽修改顏色的時候,就定到a標簽上,用繼承有時候是搞不定的
因為繼承的級別是很低的,如果a標簽設置了樣式,是不會繼承父親的
6.首行縮進:text-indent:30px
7.font-style:oblique 或者italic....(設置字體的樣式為斜體)
二、背景屬性
background-color:背景顏色
background-image:url('11.jpg'); 背景圖片鏈接
background-repeat:repeat-x; x軸平鋪
background-repeat:no-repeat; 不重復
background-position:400px 200px 調整背景的位置(距左。距右)
background-position: center:center; 背景居中
簡寫:
background: url('11.jpg') no-repeat center;

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>背景處理</title> 6 <style> 7 .c1{ 8 width: 100px; 9 height: 100px; 10 border: 1px solid red; 11 background: url("xhr.jpg") -206px -29px; 12 /*可在那個網頁上右擊點擊檢查,調試*/ 13 /*background-position: center; */ 14 /*定位*/ 15 } 16 </style> 17 </head> 18 <body> 19 <div class="c1"> 20 </div> 21 </body> 22 </html>
三、邊框屬性
常用屬性
簡寫:border :1px soild red;
deshed:虛線
只加有一個方向的:border-right :1px soild red;
四、列表屬性
去掉列表前面的標志:ul li{list-style:none;}
去掉列表前面的空格:ul{padding:0}
上面兩行也可寫成下面一行
去掉盒子上面的間隙:*{margin:0; padding :0;}
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> ul li{ font-family: 華文中宋; list-style: none; //去掉點 /*list-style: circle;//空心圓*/ /*list-style: disc;//實心圓(默認也是實心圓)*/ } ul{ padding: 0; //把字體移到前面 } </style> </head> <body> <div> <ul> <li>第一章</li> <li>第二章</li> <li>第三章</li> <li>第四章</li> </ul> </div> </body> </html>
五、display屬性
display屬性
1.將塊級標簽設置成內聯標簽:disply:inline;
2.將內聯標簽設置成塊級標簽:disply:block;
3.內聯塊級標簽:像塊級一樣可設長寬,也可像內聯一樣在一行顯示:display:inline-block;
4.display:none; 吧不想讓用戶看到的給隱藏了(很重要的一個屬性)
5.visibility :hiddon; 也是隱藏
注意與visibility:hidden的區別:
visibility:hidden:可以隱藏某個元素,但隱藏的元素仍需占用與未隱藏之前一樣的空間。也就是說,該元素雖然被 隱藏了,但仍然會影響布局。
display:none:可以隱藏某個元素,且隱藏的元素不會占用任何空間。也就是說,該元素不但被隱藏了,而且該元 素原本占用的空間也會從頁面布局中消失

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 .c1{ 8 width: 100px; 9 height:100px; 10 background-color: rebeccapurple; 11 } 12 .c2{ 13 width: 100px; 14 height:100px; 15 background-color: burlywood; 16 } 17 .c3{ 18 width: 100px; 19 height:100px; 20 background-color: crimson; 21 display: inline; 22 } 23 .c4{ 24 width: 100px; 25 height:100px; 26 background-color: gray; 27 } 28 .s1{ 29 display: block; 30 width: 200px; 31 height: 200px; 32 background-color: royalblue; 33 /*visibility: hidden;*/ //隱藏了其他的不會頂上去 34 display:none; //隱藏了其他的會頂上去 35 36 } 37 </style> 38 </head> 39 <body> 40 <div class="c4">div</div> 41 <span class="s1">span</span> 42 <div class="c1">年后</div> 43 <div class="c2">年后</div> 44 <div class="c3">年后</div> 45 </body> 46 </html>
六、邊距的塌陷問題
1、兄弟div:
上面div的margin-bottom和下面div的margin-top會塌陷,也就是會取上下兩者margin里最大值作為顯示值
2、父子div:
if 父級div中沒有border,padding,inlinecontent,子級div的margin會一直向上找,直到找到某個標簽包括border,padding,inline content中的其中一個,然后按此div 進行margin;
解決方法
解決方法
這兩種會改變結構
1.加上padding
2.加上border
不改變結構
3.overflow:hidden

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 body{ 8 margin: 0; 9 } 10 .outer{ 11 background-color: gold; 12 width: 300px; 13 height: 300px; 14 /*第一種解決方法:但是改變了結構padding: 10px;*/ 15 /*第二種方法:加個border*/ /*border: 1px solid;*/ 16 /*第三種方法*/ 17 overflow: hidden; 18 } 19 .box1{ 20 width: 100px; 21 height: 100px; 22 background-color: blue; 23 /*如果父級標簽什么都沒有,那么就會找叔叔的*/ 24 margin-top:10px; 25 26 } 27 .box2{ 28 width: 100px; 29 height: 100px; 30 background-color: darksalmon; 31 /*如果這樣的話就合適呢,對着就下去了*/ 32 margin-top: 10px; 33 } 34 35 </style> 36 </head> 37 <body> 38 <div style="background-color: burlywood; width:300px; height 39 :300px"></div> 40 <div class="outer"> 41 <div class="box1"></div> 42 <div class="box2"></div> 43 </div> 44 </body> 45 </html>
處理后的結果如圖:
溢出問題

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>css屬性操作</title> 6 <style> 7 .c1{ 8 border: 1px solid; 9 background-color: blueviolet; 10 width: 100%; 11 height:200px; 12 /*text-align: center;*/ 13 /*設置兩端對齊*/ 14 text-align: justify; 15 line-height: 200px; 16 /*如果你寫的多了,會溢出來*/ 17 /*第一種方法:overflow: hidden;*/ 18 overflow: scroll; 19 } 20 .btn{ 21 width: 45px; 22 height: 70px; 23 background-color: gray; 24 /*設置透明度*/ 25 opacity: 0.4; 26 text-align: center; 27 line-height: 70px; 28 /*行高和高度對應*/ 29 30 } 31 </style> 32 </head> 33 <body> 34 <div class="c1">啦啦啦啦啦綠綠綠 35 綠綠綠綠 綠綠綠綠綠綠 綠綠綠綠綠綠綠 36 啦啦啦啦啦 綠綠綠綠綠綠綠綠綠綠綠綠綠 37 綠綠綠綠綠 綠綠綠綠綠綠綠綠綠綠綠綠 38 綠綠綠 綠綠綠綠綠綠綠綠 綠綠綠綠綠 39 綠綠綠綠 綠綠綠綠綠綠 綠綠lllllllllllllllllllllll 40 綠綠綠綠綠</div> 41 <div class="btn"> < </div> 42 </body> 43 </html>
解決溢出的方法
解決溢出的方法 overflow:auto;
overflow: hidden;
overflow:scoll; #加上滾動條
七、清除浮動
clear語法:
clear:none | left | right | both
1.clear:left 清除的是左邊的浮動
2.clear:both :保證左右兩邊都沒有浮動
注意:
排序的時候是一個標簽一個標簽的排
如果上一個是浮動的,就緊貼個上一個
如果上一個不是浮動的,就和上一個保持垂直不變
八、float父級的塌陷問題
float它不是完全脫離,它是半脫離的。像是文字環繞的就是用float實現的。float是不覆蓋文字的
半脫離的,吧文字給擠過去了。

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 .c1{ 8 width: 100px; 9 height: 60px; 10 background-color: blue; 11 float: left; 12 } 13 .c2{ 14 width: 200px; 15 height: 30px; 16 background-color: aqua; 17 float: left; 18 } 19 .c3{ 20 width: 200px; 21 height: 100px; 22 background-color: crimson; 23 float: left; 24 } 25 26 </style> 27 </head> 28 <body> 29 <div class="c1"></div> 30 <div class="c2"></div> 31 <div class="c3"></div> 32 33 <div class="content"> 34 content 35 </div> 36 </body> 37 </html>
解決方案
解決方案 1.<div style='clear:both'></div> 也可以不加div 2.用after .header:after{ content:""; #內容為空 display:block; #塊級標簽 clear:both; #清楚浮動的功能 } 約定的名字:clearfix .clearfix:after{ content:""; #內容為空 display:block; #塊級標簽 clear:both; #清楚浮動的功能(可以做到一個自動切換的功能) }
解決問題以后的
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ margin: 0; padding: 0; } .header{ /*height: 30px;*/ } .box1{ width: 200px; height: 80px; background-color: wheat; float: left; } .box2{ width: 200px; height: 30px; background-color: rebeccapurple; float: left; } .box3{ width: 100px; height: 50px; background-color: rosybrown; float: left; } .content{ width: 100%; height: 200px; background-color: royalblue; } .clearfix:after{ content: ""; display: block; clear: both; } </style> </head> <body> <div class="header clearfix"> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </div> <div class="content"> Content </div> </body> </html>
九、position(定位)屬性
position的四種屬性
1.static:默認位置
2.fixed:完全脫離文檔流,固定定位(以可視窗口為參照物)
3.relative:相對定位(參照的是自己本身的位置),沒有脫離文檔流,沒有頂上去,會保持自己的位置不動。可以使用top left 進行定位
4.absolute:絕對定位:脫離了文檔流(參照的是按已定位的父級標簽定位,如果找不到會按body的去找)
注意:將定位標簽設置為absolute,將他的父級標簽設置為定位標簽 (relative)
field舉例(做一個返回頂部的樣式。不管你拉不拉滾動條,他都會固定位置不變給它加一個)

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>固定位置</title> 6 7 <style> 8 .c1{ 9 background-color: limegreen; 10 width:100%; 11 height: 1000px; 12 } 13 .returntop{ 14 width: 100px; 15 height: 40px; 16 background-color: gray; 17 /*透明度*/ 18 /*opacity: 0.4;*/ 19 color: white; 20 text-align: center; 21 line-height: 40px; 22 position: fixed; 23 bottom:50px; 24 right: 20px; 25 } 26 </style> 27 </head> 28 <body> 29 <div class="c1"></div> 30 <div class="returntop">返回頂部>></div> 31 32 33 </body> 34 </html>
相對位置,絕對位置例子

1 =============== 2 一開始父級沒有定位、 3 <!DOCTYPE html> 4 <html lang="en"> 5 <head> 6 <meta charset="UTF-8"> 7 <title>絕對定位</title> 8 <style> 9 *{ 10 margin: 0; 11 } 12 .box1 ,.box2,.box3{ 13 width: 200px; 14 height: 200px; 15 } 16 .box1{ 17 background-color: blueviolet; position: relative; 18 19 } 20 .box2{ 21 background-color: darksalmon; 22 position: relative; 23 /*position: absolute;*/ 24 left: 200px; 25 /*right: 200px;*/ 26 top: 200px; 27 } 28 .box3{ 29 background-color: lime; 30 } 31 </style> 32 </head> 33 <body> 34 <div class="box1"></div> 35 <div class="box2"></div> 36 <div class="box3"></div> 37 </body> 38 </html>

1 <!--父級有了定位--> 2 <!--================--> 3 <!DOCTYPE html> 4 <html lang="en"> 5 <head> 6 <meta charset="UTF-8"> 7 <title>絕對定位</title> 8 <style> 9 .father{ 10 position: relative; 11 } 12 *{ 13 margin: 0; 14 } 15 .box1 ,.box2,.box3{ 16 width: 200px; 17 height: 200px; 18 } 19 .box1{ 20 background-color: blueviolet; position: relative; 21 22 } 23 .box2{ 24 background-color: darksalmon; 25 /*position: relative;*/ 26 position: absolute; 27 left: 200px; 28 /*right: 200px;*/ 29 top: 200px; 30 } 31 .box3{ 32 background-color: lime; 33 position: absolute; 34 } 35 </style> 36 </head> 37 <body> 38 <div class="box1"></div> 39 <div class="father"> 40 <div class="box2"></div> 41 </div> 42 <div class="box3"></div> 43 44 45 </body> 46 </html>
十、float和position的區別
float:半脫離文檔流
position:全脫離文檔流