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?
Asked Answered
C

4

23

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?

Coalfield answered 24/10, 2009 at 3:44 Comment(2)
In a standards compliant browser, an empty div without vertical padding has zero height. What do you expect to be rendered?Unlatch
I expect to be rendered a 50% empty space before next float:left; display:inlide; elementCoalfield
L
25

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>
Letsou answered 24/10, 2009 at 11:14 Comment(0)
P
34

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

Pitapat answered 12/1, 2012 at 14:29 Comment(1)
IMHO this is the best xbrowser solutionVancouver
L
25

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>
Letsou answered 24/10, 2009 at 11:14 Comment(0)
O
9

Or give it one non-breaking space (&nbsp;)

Osman answered 26/10, 2009 at 18:36 Comment(1)
I had to make this lowercaseBroad
L
2

My Experience:

In addition to what user 'random' answered, i need to add space (&nbsp;) to make it work Hope this helps!

    <div style="width:50%; padding:10px;">&nbsp;</div>
Lundeen answered 4/10, 2013 at 1:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.