我试图构造一个类似于下面的布局:
+---+---+---+
| | | |
+---+---+---+
| |
+-----------+
底部填充上一行的空间。
如果这是一个实际的表,我可以使用<td colspan="3">轻松完成,但由于我只是创建一个类似于表的布局,所以不能使用<table>标记。这是可能的使用CSS?
我试图构造一个类似于下面的布局:
+---+---+---+
| | | |
+---+---+---+
| |
+-----------+
底部填充上一行的空间。
如果这是一个实际的表,我可以使用<td colspan="3">轻松完成,但由于我只是创建一个类似于表的布局,所以不能使用<table>标记。这是可能的使用CSS?
当前回答
这不是CSS权限的一部分。colspan描述页面内容的结构,或者为表中的数据赋予一些含义,这是HTML的工作。
其他回答
提供一个最新的答案:今天最好的方法是使用css网格布局,像这样:
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas:
"top-left top-middle top-right"
"bottom bottom bottom"
}
.item-a {
grid-area: top-left;
}
.item-b {
grid-area: top-middle;
}
.item-c {
grid-area: top-right;
}
.item-d {
grid-area: bottom;
}
以及HTML
<div class="container">
<div class="item-a">1</div>
<div class="item-b">2</div>
<div class="item-c">3</div>
<div class="item-d">123</div>
</div>
我来这里是因为目前WordPress表块不支持colspan参数,我想我会用CSS替换它。这是我的解决方案,假设列的宽度相同:
table { width: 100%; } table td { width: 50%; background: #dbdbdb; text-align: center; } table tr:nth-child(2n+1) { position:relative; display:block; height:20px; background:green; } table tr:nth-child(2n+1) td { position:absolute; left:0; right:-100%; width: auto; top:0; bottom:0; background:red; text-align:center; } <table> <tr> <td>row</td> </tr> <tr> <td>cell</td> <td>cell</td> </tr> <tr> <td>row</td> </tr> <tr> <td>cell</td> <td>cell</td> </tr> </table>
Media Query类可用于实现带有重复标记的可传递内容。下面是我使用bootstrap的方法:
<tr class="total">
<td colspan="1" class="visible-xs"></td>
<td colspan="5" class="hidden-xs"></td>
<td class="focus">Total</td>
<td class="focus" colspan="2"><%= number_to_currency @cart.total %></td>
</tr>
colspan 1用于移动,colspan 5用于其他使用CSS的工作。
这不是CSS权限的一部分。colspan描述页面内容的结构,或者为表中的数据赋予一些含义,这是HTML的工作。
尝试添加display: table-cell;宽度:1%;到您的表格单元格元素。
.table-cell { display: table-cell; width: 1%; padding: 4px; border: 1px solid #efefef; } <div class="table"> <div class="table-cell">one</div> <div class="table-cell">two</div> <div class="table-cell">three</div> <div class="table-cell">four</div> </div> <div class="table"> <div class="table-cell">one</div> <div class="table-cell">two</div> <div class="table-cell">three</div> <div class="table-cell">four</div> </div> <div class="table"> <div class="table-cell">one</div> </div>