如何将table的第一列分成对角两部分?
How to make the first column of a table divided into two parts diagonally?
我有这张图片:
我用 HTML
& CSS
做到了
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
</tbody>
</table>
但是我想把第一行的第一列分成两部分(一条对角线是连接单元格两个角的直线段) 就像我用 paint edited 的图像:
为了做这个风格我选择了第一个th:first-child
基于这个Answer
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
background: linear-gradient(
to top right,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0) calc(50% - 0.8px),
rgba(0, 0, 0, 1) 50%,
rgba(0, 0, 0, 0) calc(50% + 0.8px),
rgba(0, 0, 0, 0) 100%
);
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
是否有任何其他方法或方法可以在不使用 background 和 linear-gradient 的情况下构建此样式?
对于快速和肮脏的格式化感到抱歉,但是从这里借用了 svg 背景,
并将资产和文件定位为 th 中的单独 div。看起来像您要找的东西
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
position: relative;
width: 200px;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M1 0 L0 1 L99 100 L100 99' fill='black' /></svg>");
background-repeat:no-repeat;
background-position:center center;
background-size: 100% 100%, auto;
}
#leftItem {
position:absolute;
left:2px;
bottom:2px;
}
#rightItem {
position:absolute;
right:2px;
top:2px;
}
<table>
<thead>
<tr>
<th>
<div id="leftItem">File</div>
<div id="rightItem">Asset</div>
</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
您可以按照指出的那样使用网格 here
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
display: grid;
width: max-content;
justify-content: space-between;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 1fr;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><line x1='0' y1='0' x2='100' y2='100' stroke='black' vector-effect='non-scaling-stroke'/></svg>");
background-size: 100% 100%;
border: 0;
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
我有这张图片:
我用 HTML
& CSS
做到了
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
</tr>
</tbody>
</table>
但是我想把第一行的第一列分成两部分(一条对角线是连接单元格两个角的直线段) 就像我用 paint edited 的图像:
为了做这个风格我选择了第一个th:first-child
基于这个Answer
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
background: linear-gradient(
to top right,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0) calc(50% - 0.8px),
rgba(0, 0, 0, 1) 50%,
rgba(0, 0, 0, 0) calc(50% + 0.8px),
rgba(0, 0, 0, 0) 100%
);
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
是否有任何其他方法或方法可以在不使用 background 和 linear-gradient 的情况下构建此样式?
对于快速和肮脏的格式化感到抱歉,但是从这里借用了 svg 背景, 并将资产和文件定位为 th 中的单独 div。看起来像您要找的东西
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
position: relative;
width: 200px;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><path d='M1 0 L0 1 L99 100 L100 99' fill='black' /></svg>");
background-repeat:no-repeat;
background-position:center center;
background-size: 100% 100%, auto;
}
#leftItem {
position:absolute;
left:2px;
bottom:2px;
}
#rightItem {
position:absolute;
right:2px;
top:2px;
}
<table>
<thead>
<tr>
<th>
<div id="leftItem">File</div>
<div id="rightItem">Asset</div>
</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
您可以按照指出的那样使用网格 here
table {
border: 1px solid;
border-collapse: collapse;
}
tr,
th,
td {
border: 1px solid;
padding: 10px;
}
/*diagonal line*/
th:first-child {
display: grid;
width: max-content;
justify-content: space-between;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: 1fr;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' preserveAspectRatio='none' viewBox='0 0 100 100'><line x1='0' y1='0' x2='100' y2='100' stroke='black' vector-effect='non-scaling-stroke'/></svg>");
background-size: 100% 100%;
border: 0;
}
<table>
<thead>
<tr>
<th>Asset \ File</th>
<th>Link</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>