How to ignore certain elements of a CSS style in HTML?

Basically, I want to have every instance of a heading <h1> have an upper and lower margin EXCEPT for one. Is this possible? Can i re-assign the margin setting in <h1>? ex. <h1 margin-top=0>

Update:

I’ve defined <h1> in the CSS to have margins.

3

✅ Answers

? Favorite Answer

  • The HTML like:

    <h1 id=”myh1″ style=”margin-top: 0px;”>

    should override the CSS, but if it doesn’t you can go:

    <h1 id=”myh1″ style=”margin-top: 0px; !important”>

  • The easiest way would just be to specify a specific class or id attribute to the exception.

    For example:

    <h1>Standard Header</h1>

    <h1 id=”special”>Special Header</h1>

    <h1>Another standard header</h1>

    In CSS:

    h1 {

        margin: 5px 0;

    }

    h1#special {

        margin: 0;

    }

    It’s important that the h1#special rule (you could probably just call it #special as well, or use a class) is below the first one, so that it’s able to take effect.

  • Neatest way to do it is specify an id for that one instance. See http://www.w3schools.com/css/css_id_class.asp for details.

  • Leave a Comment