Note that there are some explanatory texts on larger screens.

plurals
  1. POAre we supposed to be able to trust empty DIVs to show in HTML5?
    text
    copied!<p>Having seen advice seemingly change over the years regarding use of empty DIVs (ie. <code>&lt;DIV CLASS="somediv"&gt;&lt;/DIV&gt;</code>) I'm confused as to the current thinking over whether or not to use <code>&amp;nbsp;</code> when a DIV will have no inner HTML.</p> <p>I can find no definitive confirmation over whether we can rely on all modern browsers to display background color and image correctly at the specified width &amp; height when there is no inner HTML, so I'm thinking maybe we can't rely on it - yet it's such a seemingly basic area.</p> <p>I have even seen suggestions that empty DIVs should never be used - but do specs really state it is 'wrong' to have empty DIVs, or is it just unreliable? (I've tried finding reference to them, but maybe I'm using the wrong terms).</p> <p>To illustrate, here are 5 areas where I would normally use an empty DIV, in the absence of any recommended alternative:</p> <ol> <li>as a placeholder for content which will subsequently be fetched by XHR calls</li> <li>as a way to manually create space in a layout</li> <li>where an image is defined in CSS (as a background image, but will effectively be foreground)</li> <li>where the text will come from the CSS using <code>.somediv:after{content:SOMETEXT}</code></li> <li>where CSS is used to display graph bars etc using solid background color</li> </ol> <p>Maybe there are different answers for each of these, which might explain the complexity over this issue.</p> <p>I have, of course, tried discovering already, but for example the SO question <a href="https://stackoverflow.com/questions/198058/is-necessary-to-show-an-empty-div">Is necessary to show an empty &lt;div&gt;?</a> suggests to me there is a huge amount of "IMHO", "probably", "seems to work" in this area. I would expect that by now that some official consensus has been reached on best practice.</p> <p>So.. should I use <code>&amp;nbsp;</code> and if so should I set font-size to the same as the smaller of DIV width/height to ensure that space is filled in all browsers? Are there any other CSS tricks to ensure this will work in all browsers?</p>
 

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