gpt4 book ai didi

CSS 表格样式 : Separate Borders and Borders for Row Groups

转载 作者:太空宇宙 更新时间:2023-11-04 07:38:54 25 4
gpt4 key购买 nike

我一直在努力设计这张 table 的样式。标题标题需要有单独的下划线,我需要在两组“名称”行之间有一条分隔线。 (这些在最终渲染中会有所不同。)

这是现在的样子: Table not quite there

这就是我要找的: Photoshopped. Kinda.

如果你想看它的实际效果,我有一个代码笔:Table Styling Codepen

我一直在试验边界折叠。我能够在某些情况下获得单独的边框,而在其他情况下获得部分分隔符。但是总是有问题,比如单元格之间没有间距,所以样式看起来很局促。

这是 HTML:

<table class="data-table">
<thead>
<tr>
<th></th>
<th colSpan="2" class="title">Source</th>
<th colSpan="2" class="title">Destination</th>
</tr>
<tr>
<th></th>
<th colSpan="1" class="fieldname title">Field</th>
<th colSpan="1" class="title">Value</th>
<th colSpan="1" class="fieldname title">Field</th>
<th colSpan="1" class="title">Value</th>
</tr>
</thead>
<tbody class="bodySection">
<tr>
<td rowSpan="2" class="side-title">Name</td>
<td class="fieldname src-data">Short Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Short Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
<tr>
<td class="fieldname src-data">Long Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Long Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
</tbody>
<tbody class="bodySection">
<tr>
<td rowSpan="2" class="side-title">Name</td>
<td class="fieldname src-data">Short Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Short Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
<tr>
<td class="fieldname src-data">Long Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Long Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
</tbody>

这是 CSS:

body {
padding: 10px;
}

.data-table {
width: 100%;
border-spacing: 0 4px;
border-collapse: separate;

thead tr th {
border-collapse: separate;
border-spacing: 0 5px;
}
.title {
border-bottom: 1px solid #bbb;
text-align: left;
border-spacing: 0 5px;
}

.side-title {
transform: rotate(-90deg);
width: 25px;
}
.fieldname {
width: 130px;
}
.fieldvalue.dest-data input[type=text] {
width: 100%;
}
.bodySection {
border-bottom: 10px solid #bbb;
margin-bottom: 10px;
}
tr {
// border-bottom: 10px solid #bbb;
}
}

感谢您的帮助。

最佳答案

将您的 header 替换为(我在每个 th 中添加了一个 div):

<thead>
<tr>
<th></th>
<th colSpan="2" class="title"><div>Source</div></th>
<th colSpan="2" class="title"><div>Destination</div></th>
</tr>
<tr>
<th></th>
<th colSpan="1" class="fieldname title"><div>Field</div></th>
<th colSpan="1" class="title"><div>Value</div></th>
<th colSpan="1" class="fieldname title"><div>Field</div></th>
<th colSpan="1" class="title"><div>Value</div></th>
</tr>
</thead>

将您的 .title 替换为:

.title {
text-align: left;
padding-right: 5px;
}
tr .title:last-child {
padding-right: 0px;
}
.title div {
width: 100%;
border-bottom: 1px solid #bbb;
}

你的 .bodySection 有:

   .bodySection tr:last-child td { 
border-bottom: 1px solid #bbb;
padding-bottom: 15px;
}
.bodySection tr:first-child td {
padding-top: 10px;
}

这是片段:

body {
padding: 10px;
}

.data-table {
width: 100%;
border-spacing: 0 4px;
border-collapse: separate;
}
.title {
text-align: left;
padding-right: 5px;
}
tr .title:last-child {
padding-right: 0px;
}
.title div {
width: 100%;
border-bottom: 1px solid #bbb;
}

.side-title {
transform: rotate(-90deg);
width: 25px;
}
.fieldname {
width: 130px;
}
.fieldvalue.dest-data {
padding-right: 5px;
}
.fieldvalue.dest-data input[type=text] {
width: 100%;
}
.bodySection tr:last-child td {
border-bottom: 1px solid #bbb;
padding-bottom: 15px;
}
.bodySection tr:first-child td {
padding-top: 10px;
}
tr {
// border-bottom: 10px solid #bbb;
}
<table class="data-table">
<thead>
<tr>
<th></th>
<th colSpan="2" class="title"><div>Source</div></th>
<th colSpan="2" class="title"><div>Destination</div></th>
</tr>
<tr>
<th></th>
<th colSpan="1" class="fieldname title"><div>Field</div></th>
<th colSpan="1" class="title"><div>Value</div></th>
<th colSpan="1" class="fieldname title"><div>Field</div></th>
<th colSpan="1" class="title"><div>Value</div></th>
</tr>
</thead>
<tbody class="bodySection">
<tr>
<td rowSpan="2" class="side-title">Name</td>
<td class="fieldname src-data">Short Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Short Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
<tr>
<td class="fieldname src-data">Long Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Long Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
</tbody>
<tbody class="bodySection">
<tr>
<td rowSpan="2" class="side-title">Name</td>
<td class="fieldname src-data">Short Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Short Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
<tr>
<td class="fieldname src-data">Long Name</td>
<td class="fieldvalue src-data"My Store/td>
<td class="fieldname dest-data">Long Name</td>
<td class="fieldvalue dest-data"><input type="text" value="My Store" /></td>
</tr>
</tbody>
</table>

关于CSS 表格样式 : Separate Borders and Borders for Row Groups,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48690257/

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