1.CSS的引入的三種方式
a)行內樣式
使用style屬性引入CSS樣式。
示例:
<h1 style="color:red;">style屬性的應用</h1>
<p style="font-size:14px;color:green;">直接在HTML標簽中設置的樣式</p>
實際在寫頁面時不提倡使用,在測試的時候可以使用。
<!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title>行內樣式</title> </head> <body> <!--使用行內樣式引入CSS--> <h1 style="color:red;">Leaping Above The Water</h1> <p style="color:red;font-size:30px;">我是p標簽</p> </body> </html>
b)內部樣式表
在style標簽中書寫CSS代碼。style標簽寫在head標簽中。
示例:
<head>
<style type="text/css">
h3{
color:red;
}
</style>
</head>
<!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title>內部樣式表</title> <!--使用內部樣式表引入CSS--> <style type="text/css"> div{ background: green; } </style> </head> <body> <div>我是DIV</div> </body> </html>
c)外部樣式表
CSS代碼保存在擴展名為.css的樣式表中
HTML文件引用擴展名為.css的樣式表,有兩種方式:鏈接式、導入式。
語法:
1、鏈接式
<link type="text/css" rel="styleSheet" href="CSS文件路徑" />
2、導入式
<style type="text/css">
@import url("css文件路徑");
</style>
<!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title>外部樣式表</title> <!--鏈接式:推薦使用--> <link rel="stylesheet" type="text/css" href="css/style.css" /> <!--導入式--> <style type="text/css"> @import url("css/style.css"); </style> </head> <body> <ol> <li>1111</li> <li>2222</li> </ol> </html>