我有一个放置在容器内的表格。
我想让表格的宽度在两侧比容器多20像素,但我无法实现这一点。
我尝试将表格元素上的“ margin:0 auto;”更改为“ margin:0 -40px;”,以便它在容器的每侧超出20px,但那只是将整个表格向左移动。
我想让表格的宽度在两侧比容器多20像素,但我无法实现这一点。
我尝试将表格元素上的“ margin:0 auto;”更改为“ margin:0 -40px;”,以便它在容器的每侧超出20px,但那只是将整个表格向左移动。
.container {
width: 400px;
display: block;
border: 2px solid red;
margin: 0 auto;
}
table {
border-spacing: 1;
border-collapse: collapse;
background: white;
border-radius: 10px;
overflow: hidden;
width: 100%;
margin: 0 auto;
position: relative;
}
table * {
position: relative;
}
table td,
table th {
padding-left: 8px;
}
table thead tr {
height: 60px;
background: #36304a;
}
table tbody tr {
height: 50px;
}
table tbody tr:last-child {
border: 0;
}
table td,
table th {
text-align: left;
}
table td.l,
table th.l {
text-align: right;
}
table td.c,
table th.c {
text-align: center;
}
table td.r,
table th.r {
text-align: center;
}
.header th {
font-size: 18px;
color: #fff;
line-height: 1.2;
font-weight: unset;
}
tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
tbody tr {
font-size: 15px;
color: #808080;
line-height: 1.2;
font-weight: unset;
}
tbody tr:hover {
color: #555555;
background-color: #f5f5f5;
cursor: pointer;
}
.column {
width: 160px;
}
.column:first-child {
padding-left: 40px;
}
.column:last-child {
padding-right: 40px;
}
<div class="container">
<table>
<thead>
<tr class="header">
<th class="column">1</th>
<th class="column">2</th>
<th class="column">3</th>
</tr>
</thead>
<tbody>
<tr>
<td class="column">mnbvbmvn</td>
<td class="column" data-title="Points">28761528</td>
<td class="column" data-title="Points">Some text here</td>
</tr>
<tr>
<td class="column">adsfasdf</td>
<td class="column" data-title="Points">12341234</td>
<td class="column" data-title="Points">blah blah blah</td>
</tr>
<tr>
<td class="column">ajgsgdsdjha</td>
<td class="column" data-title="Points">85765</td>
<td class="column" data-title="Points">some other text</td>
</tr>
</tbody>
</table>
</div>
display: flex
和flex-flow: column nowrap;
。这实际上会居中内容,但是你会看到它可能会从左右两侧裁剪内容。如何切换这些挑战取决于您的用例。 - Nico O