Can I target all tags with a single selector?

后端 未结 10 1697
予麋鹿
予麋鹿 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:28

    You could .class all the headings in Your document if You would like to target them with a single selector, as follows,

    ...heading text...

    ...heading text...

    and in the css

    .heading{
        color: #Dad;
        background-color: #DadDad;
    }
    

    I am not saying this is always best practice, but it can be useful, and for targeting syntax, easier in many ways,

    so if You give all h1 through h6 the same .heading class in the html, then You can modify them for any html docs that utilize that css sheet.

    upside, more global control versus "section div article h1, etc{}",

    downside, instead of calling all the selectors in on place in the css, You will have much more typing in the html, yet I find that having a class in the html to target all headings can be beneficial, just be careful of precedence in the css, because conflicts could arise from

提交回复
热议问题