Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Which is faster?</p> </blockquote> <p>Like Cody and thirtydot said, theoretically using <code>&gt;</code> should be faster, but even styling for IE6 is less a waste of your time than styling for performance. Browsers are <em>fast enough</em>; trust your <em>browsers</em>, not the <em>people</em> who tell you this, especially not those who don't provide any <em>browser</em> benchmarks to back their claims.</p> <blockquote> <p>any reliability problem for any of this?</p> </blockquote> <p>Sure. Besides IE6 not supporting <code>&gt;</code> at all as thirtydot mentions, there's also the difference in elements matched since <code>&gt;</code> and the whitespace combinators select different things:</p> <pre><code>&lt;section class="slide"&gt; &lt;div&gt; &lt;span&gt;&lt;/span&gt; &lt;!-- [1] --&gt; &lt;div&gt; &lt;span&gt;&lt;/span&gt; &lt;!-- [2] --&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;p&gt; &lt;span&gt;&lt;/span&gt; &lt;!-- [3] --&gt; &lt;/p&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p>What's selected and what's not:</p> <ol> <li><p><strong>Selected by both selectors</strong><br> This <code>span</code> is a child of a <code>div</code> which is a child of an element with class <code>slide</code>. Since <code>span</code> is a child of <code>div</code>, it's also a descendant of <code>div</code>. Likewise for <code>div</code> and its <code>.slide</code> parent/ancestor.</p> <p>On hovering the <code>.slide</code> element, this <code>span</code> is selected. The rule applied is the second one because both selectors are of equal specificity, but the second one, well, comes second.</p></li> <li><p><strong>Selected only by <code>.slide:hover div span</code></strong><br> This <code>span</code> is in a <code>div</code>, <em>but</em> its parent <code>div</code> is located in <em>another</em> <code>div</code> that doesn't have the class <code>slide</code>. So the first selector doesn't find this element.</p> <p>The inner parent <code>div</code> is, however, a grandchild of a <code>.slide</code> element. Regardless of depth, it's still in some way a descendant of <code>.slide</code> (it's contained somewhere within it).</p> <p>On hovering the <code>.slide</code> element, this <code>span</code> is selected. The rule applied is the second one because it's the only one that matches.</p></li> <li><p><strong>Selected only by <code>.slide:hover div span</code></strong><br> This <code>span</code>'s parent is a <code>p</code> element, not a <code>div</code>. Easy enough; the first selector doesn't find this element.</p> <p>The <code>span</code> is, however, a grandchild of a <code>div</code> element, which itself is inside a <code>.slide</code>.</p> <p>On hovering the <code>.slide</code> element, this <code>span</code> is selected. The rule applied is the second one because it's the only one that matches.</p></li> </ol> <p>One last thing: in all three scenarios do you find that the rules in only the second selector are applied. <strong>This is purely coincidental</strong>; the differences in how supporting browsers look for elements to match are still real.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload