使div拉伸以适合td高度 [英] Make div stretch to fit td height

查看:293
本文介绍了使div拉伸以适合td高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,

<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>

这种风格,

.the-div
{
  height: 100%;
  background-color: red;
}

.the-div-w-height
{
  height : 100px;
  background-color: yellow;
}

我想让td内的红色div伸展,另一个div可以根据内容改变高度,第一个div应随表格延伸

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

谢谢

推荐答案

在父母 td上添加 height:100%

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;
}

这篇关于使div拉伸以适合td高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆