0

If I have the following HTML:

<div id="container">
   <div id="inner">
   </div>
</div>

Is there any difference , performance wise, between:

#container #inner {
      width:300px;
}

to

#inner {
      width:300px;
}

?

3
  • 2
    Not sure about performance, but nesting ID selectors is almost always pointless. Commented Dec 16, 2010 at 16:18
  • true, I should've used class instead. thanks! Commented Dec 16, 2010 at 16:25
  • screwlewse.com/2010/08/… Commented Dec 16, 2010 at 16:31

3 Answers 3

3

The performance difference will be inconsequential. Try optimizing other parts of your code!

That being said, it's generally best to be as non-specific as possible.

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

Comments

1

wont really affect it,

just CSS selectors with a wide-matching key selector can hurt performance ..

some insight here: http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/

2 Comments

If I understand correctly from the article, in a page where I have many anchor tags, it will be better to give each a class/id and select it by #container a#ID {} than #container a {} ?
@ joel : i believe thats the implication. though it'd be simpler to use #ID {} instead of #container a#ID {}
1

As ids aren't supposed to repeat, you can simply select using #inner

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.