CSS Syntax

CSS Syntax

CSS 规则集(rule-set)由选择器和声明块组成:

CSS Selekta

The selector points to the HTML element you need to style.

A declaration block contains one or more declarations separated by semicolons.

Each declaration contains a CSS property name and a value, separated by a colon.

Multiple CSS declarations are separated by semicolons, and declaration blocks are enclosed in curly braces.

Example

In this example, all <p> elements will be centered and have red text color:

p {
  color: red;
  text-align: center;
}

Try It Yourself

Example Explanation

  • p Is in CSSSelector(It points to the HTML element to be styled: <p>).
  • color Is an attributered Is an attribute value
  • text-align Is an attributecenter Is an attribute value

In the next chapter, you will learn more about CSS selectors and CSS properties.