css语法由主要两个重要部分构成:选择器以及一条或多条声明(声明组)。一般来说选择器你需要改变样式HTML元素。每条声明由一个属性和一个值组成,属性(property)是您希望设置的样式属性(style attribute);每个属性有一个,属性和值被冒号分开。css声明总是以分号(;)结束,声明组以大括号({})括起来。
实例代码
实列
<html>
<head>
<style>
body {background-color:yellow;}
h1 {font-size:36pt;}
h2 {color:blue;}
p {margin-left:50px;}
</style>
</head>
<body>
<h1>This ball is 3 pt</h1>
<h2>This header is blue</h2>
<p>This picture really</p>
</body>
</html>

<html>
<head>
<style>
body {background-color:tan;}
h1 {color:maroon;font-size:20pt;}
hr {color:navy;}
p {font-size:11pt;margin-left:15px;}
a:link {color:green;}
a:visited {color:yellow;}
a:hover {color:black;}
a:active {color:blue;}
</style>
</head>
<body>
<h1>This is a header 1</h1>
<hr>
<p>You can see that the style
sheet formats the text</p>
<p><a href="https://html99.cn/"
target="_blank">html99.cn</a></p>
</body>
</html>

css实例
CSS声明总是以分号(;)结束,声明组以大括号({})括起来:
p {color:red;text-align:center;
实例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>技术中文网(html99.cn)</title>
<style>
p
{
color:red;
text-align:center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
</body>
</html>

background-color | 背景颜色 |
font-size | 字体大小 |
color | 颜色 |
margin-left | 左边边距 |
text-align | 设置h1h2h3元素的文本对齐方式 |
css注释
通过注释能更快的读懂代码对代码进行解释;
浏览器不会读取注释内容
CSS注释以 "/*" 开始, 以 "*/" 结束, 实例如下:
/*这是个注释*/
p
{
text-align:center;
/*这是另一个注释*/
color:black;
font-family:arial;
}