Search code examples
htmlcsshead

Style class superior to all headings (h1-h6)


Is there a way (a class superior to all Hs, 1-6) to set a property shared among all Hs so that you don't have to put it in each one manually? E.g. if I wanted to have an underline at the bottom of each H, I would do

border-bottom:1px solid #999;

Now I have to put it in each one separately whereas the property is the same.

I tried to do

h { border-bottom:1px solid #999; }

but it didn't work.

What I am actually doing is:

.main-heading
{
    border-bottom:1px solid #999;
}

and then

<h3 class="main-heading">My Heading</h3>

and that works but I would rather not use a class with an H tag since it will always be the same (simplicity).


Solution

  • Not really. You can just write a selector that matches all of them:

    h1, h2, h3, h4, h5, h6 {
        border-bottom:1px solid #999;
    }