如何使一个没有内容的DIV有宽度? [英] How to make a DIV with no content have a width?
本文介绍了如何使一个没有内容的DIV有宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为DIV添加宽度,但我似乎遇到了问题,因为它没有内容。
这里是我到目前为止的CSS和HTML,但它不工作:
CSS
body {
margin:0 auto;
width:1000px
}
ul {
width:800px;
}
ul li {
clear:both;
}
.test1 {
width:200px;
float:left;
}
HTML
< body>
< div id =test>
< ul>
< li>
< div class =" test1"> width1< / div>
< div class =test1> width2< / div>
< div class =test1> width3< / div>
< / li>
< li>
< div class =test1>< / div>
< div class =test1> width2< / div>
< div class =test1> width3< / div>
< / li>
< li>
< div class =test1>< / div>
< div class =test1> width2< / div>
< div class =test1> width3< / div>
< / li>
< / ul>
< / div>
解决方案>
a div通常至少需要一个不间断的空格(& nbsp;),以便具有宽度。
I am trying to add a width to a DIV, but I seem to be running into a problem because it has no content. Here is the CSS and HTML I have so far, but it is not working:
CSS
body{
margin:0 auto;
width:1000px
}
ul{
width:800px;
}
ul li{
clear:both;
}
.test1{
width:200px;
float:left;
}
HTML
<body>
<div id="test">
<ul>
<li>
<div class="test1">width1</div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
<li>
<div class="test1"></div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
<li>
<div class="test1"></div>
<div class="test1">width2</div>
<div class="test1">width3</div>
</li>
</ul>
</div>
解决方案
a div usually needs at least a non-breaking space ( ) in order to have a width.
这篇关于如何使一个没有内容的DIV有宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文