html - 如何在不指定父级大小的情况下强制表中 td 的子级使用 td 的 100% 空间?
问题描述
我有一张这样的表格
<table>
<thead>
<th> </th>
<th>foo1</th>
<th>foo2</th>
</thead>
<tbody>
<tr>
<th>Text that makes the cell use two lines of height</th>
<td className="grid-item">
<b>P</b>
</td>
<td className="grid-item">
<div>✔ 17/10/2019</div>
</td>
</tr>
/* more tr s */
</tbody>
</table>
当点击一个外部按钮时,它会变成这样:
<table>
<thead>
<th> </th>
<th>foo1</th>
<th>foo2</th>
</thead>
<tbody>
<tr>
<th>Text that makes the cell use two lines of height</th>
<td className="grid-item green_border">
<div className="clickeable-cpopup">
<b>P</b>
</div>
</td>
<td className="grid-item green_border">
<div className="clickeable-cpopup">
<div>✔ 17/10/2019</div>
</div>
</td>
</tr>
/* more tr s */
</tbody>
</table>
并且 div "clickeable-cpopup" 有一个 onClick 函数,它需要填充td
其父级的所有空间、高度和宽度,否则我单击td
而不是 div 并且没有任何反应。
"grid-item"
已经padding: 0
和我尝试了适用于的解决方案,display: flex
它"grid-item"
可以填充空间,但表格格式会变得混乱。
我也尝试了更好的结果position: relative
给"grid-item"
andabsolute
和. 可点击的 div 使用了所有空间,但是包含日期的单元格不会调整到其内容(单元格的宽度小于日期的长度)"clickeable-cpopup"
"content"
td
我怎么能做到这一点?我想避免使 td 可点击。
固定单元格大小不是一个好的选择,仅包含的列<b>P</b>
应该小于包含P
和的列, date
P 可能成为日期,反之亦然,并且第一列的某些标题可能使用 2 行高度。当然width: auto
也不行,100%
因为"grid-item"
没有固定的大小
解决方案
推荐阅读
- python - RuntimeError:预期 1D 目标张量,不支持多目标 Python:NumPy
- python - tkinter 是否支持多文档界面 (MDI)?
- android - 如何在 termux 中的 android 10 上运行 react native 程序
- python - 如何使用 Flask REST JSON 模块为所有路由添加前缀?
- android - Android Studio 显示未安装插件的错误
- assembly - 将段偏移地址转换为线性
- graphql - Apollo Server,输入一组不同形状的对象
- python - 'unicode' 对象没有属性 'keys' - 将对象转换为字典 python
- android - 未解析的引用:嵌入和未解析的引用:MainActivity.kt 中的 FlutterActivity
- node.js - 如何在heroku中设置可变存储文件夹?