外部样式表
css代码在一个独立文件中,HTML通过link标签引用css
h1{ ???color:red;}
这是css代码
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<meta name="viewport" content="width=device-width, initial-scale=1.0"> ???<meta http-equiv="X-UA-Compatible" content="ie=edge"> ???<title>Document</title> ???<link rel="stylesheet" href="Test.css"></head><body> ???<h1>Hello</h1></body></html>
href="" 具体的css文件路径
使用外部样式表能使css代码和html代码分离,方便维护和复用
内部样式表
将css代码写到html的style标签中
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<meta name="viewport" content="width=device-width, initial-scale=1.0"> ???<meta http-equiv="X-UA-Compatible" content="ie=edge"> ???<title>Document</title> ???<style type="Text/css"> ???h1 ???{ ???????color:red; ???} ???</style></head><body> ???<h1>Hello</h1></body></html>
没有了样式表文件,在某些时候可以提升效率
行内样式表
css代码写在标签的style属性中
<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<meta name="viewport" content="width=device-width, initial-scale=1.0"> ???<meta http-equiv="X-UA-Compatible" content="ie=edge"> ???<title>Document</title></head><body> ???<h1 style="color:red">Hello</h1></body></html>
行内样式不写选择器
HTML引用CSS
原文地址:https://www.cnblogs.com/WOAIXUEXI-/p/9463084.html