【发布时间】:2017-09-11 21:42:16
【问题描述】:
我正在尝试在另一个表(“表”)中嵌入一个表(“anotherTable”)。 单元格的宽度以百分比形式指定。
“表格”包含 3 个单元格,宽度分别为 10%、80% 和 10%。
“anotherTable”包含 5 个单元格,宽度分别为 20%、20%、20%、20% 和 20%。
我需要“anotherTable”中的单元格宽度相对于“table”的单元格 2。我怎样才能做到这一点?
目前,“anotherTable”中的单元格宽度是特定于视口的。
这是我的代码:https://jsfiddle.net/madathil/03u7947p/
<html lang="en">
<head>
<title>test</title>
<style>
*{margin:0px;padding:0px;}
.cell { border: 1px solid red; border-style: none solid none none; }
</style>
</head>
<body>
<div class="table" style="width: 100%;">
<div class="row" >
<div class="cell" style="width: 10%; background-color: powderblue; float: left;"> </div>
<div class="cell" style="width: 80%; background-color: pink; float: left;">
<div class="anotherTable">
<div class="row">
<div class="cell" style="width: 20%; background-color: lightgreen; float: left; border"> </div>
<div class="cell" style="width: 20%; background-color: lightred; float: left;"> </div>
<div class="cell" style="width: 20%; background-color: lightyellow; float: left;"> </div>
<div class="cell" style="width: 20%; background-color: lightblue; float: left;"> </div>
<div class="cell" style="width: 20%; background-color: orange; float: left;"> </div>
</div>
</div>
</div>
<div class="cell" style="width: 10%; background-color: powderblue; float: left;"> </div>
<div>
</div>
</body>
</html>
【问题讨论】:
-
没有表格...只有 div 和浮动 div。如果您真的想要一个表现得像表格的表格,您应该使用正确的显示/标签。
-
你为什么说宽度是视口特定的?它发生的唯一原因是因为你的边界。
-
@Salketer 我现在看到了,谢谢