W3C home > Mailing lists > Public > www-style@w3.org > November 2010

Re: [css3-selectors] What's the point of :empty?

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Tue, 02 Nov 2010 11:15:33 -0400
Message-ID: <4CD02B15.6010804@mit.edu>
To: Rob Crowther <robertc@boogdesign.com>
CC: www-style@w3.org
On 11/2/10 10:56 AM, Rob Crowther wrote:
> The selector 'div:empty' only selects div one, because all the others
> end up with an all whitespace text node as a child.

For what it's worth, this is why Gecko has a :-moz-only-whitespace (that 
we mostly use in our quirks-mode stylesheet)....

> The top row has the divs set to display: inline-block, the bottom row
> has them float: left. The last div (with the &nbsp;) appears below all
> the others on the top row in Firefox, Chrome and Opera (so I assume
> that's correct behaviour), but why? Something to do with text alignment?
> And why would it affect div four, but not two or three?

For purposes of CSS, divs one, two, and three end up with no child boxes 
(because all the whitespace is trimmed).  The relevant part of the spec 
is this section 10.8.1 last paragraph:

   The baseline of an 'inline-block' is the baseline of its last line
   box in the normal flow, unless it has either no in-flow line boxes or
   if its 'overflow' property has a computed value other than 'visible',
   in which case the baseline is the bottom margin edge.

Since the default vertical-align value is baseline, this lines up the 
bottom margin edge of blocks 1-3 with the baseline of the last (and 
only) line of text in block 4, which is near the top of the block.

> And, finally, if there is a layout impacting difference between two,
> three and four based on their contents, why is there not a selector I
> can target them with? (Or is there?)

Note that there can also be layout differences between blocks 1, 2, and 
3, depending on the styles applied; try setting |#one > div { 
white-space: pre; }|....

Received on Tuesday, 2 November 2010 15:16:07 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:40 UTC