Html div 标签的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4593522/
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
Height of the div tag
提问by Rajeev
How to make the div height to 100% so that if i change the div color the whole td color should be changed
如何使 div 高度为 100%,以便如果我更改 div 颜色,则应更改整个 td 颜色
<table style="table-layout:fixed;width:100%;" border="1" cellpadding=0 cellspacing=0>
<tr>
<td width="20%" height="70px" align="center">
<div class="step step1" style="display:block;" step="1">
<a href="#" onclick="javascript:getresource('1');">Video</a><p align="center"> <img id="img1" src="/media/img/accept.png" /><img id="img2" src="/media/img/close.gif" /></p>
</div>
</tr>
</table>
回答by Nick Craver
You just need height: 100%;
in your styling, like this:
你只需要height: 100%;
在你的造型中,像这样:
<div class="step step1" style="display:block; height: 100%;" step="1">
You can test it out here. However, you're missing a </td>
which will give odd behavior in certain DOCTYPEs (it is valid in some), make sure to close that table cell to be safe. One other note, unless you have it overridden somewhere, there's no need for the display: block;
, that's the default display
for a <div>
element.
你可以在这里测试一下。但是,您缺少一个</td>
会在某些 DOCTYPE 中产生奇怪行为(在某些情况下有效),请确保关闭该表格单元格以确保安全。另一个注意事项,除非您在某处覆盖它,否则不需要display: block;
,这display
是<div>
元素的默认值。
回答by Simon
Why don't you change the td's color?
你为什么不改变 td 的颜色?
div's style:
div的风格:
margin: 0;
padding: 0;
width: 100%;
height: 100%;
border: none;
回答by m.edmondson
Why don't you set the td color then?
那你为什么不设置 td 颜色呢?
<td width="20%" height="70px" align="center" style="background-color:Orange;">
回答by Norm
<td style="height: 100%"><div style="height: 100%"></div></td>
to be explicit, but by default it should be the whole height and width of the td provided the td and table have a height.
<td style="height: 100%"><div style="height: 100%"></div></td>
明确地说,但默认情况下,它应该是 td 的整个高度和宽度,前提是 td 和 table 具有高度。