Make div stretch to fit td height [duplicate]

怎甘沉沦 提交于 2019-12-12 02:46:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!