问题
Hi I have this code,
<html>
<body>
<table>
<tr>
<td>
<div class="the-div">h:100%</div>
</td>
<td>
<div class="the-div-w-height">h:100px</div>
</td>
</tr>
</table>
</body>
</html>
with this style,
.the-div
{
height: 100%;
background-color: red;
}
.the-div-w-height
{
height : 100px;
background-color: yellow;
}
I want to make the red div stretch inside the td, the other div can change in height according to the content, the first div shall stretch with the table
Thank you
回答1:
Adding height: 100%
on parents table
and td
:
http://codepen.io/anon/pen/ByjIv
table {
height: 100%;
}
td {
border: 1px solid #000;
height: 100%;
}
.the-div
{
height: 100%;
background-color: red;
}
.the-div-w-height
{
line-height: 100px;
background-color: yellow;
}
来源:https://stackoverflow.com/questions/24594742/make-div-stretch-to-fit-td-height