Are there any CSS standards that I should follow while writing my first stylesheet?

前端 未结 17 650
有刺的猬
有刺的猬 2020-12-13 02:40

I am currently working on my first website. I have no idea where to start on the CSS page, or if there are any standards that I should be following.

I would appreci

17条回答
  •  清歌不尽
    2020-12-13 03:26

    You can save yourself a lot of headache by understanding specificity. When you set a rule for something, if there is a conflicting rule, specificity decides which rule wins.

    A quick (incomplete) rundown:

    An element-wide rule (like p {color:green;}) will be trumped by:
    A class-specific rule (like p.sidenote {color: blue;}), which will be trumped by:
    An id-specific rule (like p#final {color: red;}), which will be trumped by:
    An inline declaration (like

    ), which will be trumped by:
    An important rule (like p#final {color: inherit !important;})

    ...all of which can be trumped by the user's rules.

    The interactions can be complex, but there are mathematic rules underlying them. For a more complete treatment, see Chapter 3 of Eric Meyer's "CSS: The Definitive Guide."

    To recap: if you set a rule and it doesn't seem to affect anything, you've probably got a conflicting rule. To understand why one rule beats the other, learn about specificity.

提交回复
热议问题