Skip to main content
Inspiring
July 28, 2017
Answered

restyle h2

  • July 28, 2017
  • 3 replies
  • 401 views

Hi,

I have set many different style assignments to my h2 like this. For no good reason, this one just won't apply. Any ideas?

.myClass h2    {

    color: #233e99;

    font-weight: 900;

    }

<div class="text-center">

      <h2 class="myClass">This Text in a Rich Blue</h2>

</div>

Thanks!

    This topic has been closed for replies.
    Correct answer osgood_

    r_tist  wrote

    Hi,

    I have set many different style assignments to my h2 like this. For no good reason, this one just won't apply. Any ideas?

    .myClass h2    {

        color: #233e99;

        font-weight: 900;

        }

    That says:

    Apply styling to any h2 tag inside a container with the class name of myClass

    You want:

    .text-center h2 {

    }

    or if you have many different h2 styles within the text-center container then follow the other 2 replies and apply them directly to the h2 tag.

    But this get a bit messy IF all the h2 styling is the same

    <div class="text-center">

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    </div>

    When it could be simplified:

    <div class="text-center">

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    </div>

    Choose which option best fits in with your own requirements.

    3 replies

    osgood_Correct answer
    Legend
    July 28, 2017

    r_tist  wrote

    Hi,

    I have set many different style assignments to my h2 like this. For no good reason, this one just won't apply. Any ideas?

    .myClass h2    {

        color: #233e99;

        font-weight: 900;

        }

    That says:

    Apply styling to any h2 tag inside a container with the class name of myClass

    You want:

    .text-center h2 {

    }

    or if you have many different h2 styles within the text-center container then follow the other 2 replies and apply them directly to the h2 tag.

    But this get a bit messy IF all the h2 styling is the same

    <div class="text-center">

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2 class="myClass">This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    </div>

    When it could be simplified:

    <div class="text-center">

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    <h2>This Text in a Rich Blue</h2>

    <p>Some text Some text Some text Some test</p>

    </div>

    Choose which option best fits in with your own requirements.

    Nancy OShea
    Community Expert
    Community Expert
    July 28, 2017

    Try

    h2.myClass  {

        color: #233e99 !important;

        font-weight: 900;

        }

    Nancy O'Shea— Product User & Community Expert
    pziecina
    Legend
    July 28, 2017

    Try doing it the other way around.

    h2 .myClass