是否需要显示一个空的< div>? [英] Is necessary to show an empty <div>?
本文介绍了是否需要显示一个空的< div>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示一个背景颜色的div,其高度和宽度设置为100%,但没有内容。是否有可能做到这一点,而不是把一个& nbsp;内部?
编辑:感谢Mark Biek指出,带有宽度和高度样式的空白div显示了我的期望。我的div位于表格单元格中,它没有显示。
< table style =width:100%> ;
< tr>
< th>标头< / th>
< td>< div id =foo>< / div>< / td>
< / tr>
< / table>
解决方案
这似乎适用于Firefox,Safari,IE6, &安培; IE7。
< html>
< head>
< style>
#foo {
background:#ff0000;
宽度:100%;
身高:100%;
border:2px虚线黑色;
}
< / style>
< / head>
< body onload =>
< div id =foo>< / div>
< / body>
< / html>
I'd like to show a div that has a background-color with the height and width set to 100% but no content. Is it possible to do that without putting a inside?
Edit: Thanks to Mark Biek for pointing out that empty div with width and height styles shows how I'd expect. My div is in a table cell, where it does not show.
<table style="width:100%">
<tr>
<th>Header</th>
<td><div id="foo"></div></td>
</tr>
</table>
解决方案
This seems to work in Firefox, Safari, IE6, & IE7.
<html>
<head>
<style>
#foo{
background: #ff0000;
width: 100%;
height: 100%;
border: 2px dashed black;
}
</style>
</head>
<body onload="">
<div id="foo"></div>
</body>
</html>
这篇关于是否需要显示一个空的< div>?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文