账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么table中的td设置height:"100%"无效?
    116
    0
    容器中有一个table,我希望这个table能够始终自适应撑满容器,代码如下: < div style = {{ height: "300px" }}> <table style={{ height: "100%" }}> <thead style={{ height: "20%" }}> <tr> <th>张三</th> <th>李四</th> </tr> </thead> <tbody style={{ height: "30%" }}> <tr style={{ height: "50%" }}> <td style={{ height: "100%" }}> <div style={{ height: "100%" }}></div> </td> <td style={{ height: "100%" }}> <div style={{ height: "100%" }}></div> </td> </tr> <tr style={{ height: "50%" }}> <td style={{ height: "100%" }}> <div style={{ height: "100%" }}></div> </td> <td style={{ height: "100%" }}> <div style={{ height: "100%" }}></div> </td> </tr> </tbody> </table></div>问题:在设置tr的高度的情况下,设置td的高度,但是无论设置百分比还是设置固定高度,都会被内部的div撑开,请问有没有什么办法能够解决这个问题呢,让td内部的div高度始终为td高度的100%,并且不会撑开td?
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 宁夜空 超级管理员 1楼

      在表格中设置td的height为100%,但是它可能无法正常工作,原因可能有以下几点:

      1. 确保你的CSS样式正确:确保你已经为td设置了height属性,并且值设置为100%。你可以在样式表中添加以下代码来检查样式是否正确:

      css td { height: 100%; }

      1. 检查td是否在行内:确保td元素在表格中以行内元素呈现。这可以通过在HTML代码中使用<tr>标签来实现:

      ```html

      这是td元素 这是td元素 这是td元素

      ```

      1. 检查td的宽度是否正确:确保td元素的宽度设置为100%。你可以使用width属性来实现:

      css td { width: 100%; }

      1. 检查td元素的背景颜色:确保td元素的背景颜色设置为黑色,以防止td元素被其他内容覆盖。你可以使用background-color属性来实现:

      css td { background-color: #000; }

      1. 检查td元素的字体大小:确保td元素的字体大小设置为100%,以便在表格中正常显示。你可以使用font-size属性来实现:

      css td { font-size: 100%; }

      如果以上检查都没有问题,那么问题可能在于你的表格或表格样式。确保你的表格已经正确地在HTML代码中正确地嵌入,并且你已经正确设置了td元素的样式。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部