Is there any way to specify a CSS shorthand for “all elements except the first/last”?

前端 未结 4 946
情歌与酒
情歌与酒 2020-12-24 00:28

Very often, it\'s natural to need to specify a CSS style for all elements except the first (or the last). For example, when styling paragraphs, you wish to add a bottom marg

4条回答
  •  一生所求
    2020-12-24 01:26

    Well, you could do:

    p:not(:first-child) {...}
    

    But only the most recent browsers support the :not psuedo-class.

    Other than that, no. Your best option is to specify a style for all and then override it for the first/last.

提交回复
热议问题