CSS terminology: what are these called?

前端 未结 7 1543
面向向阳花
面向向阳花 2021-02-13 22:42

Consider:

p {
  ...
}

.foo {
  ...
}

#bar {
  ...
}

What is the correct name for these statements in CSS? I\'ve seen them called selectors, rules or rule

7条回答
  •  逝去的感伤
    2021-02-13 22:46

    A rule would be considered:

    p {…}

    A selector in this case is:

    p

    A rule is made up of selectors and declarations. A declaration is property:value so the entire rule would be:

    selector { property:value }

    A rule can have multiple declarations and multiple selectors so we can actually have:

    selector, selector2
    {
      property:value;
      property2:value;
    } 
    

    A rule set would be multiple rules.

    Here's a quick source on this or the CSS 1 Specification.

提交回复
热议问题