是否可以在 xHTML strict 1.0 中使用 CSS 呈现空的 <div style="width:50%"> </div> 而不以像素为单位设置宽度和高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1616879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
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?
提问by Artem
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
inside?
Targets are IE7-8, FF 3.x
是否可以<div style="width:50%"> </div>
在 xHTML strict 1.0 中使用 CSS呈现空值而无需在绝对值中设置宽度和高度并且不在
内部添加?目标是 IE7-8、FF 3.x
Can I somehow render empty div if I want it to get 50% width and variable height?
如果我希望它获得 50% 的宽度和可变的高度,我可以以某种方式呈现空 div 吗?
回答by Christopher Causer
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.
我个人会选择<div style="min-height:1px;width:50%"></div>.
那样,任何非空的 div 都不会像其他答案中那样获得不需要的填充。
Obviously, in a separate CSS file it would be div { min-height:1px; width:50%}
显然,在一个单独的 CSS 文件中,它将是 div { min-height:1px; width:50%}
回答by random
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.
向 the 添加一些填充,DIV
这样即使开始和结束标记之间绝对没有任何内容,您仍然可以看到一些东西。
<div style="width:50%; padding:10px;"></div>
回答by tahdhaze09
Or give it one non-breaking space ( )
或者给它一个不间断的空间 ( )
回答by Sonny Ng
My Experience:
我的经验:
In addition to what user 'random' answered, i need to add space ( ) to make it work Hope this helps!
除了用户“随机”回答的内容之外,我还需要添加空间( )以使其工作希望这会有所帮助!
<div style="width:50%; padding:10px;"> </div>