Is it possible to render empty <div style="width:50%"> </div> with CSS in xHTML strict 1.0 without setting width and height in pixels?

Artem picture Artem · Oct 24, 2009 · Viewed 30k times · Source

Is it possible to render empty <div style="width:50%"> </div> with CSS in xHTML strict 1.0 without setting width and height in absolute values and not adding &nbsp; inside? Targets are IE7-8, FF 3.x

Can I somehow render empty div if I want it to get 50% width and variable height?

Answer

Christopher Causer picture Christopher Causer · Jan 12, 2012

I'd personally go for <div style="min-height:1px;width:50%"></div>. That way any non empty divs will not get unwanted padding as in the other answer.

Obviously, in a separate CSS file it would be div { min-height:1px; width:50% }