gpt4 book ai didi

html - 如何修复悬停时的渐变过渡

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

我目前正在研究从背景到背景渐变的悬停过渡。但我希望它更改表格行,而是更改表格的整个背景。

这是 JSFiddle显示将鼠标悬停在表格行上时发生的情况

我试过使用显示 block ,它通过过渡更改表格行背景,但随后它弄乱了我的整个表格行。

表格的背景发生变化,但只需更改表格行。

.container #table {
width: 100%;
font-weight: bold;
border-spacing: 0px 15px;
}
.container #table tr {
position: relative;
background-color: #273240;
z-index: 1;
}
.container #table tr::before {
position: absolute;
content: "";
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to right, #0089e0, #c0c1c1);
z-index: -1;
transition: opacity 0.5s linear;
opacity: 0;
}
.container #table tr:hover::before {
opacity: 1;
}
.container #table tr th {
height: 35px;
font-size: 10px;
text-align: left;
font-weight: bold;
text-transform: uppercase;
background-color: #273240;
}
.container #table tr th:nth-child(n+5) {
width: 75px;
}
.container #table tr td {
padding: 0px;
font-size: 12px;
font-style: italic;
}
.container #table tr td:first-child {
width: 25px;
font-style: normal;
font-weight: 500;
padding-left: 25px;
}
.container #table tr td div {
max-height: 70px;
padding: 25px 0px;
transition: max-height 0.5s, padding 0.5s;
}
.container #table tr td i {
font-size: 12px;
}
<div class="container">
<table id="table">
<tr>
<th></th>
<th>POS</th>
<th>TEAM</th>
<th>DRIVER</th>
<th>MUG</th>
<th>SPA</th>
<th>BRN</th>
<th>POR</th>
<th>BAR</th>
<th>TOT</th>
</tr>
<tbody>
<tr>
<td></td>
<td>1ST</td>
<td>PROSPORT PERFORMANCE (85)</td>
<td>ROBERT RENAUER</td>
<td>24</td>
<td>28</td>
<td>33</td>
<td>-</td>
<td>-</td>
<td>85</td>
</tr>
</tbody>
</table>
</div>

最佳答案

th/td 上制作背景和伪元素,并使用 background-attachment:fixed 模拟连续背景:

.container #table {
width: 100%;
font-weight: bold;
border-spacing: 0px 15px;
}
.container #table tr >* {
position: relative;
background-color: #273240;
z-index: 1;
}
.container #table tr > *::before {
position: absolute;
content: "";
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to right, #0089e0, #c0c1c1) fixed;
z-index: -1;
transition: opacity 0.5s linear;
opacity: 0;
}
.container #table tr:hover > *::before {
opacity: 1;
}
.container #table tr th {
height: 35px;
font-size: 10px;
text-align: left;
font-weight: bold;
text-transform: uppercase;
background-color: #273240;
}
.container #table tr th:nth-child(n+5) {
width: 75px;
}
.container #table tr td {
padding: 0px;
font-size: 12px;
font-style: italic;
}
.container #table tr td:first-child {
width: 25px;
font-style: normal;
font-weight: 500;
padding-left: 25px;
}
<div class="container">
<table id="table">
<tr>
<th></th>
<th>POS</th>
<th>TEAM</th>
<th>DRIVER</th>
<th>MUG</th>
<th>SPA</th>
<th>BRN</th>
<th>POR</th>
<th>BAR</th>
<th>TOT</th>
</tr>
<tbody>
<tr>
<td></td>
<td>1ST</td>
<td>PROSPORT PERFORMANCE (85)</td>
<td>ROBERT RENAUER</td>
<td>24</td>
<td>28</td>
<td>33</td>
<td>-</td>
<td>-</td>
<td>85</td>
</tr>
</tbody>
</table>
</div>

关于html - 如何修复悬停时的渐变过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56322908/

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