Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the idea of "why" is more a "generational" or "authority" view point. If <code>#Parent</code> (of any generation back) says all my children who meet qualification "x" (in your case, <code>span</code>) are going to be given an inheritance of "y" (whatever css property), it doesn't matter what the single individual <code>#Child</code> wants, it needs the authority of the <code>#Parent</code> to get it if the parent has stated otherwise.</p> <p><strong>Added on edit:</strong> The inline <code>style</code> would then be the rebellious child, and the <code>!important</code> the crack down parent. <em>Edit:</em> I kept this for humor, but I don't think it reflects the idea as well as my later statement below.</p> <p><strong>Added on edit to question in comment:</strong> Given:</p> <pre><code>#outer span ... #inner (which is a span element) </code></pre> <p>Then to help insure #inner selection I recommend:</p> <pre><code>body span#inner (*edit:* just span#inner works *edit:* if defined later) </code></pre> <p>or give body an id and</p> <pre><code>#bodyId #inner </code></pre> <p>Of course, these can still be overridden. The more "generations" involved, the more it becomes difficult to change the behavior because of the generational consensus (if great grandpa and grandpa and parent are all in agreement, it's likely the child is not going to get away with doing his own thing).</p> <p><strong>I had to majorly rewrite this section on later edit</strong> Given this HTML:</p> <pre><code>&lt;div id="grandparent"&gt; &lt;div id="parent"&gt; &lt;div id="child"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I had previously stated that "<code>#parent div</code> has greater authority than <code>#grandparent div</code>. Both have generational authority, in fact, an 'equal' generational authority, but the first is 'nearer' generation" wins. <em>The error</em> in that is that "nearer" generationally is not what matters, but rather last to be granted authority. Given equal authority powers, the own designated last is the one that wins.</p> <p>I believe I can still stand by this statement: With that thought in mind, a selector like #child[id] (which outweighs both previous selectors) treats its attributes as permissions for greater authority to rule that which itself controls. Having the # already gave it authority, but not enough to override a # of a earlier generation if that earlier generation also carries another selector granting more authority.</p> <p>So <code>#grandparent div</code> outweighs <code>#child</code> but not <code>div#child</code> <em>if it is last to receive authority [added this]</em>, and not <code>#child[id]</code> because the <code>[id]</code> adds greater authority for the <code>#child</code> to rule itself. If equal selectivity then last one to be granted authority wins.</p> <p>Again, the <code>style</code> attribute setting a style property itself really acts more like a supreme granting of authority to rule oneself, assuming something more "<code>!important</code>" doesn't take it away.</p> <p>As a summary statement to answer "why" it is this way (and not in line with "set" theory), I believe it is not about <em>accuracy</em> or really even <em>specificity</em> (though that is the term used) as indeed then one would expect <code>#ChildsName</code> to be the final unique say in the matter because nothing more specific need be said. Rather, however, while the documentation may not state it as such, "selectivity" is really structured on a granting of <em>authority</em>. Who has the most "rights" to rule the element, and given a "tie", who was the last one to be granted those rights.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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