gpt4 book ai didi

css - 响应表 - 将特定单元格中的文本限制为桌面上的一行?

转载 作者:行者123 更新时间:2023-11-28 04:38:09 24 4
gpt4 key购买 nike

我正在尝试让表格中的第二个单元格 width: 100%; 和文本保持在一行上。

移动版本工作正常,但我找不到桌面版本的解决方案,因为最后一个单元格不会折叠第二个单元格中的文本。

链接:CodePen

另外,这还挺管用的:

table {
table-layout: fixed;
width: 100%;
}

但使所有单元格的宽度均匀。 (我希望第二个单元格全宽,其余单元格适应里面的内容)

谢谢!

最佳答案

你应该使用你的th来设置col的宽度:

*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
table {
border-collapse: collapse;
margin: 20px auto;
table-layout: fixed;/* will also fix width to cells if specified */
width: 100%;
}
table thead tr th {
text-align: left;
font-weight: bold;
text-transform: uppercase;
background: #f8f8f8;
}
table thead tr th,
table tbody tr td {
padding: 10px;
}
table tbody tr td {
border: 1px solid #e5e5e5;
}
table tbody tr,
table thead tr {
border: 1px solid #e5e5e5;
}
/* set th width */
table thead tr th:first-child {
border-right: 1px solid #e5e5e5;
width: 2em;/* should be enough*/
}

/* LAST TWO CELLS */

table thead tr th:nth-child(2) ~th {
width: 4em;/* should be enough*/
}
/* end th width */

table tbody tr td:first-child {
text-align:right;
padding:0 0.25em 0 0
}

/* SECOND CELL */

table tbody tr td:nth-child(2) {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
table tbody tr td:nth-child(2) ~td {
background: red;
text-align:center;
}
/* RESPONSIVE */

@media screen and (max-width: 600px) {
table {
width: 100%;
}
table thead {
display: none;
}
table tbody tr {
display: block;
}
table tbody tr td {
display: block;
text-align: center;
border: 0;
border-bottom: 1px solid #e4e5e7;
}
table tbody tr td:first-child {
background: #f8f8f8;
}
table tbody tr td:last-child {
border-bottom: 0px;
}
table tbody tr td:before {
content: attr(data-th);
font-weight: bold;
}
}
<table>
<thead>
<tr>
<th>ID</th>
<th>Post Title</th>
<th></th>
<th></th>
</tr>
<tbody>
<tr>
<td data-th="POST ID: ">1</td>
<td data-th="TITLE: ">Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
<td><a href="#">Edit</a>
</td>
<td><a href="#">Delete</a>
</td>
</tr>
<tr>
<td data-th="POST ID: ">01</td>
<td data-th="TITLE: ">Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
<td><a href="#">Edit</a>
</td>
<td><a href="#">Delete</a>
</td>
</tr>
<tr>
<td data-th="POST ID: ">150</td>
<td data-th="TITLE: ">Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</td>
<td><a href="#">Edit</a>
</td>
<td><a href="#">Delete</a>
</td>
</tr>
</table>

关于css - 响应表 - 将特定单元格中的文本限制为桌面上的一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41368260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com