javascript - 阻止 div 在桌子上重叠
问题描述
我希望 div 能够识别其空间中已经存在 div 并向下移动空间。在此示例中,我使用了一个超出其 td 宽度的 div (stuff1),并且我希望它被重叠的 td 中的其他 div (stuff4) 容纳和/或容纳。
现表:
我多么想要
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<style>
.red{
background-color:red;
height:20px;
margin-top:2px;
}
.yellow{
background-color:yellow;
height:20px;
margin-top:2px;
}
.head{
background-color:aliceblue;
height:20px;
margin-top:2px;
position:relative;
top:0;
}
td{
vertical-align:top;
}
<table style="width:100%">
<tr>
<th>StuffList1</th>
<th>StuffList2</th>
<th>StuffList3</th>
</tr>
<tr>
<td>
<div class="head">1</div>
<div class="red" style="width:150%">stuff1</div>
<div class="red" style="width:100%">stuff2</div>
</td>
<td>
<div class="head">2</div>
<div class="yellow">stuff4</div>
</td>
<td>
<div class="head">3</div>
<div>stuff5</div>
<div>stuff6</div>
</td>
</tr>
</table>
解决方案
您只需要在第二个 td 中再添加一个 div,如下所示,
<td>
<div class="head">2</div>
<div class="red" style="width:50%"></div>
<div class="yellow">stuff4</div>
</td>
使用此代码,您将达到您想要的结果,但我更喜欢您应该使用带有 rowspan 和 colspan 的 tr td 标签
推荐阅读
- java - 从 dockerfile 构建 docker 映像,无法让 java 正确运行,但可以从映像运行 java 作为 docker run 命令中的命令行参数
- extjs - 如何防止在网格面板中单击单元格时自动水平滚动
- pycharm - 在不同的计算机上使用相同的 workspace.xml
- c - ROT13 实现中的分段错误和警告
- v8 - 这是中间表示吗?
- javascript - chrome.identity.getAuthToken 未定义
- c# - 您可以使用 WCF 配置更改 BehaviorExtension 吗?
- java - 是否可以在 JFrame 中运行进程?
- c++ - 如何在 getline 中删除/忽略超过某个数字的字符?
- ios - 实例将立即被释放,因为属性“imageView”是“弱”