gpt4 book ai didi

html - 使表头保持固定位置,并保持最长td的宽度

转载 作者:行者123 更新时间:2023-11-28 09:21:54 26 4
gpt4 key购买 nike

我只是想不通是什么问题,我有一个 HTML 表格,我想让表格标题保持在固定位置并保持最长 td 的宽度。我需要它用于脚本,并且第 th 个元素必须是固定宽度,没有 javascript 和简单的 CSS

    BODY {
font-family: Arial;
font-size: 8pt
}
.focim {
margin-left: 400px;
color: Black;
font-family: Arial;
font-size: 15pt;
font-weight: 900;
padding-bottom: 20px;
text-decoration: underline
}
Time {
color: Black;
font-family: Arial;
font-size: 10pt;
font-weight: 500;
padding-bottom: 20px
}
TABLE {
border-width: 3px;
border-style: solid;
border-color: Black;
border-collapse: collapse;
}
TH {
font-family: Arial;
font-size: 10pt;
border-width: 1px;
border-style: solid;
border-color: Black;
background: #b3b3b3;
}
TR:first-child {
position: fixed;
margin-top: 0px;
white-space: nowrap;
}
TD {
white-space: nowrap;
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: Black
}
TD:first-child {
background-color: #C19A6B;
padding-right: 5px;
padding-left: 5px
}
TR:nth-child(even) {
background-color: #dddddd;
}
tr:hover td {
background: #4E5066;
color: #FFFFFF;
border-top: 1px solid #22262e;
border-bottom: 1px solid #22262e;
}
<table>
<colgroup>
<col/>
<col/>
<col/>
<col/>
</colgroup>
<tr>
<th>Name</th>
<th>IP_Addresses0</th>
<th>Domain</th>
<th>LocalPath0</th>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>



</table>

最佳答案

试试这个例子。

BODY {
font-family: Arial;
font-size: 8pt
}
.focim {
margin-left: 400px;
color: Black;
font-family: Arial;
font-size: 15pt;
font-weight: 900;
padding-bottom: 20px;
text-decoration: underline
}
Time {
color: Black;
font-family: Arial;
font-size: 10pt;
font-weight: 500;
padding-bottom: 20px
}
TABLE {
border-width: 3px;
border-style: solid;
border-color: Black;
border-collapse: collapse;
}
TH {
font-family: Arial;
font-size: 10pt;
border-width: 1px;
border-style: solid;
border-color: Black;
background: #b3b3b3;
}
TR:first-child {
position: fixed;
left: 10px;
}
TD {
white-space: nowrap;
border-width: 1px;
padding: 3px;
border-style: solid;
border-color: Black
}
TD:first-child {
background-color: #C19A6B;
padding-right: 5px;
padding-left: 5px
}
TR:nth-child(even) {
background-color: #dddddd;
}
tr:hover td {
background: #4E5066;
color: #FFFFFF;
border-top: 1px solid #22262e;
border-bottom: 1px solid #22262e;
}
<table>
<colgroup>
<col/>
<col/>
<col/>
<col/>
</colgroup>
<tr>
<th>Name</th>
<th>IP_Addresses0</th>
<th>Domain</th>
<th>LocalPath0</th>
</tr>
<tr>
<th>Name</th>
<th>IP_Addresses0</th>
<th>Domain</th>
<th>LocalPath0</th>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>

<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>
<tr>
<td>name</td>
<td>someip</td>
<td>domain</td>
<td>path</td>
</tr>



</table>

关于html - 使表头保持固定位置,并保持最长td的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26055957/

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