一。行內樣式
(不多使用)css
<h1>靜夜思</h1> <p>牀前明月光,</p> <p style="color: red;">疑是地上霜。</p> <p style="color: #0000FF;font-size: 1rem;">舉頭望明月,</p> <p>低頭思故鄉。</p>
二。內嵌樣式
(經常使用於中小型網頁)ide
<head> <meta charset="utf-8"> <title> </title> <style type="text/css"> h1{color: red;} #aa{color: #0000FF;} .bb{color: #00FF00;} </style> </head> <body> <h1>靜夜思</h1> <p id="aa">牀前明月光,</p> <p class="bb">疑是地上霜。</p> <p>舉頭望明月,</p> <p>低頭思故鄉。</p> </body>
三。外部連接
(經常使用於大型網頁)
新建.css文件,在css文件中不須要寫<style>
鏈接方式1<link rel="stylesheet" type="text/css" href=".css"/>
鏈接方式2<style type="text/css">@import url(".css");</style>url
樣式表中:code
.red{color: red;} #green{color: green;}
鏈接方式1utf-8
<head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" type="text/css" href="css/樣式表.css"/> </head> <body> <h1>靜夜思</h1> <p class="red">牀前明月光,</p> <p>疑是地上霜。</p> <p id="green">舉頭望明月,</p> <p>低頭思故鄉。</p> </body>
鏈接方式2rem
<head> <meta charset="utf-8"> <title></title> <style type="text/css"> @import url("樣式表.css"); </style> </head> <body> <h1>靜夜思</h1> <p class="red">牀前明月光,</p> <p>疑是地上霜。</p> <p id="green">舉頭望明月,</p> <p>低頭思故鄉。</p> </body>