Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Tags:

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?

like image 423
Artem Avatar asked Oct 24 '09 03:10

Artem


People also ask

Does empty DIV take space?

When you set a particular height and width for a div, it does not matter if it is empty or overflowed, it will only take up the space as given in the code.


2 Answers

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% }

like image 79
Christopher Causer Avatar answered Sep 23 '22 17:09

Christopher Causer


Add some padding to the DIV so that even if there is absolutely nothing between the opening and the closing tags, you still see something.

<div style="width:50%; padding:10px;"></div> 
like image 21
random Avatar answered Sep 26 '22 17:09

random