1

Please may someone explain why the text 'impact on market' is green as opposed to yellow? I was expecting this to be yellow


HTML

<div> 
   <h4> International news </h4>
   <article>
      <h4 class= "headline"> news develop</h4>
      <aside>
         <h4> impact on market </h4>
      </aside>    
   </article>
</div>

CSS

h4 {
   color:blue;
}

.headline {
   color:red;
}

article {
   color:black;
   font-style:normal;
}

aside h4 {
   font-style: italic !important;
   color yellow;
}

article h4 {
   font-style:normal;
   color: green;
}
1
  • 2
    Please include your actual CSS. This is not valid CSS. Commented Aug 21, 2014 at 18:20

3 Answers 3

2

It is because article h4 comes after aside h4 and their degree of specificity are equal. CSS files are processed from top to bottom and if another style comes along with an equal or greater specificity, then that will override the previous style.

You can use this:

side > h4 {
   font-style: italic !important;
   color yellow;
}


article > h4 {
   font-style:normal;
   color: green;
}

Where > means only affect direct descendants. This is typically better to use than !important, since !important is considered the very last resort.


Further reading on CSS specificity:
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
http://css-tricks.com/specifics-on-css-specificity/

Further reading on !important:
http://css-tricks.com/when-using-important-is-the-right-choice/

Sign up to request clarification or add additional context in comments.

Comments

1

The order in which you put them. The last one is the one written last, so therefore more important.

Try:

article aside h4 
{
font-style: italic !important;
color: yellow;
}

Specify the structure more.

Alternative, create a class.

<h4 class="level3"> impact on market </h4>

Then add

.level3
{
 color: yellow;
}

Comments

0

It is all about CSS weights, here

article h4

is overriding

aside h4

you can change order or edit the

aside h4

for

article aside h4

and it will work. Both will work, change order or edit the selector.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.