首先上一个样式的例子css
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> This is my HTML</title> <!-- 定义样式--> <style type="text/css"> h2 {color: red} p {color: green} </style> </head> <body> <h2>红颜色</h2> <p>绿颜色</p> </body> </html>
HTML中经常使用的三种方式插入样式表
html
1>外部样式表
code
在一个工程中,每一个页面的共同部分能够采用外部样式表。使用外部样式表,咱们能够经过更改一个文件来改变整个工程的外观。htm
<head> <link rel="stylesheet" type="text/css" href="mySelfStyle.css"> </head>
以下图是个人此次工程中的一个页面用到的外部样式表utf-8
2>内部样式表
it
当单个文件须要特别样式时,能够使用内部样式表,咱们能够在head中经过<style>标签订义内部样式表。class
<head> <style type="text/css"> body {background-color: red} p {margin-left: 20px} </style> </head>
3>内联样式
meta
当特殊的样式须要应用到个别元素时,就能够使用内联样式。使用内联样式的方法是在相关的标签中使用样式属性。方法
<p style="color: red; margin-left: 100px">设置段落颜色为红色,距离左边100px</p>