0

I run into this a lot and it's fairly annoying. Does anyone know about this:

#content h5 {
color:red;
}

#next h5 {
color:blue;
}

When the markup looks like this:

<div id="content>
  <h5>RED</h5>

  <div id="next">
    <h5>BLUE</h5>
  </div>
</div>

The blue h5 will actually appear red, what gives?!

1
  • There is a typo in your markup, id="content" needs a closing quote (assuming this is just a typo in the example). The concept is working okay for me in Chrome, Firefox and IE 8 at jsfiddle.net/AWVdY What browser are you using? Commented Jun 25, 2010 at 20:33

3 Answers 3

2

I had no problems with it. You do have a quote mark missing after content though. Below is what I tested with

<html>
<head>
<style>
#content h5 {
color:red;
}

#next h5 {
color:blue;
}
</style>
</head>
<body>
<div id="content">
  <h5>RED</h5>

  <div id="next">
    <h5>BLUE</h5>
  </div>
</div>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

No, it won't.

Comments

0

That's because of what is known as CSS Specificity, here is a good tutorial about it:

Specifics On CSS Specificity

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.