CSS 如何显示一个空白的 div 元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3465203/
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
How to display a blank div element?
提问by Xofo
I have a blank div class that is called spacer ... it has a blue background and a width of 100% of the container (the body) ...
我有一个空白的 div 类,称为间隔...它有一个蓝色背景和容器(主体)的 100% 的宽度...
What I have found is that the spacer will not DISPLAY unless I toss some character in it. I can color the character blue so it is hidden, but that is so inelegant.
我发现除非我在其中折腾一些字符,否则垫片不会显示。我可以将角色涂成蓝色以便隐藏,但这太不优雅了。
What is the CORRECT way to do this.
这样做的正确方法是什么。
回答by Ferdinand Beyer
Give it a height.
给它一个高度。
Otherwise, with no content, it has zero height and is effectively invisible.
否则,如果没有内容,它的高度为零并且实际上是不可见的。
回答by khairil
Add
inside to have some content inside the div
在里面添加一些内容div
回答by anishMarokey
add height
to the div
添加height
到div
<div style="height:10px; width:100%"></div>