Can I target all tags with a single selector?

后端 未结 10 1694
予麋鹿
予麋鹿 2020-12-04 08:44

I\'d like to target all h tags on a page. I know you can do it this way...

h1,
h2,
h3,
h4,
h5,
h6 {
  font: 32px/42px trajan-pro-1,trajan-pro-2;
}

10条回答
  •  清歌不尽
    2020-12-04 09:20

    To tackle this with vanilla CSS look for patterns in the ancestors of the h1..h6 elements:

    AMD RX Series

    These come in different brands and types

    Sapphire RX460 OC 2/4GB

    Available in 2GB and 4GB models

    If you can spot patterns you may be able to write a selector which targets what you want. Given the above example all h1..h6 elements may be targeted by combining the :first-child and :not pseudo-classes from CSS3, available in all modern browsers, like so:

    .row :first-child:not(header) { /* ... */ }
    

    In the future advanced pseudo-class selectors like :has(), and subsequent-sibling combinators (~), will provide even more control as Web standards continue to evolve over time.

提交回复
热议问题