、頁面使用CSS的好處:
有效的傳遞頁面信息。
使用CSS美化過的頁面文本,使頁面漂亮、美觀,吸引用戶。
可以很好的突出頁面的主題內容,使用戶第一眼可以看到頁面主要內容。
具有良好的用戶體驗。
2、美化網頁的一些基本樣式
A:字體樣式:
font-family設置字體類型font-family:"隸書";
font-size設置字體大小font-size:12px;
font-style設置字體風格font-style:italic;
font-weight設置字體的粗細font-weight:bold;
font在一個聲明中設置所有字體屬性font:italic bold 36px "宋體";
舉例:
body{font-family: Times,"Times New Roman", "楷體";}
h1{font-size:24px;} 單位->px:像素
h2{font-style:oblique;}
p{font-weight:bold;}
p span{font:oblique bold 12px "楷體";}
B:文本屬性:
color設置文本顏色color:#00C;
text-align設置元素水平對齊方式text-align:right;
text-indent設置首行文本的縮進text-indent:20px;
line-height設置文本的行高line-height:25px;
text-decoration設置文本的裝飾text-decoration:underline;
C:排版文本段落:
水平對齊方式:text-align:left|right|center|justify;
left把文本排列到左邊。默認值:由瀏覽器決定
right把文本排列到右邊
center把文本排列到中間
justify實現兩端對齊文本效果
首行縮進:text-indent:em或px
行高:line-height:px
文本修飾:text-decoration:none|underline|overline|line_through
值說明
none默認值,定義的標準文本
underline設置文本的下劃線
overline設置文本的上劃線
line-through設置文本的刪除線
垂直對齊方式:vertical-align屬性:middle、top、bottom
文本陰影:text-shadow : color x-offset y-offset blur-radius;
D:背景顏色和背景圖片:
background-color:"red";
background-image:url(圖片路徑);
background-repeat:
沿水平和垂直兩個方向平鋪
no-repeat:不平鋪,即只顯示一次
repeat-x:只沿水平方向平鋪
repeat-y:只沿垂直方向平鋪
background-position:X、Y方向關鍵詞 水平方向的關鍵詞:left、center、right
垂直方向的關鍵詞:top、center、bottom
舉例:
.title {
font-size:18px;
font-weight:bold;
color:#FFF;
text-indent:1em;
line-height:35px;
background:#C00 url(../image/arrow-down.gif) 205px 10px no-repeat;
}
線性漸變:linear-gradient ( position, color1, color2,…)
3、舉例:
<head>
<title>家用電器</title>
</head>
<link rel="stylesheet" href="jiayongdianqi.css">
<body>
<div class="container">
<h2>家用電器</h2>
<div class="type">
<h6><a href="#">大家電</a></h6>
<ul>
<li> <a href="#">平板電視</a> <a href="#">洗衣機</a> <a href="#">冰箱</a></li>
<li> <a href="#">空調</a> <a href="#">煙機/灶具</a> <a href="#"> 熱水器</a></li>
<li> <a href="#">冷柜/酒柜</a> <a href="#">消毒柜</a> <a href="#">家庭影院</a></li>
</ul>
<h6><a href="#">生活電器</a></h6>
<ul>
<li> <a href="#">電風扇</a> <a href="#">凈化器</a> <a href="#">吸塵器</a></li>
<li> <a href="#">凈水設備</a> <a href="#">掛燙機</a> <a href="#"> 電話機</a></li>
</ul>
<h6><a href="#">廚房電器</a></h6>
<ul>
<li> <a href="#">榨汁機</a> <a href="#">電壓力鍋</a> <a href="#">電飯煲</a></li>
<li> <a href="#">豆漿機</a> <a href="#">微波爐</a> <a href="#"> 電磁爐</a></li>
</ul>
<h6><a href="#">五金家裝</a></h6>
<ul>
<li> <a href="#">淋浴/水槽</a> <a href="#">電動工具</a> <a href="#">手動工具</a></li>
<li> <a href="#">儀器儀表 </a> <a href="#">浴霸/排氣 </a> <a href="#"> 燈具</a></li>
</ul>
</div>
</div>
</body>
</html>
li{
/* 去圓點 */
list-style: none;
}
/* 分類頁面總寬度 */
.container{
width: 500px;
}
a{
/* 去超鏈接下劃線 */
text-decoration: none;
}
/* 大標題字體 */
.container>h2{
font-size: 18px;
color: white;
font-weight: bolder;
line-height: 50px;
text-indent: 2px;
/*從上到下,0%開始顏色。50%顏色。70%顏色 */
background: linear-gradient(to bottom,#0467ac,#63a7d6,#b6dbf5);
}
css代碼:
/* 所有電器分類內容 */
.type{
/* 首行縮進 */
text-indent: 4.5em;
/* 左外邊距40px */
margin-left: 40px;
}
/* 電器分類 */
.type>h6{
font-size: 14px;
font-weight: bolder;
line-height: 30px;
background: linear-gradient(to bottom,#e4f1fa,#bddff7,#e4f1fa);
}
/* 電器分類中的A標簽 */
.type>h6>a{
color:#0467ac;
}
/* 電器分類中的A標簽鼠標懸浮效果 */
.type>h6>a:hover{
text-decoration: underline;
}
/* 分類內容字體 */
.type>ul>li{
font-size: 12px;
line-height: 26px;
}
/* 分類內容字體里面的A標簽 */
.type>ul>li>a{
color: #969696;
}
/* 分類內容字體里面的A標簽懸浮效果 */
.type>ul>li>a:hover{
color: #804000;
text-decoration: underline;
}
4、效果圖鏈接:file:///D:/ruanjian/VS/wenjianxiangmu/htmlFive/jiayongdianqi.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> <style type="text/css"> p{ font-family:"宋體"; font-size:14px; } .p2{ font-style:italic; } .p3{ font-weight:bold; } .p4{ font-family:"微軟雅黑"; } .p5{ font-size:36px; } </style> </head> <body> <p class="p1">這是第一行(樣式為:標簽選擇器p中的樣式)</p> <p class="p2">這是第二行(樣式為:斜體)</p> <p class="p3">這是第三行(樣式為:加粗)</p> <p class="p4">這是第四行(樣式為:字體變成微軟雅黑)</p> <p class="p5">這是第五行(樣式為:字體大小為36px)</p> </body> </html>
效果演示圖如下所示:
1.png
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> <style type="text/css"> .div1{ width:500px; border:1px solid #000; padding:20px; } .p1{ color:red; } .p2{ text-align:center; } .p3{ line-height:50px; } .p4{ text-indent:2em; } .p5{ text-decoration:line-through; } .div2{ border:1px solid red; padding:20px; }  .img1{ width:70px; height:70px; vertical-align:middle; } </style> </head> <body> <div class="div1"> <p class="p1">這是第一行(樣式為: 字體紅色)</p> <p class="p2">這是第二行(樣式為:居中)</p> <p class="p3">這是第三行(樣式為:行高50px)</p> <p class="p4">這是第四行(樣式為:縮進2em)</p> <p class="p5">這是第五行(樣式為:刪除線)</p> <div class="div2"> <img src="tu24.png" alt="" class="img1">這是第六行(樣式為:垂直居中) </div> </div> </body> </html>
演示效果如圖所示:
2.png
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> <style type="text/css"> .div1{ width:500px; height:500px; background-color:#F1CCE8; //背景顏色 } .div2{ width:100%; height:100%; background-image:url(tu24.png); // 插入背景圖片 background-repeat:no-repeat; //圖片不平鋪 background-position:center center; //背景圖片垂直水平居中 } </style> </head> <body> <div class="div1"> <div class="div2"> </div> </div> </body> </html>
演示效果圖:
3.png
<!doctype html> <html> <head> <meta charset="utf-8"> <title>無標題文檔</title> <style type="text/css"> .div1{ width:300px; height:300px; background-color:#F1CCE8; padding:20px; } .ul1{ } .ul2{ list-style-type:none; } .ul3{ list-style-image:url(person02.png); list-style-position:outside; } </style> </head> <body> <div class="div1"> <ul class="ul1"> <li>第一隊</li> <li>第一隊</li> <li>第一隊</li> </ul> <ul class="ul2"> <li>第二隊</li> <li>第二隊</li> <li>第二隊</li> </ul> <ul class="ul3"> <li>第三隊</li> <li>第三隊</li> <li>第三隊</li> </ul> </div> </body> </html>
演示效果圖為:
4.png
、美化網頁元素
本章目標:
【查看淘寶頁面,讓學員觀察,重點記住了什么東西】 因此使用CSS樣式美化網頁文本具有如下意義。
< span>標簽 < span>標簽 的作用:能讓某幾個文字或者某個詞語凸顯出來,從而添加對應的樣式!
<p>好好學習,<span>天天向上</span></p>
在這里插入圖片描述
*請認真填寫需求信息,我們會在24小時內與您取得聯系。