1. Grammar introduction:
1. A CSS rule consists of two main parts: a selector, and one or more declarations:
(1) A selector is usually an HTML element that you need to change the style of.
(2), each statement consists of an attribute and a value.
(3) Attribute is the style attribute you want to set. Each attribute has a value. Attributes and values are separated by colons.
2. Examples
CSS declarations always end with a semicolon ; and declarations are always enclosed in curly braces {}
p {color:red;text-align:center;}
To make CSS more readable, you can describe only one property per line:
p {
color:red;
text-align:center;
}
2. CSS Comments
Comments are used to explain your code, and feel free to edit it, browsers ignore it.
CSS comments start with /* and end with */ , examples are as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS基础学习</title>
<style>
h1 {
/* 字体颜色设置为红色*/
color: red;
}
p {
/* 段落 添加背景*/
background-color: aqua;
/* 段落 文字居中显示*/
text-align: center;
}
</style>
</head>
<body>
<h1>这是一个标题</h1>
<p>这是一个段落。</p>
</body>
</html>