[原生table] table td 下的内容高度100%自适应

top、效果图

在这里插入图片描述

一、顶级设置高度 100%重点

.table-warp {
	height: 100%;
}

二、css 代码

.table-warp {
   height: 100%;
 }
 table {
   border-collapse: collapse;
   border-spacing: 0px;
   table-layout: fixed;
   width: 300px;
   height: 100%;
 }
 tr > td,
 tr > th {
   border: 1px solid red;
   word-wrap: break-word;
   height: 100%;
 }
 .item {
   display: flex;
   height: 100%;
 }
 .label {
   display: flex;
   align-items: center;
   height: 100%;
   width: 60px;
   background-color: aqua;
   padding: 10px;
   box-sizing: border-box;
 }
 .value {
   display: flex;
   align-items: center;
   height: 100%;
   flex: 1;
   margin: auto;
 }
 input {
   width: 100%;
 }

三、html 代码

<div class="table-warp">
   <table>
     <tr>
       <th></th>
       <th></th>
     </tr>
     <tr>
       <td>
         <div class="item">
           <div class="label">我是标题我是标题我是标题我是标题我是标题</div>
           <div class="value">
             <input />
           </div>
         </div>
       </td>
       <td>
         <div class="item">
           <div class="label">我是标题</div>
           <div class="value">
             <input />
           </div>
         </div>
       </td>
     </tr>
     <tr>
       <td>
         <div class="item">
           <div class="label">我是标题</div>
           <div class="value">
             <input />
           </div>
         </div>
       </td>
       <td>
         <div class="item">
           <div class="label">我是标题啊啊啊啊啊啊啊啊</div>
           <div class="value">
             <input />
           </div>
         </div>
       </td>
     </tr>
   </table>
 </div>

四、全部 html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .table-warp {
        height: 100%;
      }
      table {
        border-collapse: collapse;
        border-spacing: 0px;
        table-layout: fixed;
        width: 300px;
        height: 100%;
      }
      tr > td,
      tr > th {
        border: 1px solid red;
        word-wrap: break-word;
        height: 100%;
      }
      .item {
        display: flex;
        height: 100%;
      }
      .label {
        display: flex;
        align-items: center;
        height: 100%;
        width: 60px;
        background-color: aqua;
        padding: 10px;
        box-sizing: border-box;
      }
      .value {
        display: flex;
        align-items: center;
        height: 100%;
        flex: 1;
        margin: auto;
      }
      input {
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div class="table-warp">
      <table>
        <tr>
          <th></th>
          <th></th>
        </tr>
        <tr>
          <td>
            <div class="item">
              <div class="label">我是标题我是标题我是标题我是标题我是标题</div>
              <div class="value">
                <input />
              </div>
            </div>
          </td>
          <td>
            <div class="item">
              <div class="label">我是标题</div>
              <div class="value">
                <input />
              </div>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            <div class="item">
              <div class="label">我是标题</div>
              <div class="value">
                <input />
              </div>
            </div>
          </td>
          <td>
            <div class="item">
              <div class="label">我是标题啊啊啊啊啊啊啊啊</div>
              <div class="value">
                <input />
              </div>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值