在HTML文档中,<link>元素用来告诉浏览器在何处寻找用于定义页面样式的CSS文件。它是一个空元素,而且位于<head>元素中。
常见特性:
href:该特性表明CSS文件的路径。
type:该特性表明页面所链接文档的类型。它的值应该是text/css
rel:该特性表示HTML页面与被链接文件的关系。当链接到一个CSS文件时,该特性的值应该为stylesheet
示例:
HTML部分源码
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>使用外部CSS</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="css/styles.css" type="text/css" rel="stylesheet"/> </head> <body> <h1>Potatoes</h1> <p>There are dozens of different potato varieties.They are usually described as early,second early and maincrop. </p> </body> </html>
CSS文件部分源码:
body{ font-family: arial; background-color: rgb(185,179,175); } h1{ color: rgb(255,255,255); }
运行结果: