gpt4 book ai didi

html - 滚动条 CSS 仅到表格

转载 作者:行者123 更新时间:2023-11-27 23:35:35 25 4
gpt4 key购买 nike

我已经创建了一个响应式表格 CSS,我想要一个特定的 CSS 到表格的滚动条。

但是,当插入这段代码时,浏览器滚动条也会发生变化。

如何将此设计专门用于我的 table ?

body {
padding:1.5em;
background: #f5f5f5
}

table {
border: 1px #a39485 solid;
font-size: .9em;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,.25);
width: 100%;
table-layout: fixed;
border-collapse: collapse;
border-radius: 5px;
overflow: hidden;
}

th {
text-align: center;
}

thead {
font-weight: bold;
color: #fff;
background: #0088CC;
}

td, th {
padding: 1em .5em;
vertical-align: middle;
}

td {
border-bottom: 1px solid rgba(0,0,0,.1);
background: #fff;
}

a {
color: #73685d;
}

@media all and (max-width: 768px) {

table, thead, tbody, th, td, tr {
display: block;
}

th {
text-align: right;
}

table {
position: relative;
padding-bottom: 0;
border: none;
box-shadow: 0 0 10px rgba(0,0,0,.2);
}

thead {
float: left;
white-space: nowrap;
}

tbody {
overflow-x: auto;
overflow-y: hidden;
position: relative;
white-space: nowrap;
}

tr {
display: inline-block;
vertical-align: top;
}

th {
border-bottom: 1px solid #a39485;
}

td {
border-bottom: 1px solid #e5e5e5;
}


}

::-webkit-scrollbar {
width: 12px;
}

/* Track */
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
-webkit-border-radius: 10px;
border-radius: 10px;
}

/* Handle */
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(255,0,0,0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(255,0,0,0.4);
}

请帮忙。

最佳答案

通过将表格放在滚动条选择器之前,您应该能够像任何其他 css 元素一样专门针对表格滚动条。所以你可以这样做:

table::-webkit-scrollbar{
/*Your styles here*/
}
table::-webkit-scrollbar-thumb{
/*Your styles here*/
}
table::-webkit-scrollbar-thumb:window-inactive{
/*Your styles here*/
}

这里的概念证明:http://codepen.io/supah_frank/pen/JooNKx

编辑:此外,我在 chrome 中玩这个时注意到一些奇怪的怪癖(不知道它是否会影响其他浏览器)。

首先,滚动条的 css 似乎已缓存,因此请确保在更改 css 后进行硬刷新 (ctrl + F5)。

其次,即使您没有对其进行样式设置,您也需要在对滚动条进行任何其他更改之前针对 {your element}::-webkit-scrollbar 应用一些样式元素(我发现 display: block 如果你真的不想做任何改变就可以工作)。如果你不定位它,滚动条上的其他 css 都不会因为一些奇怪的原因而工作。

关于html - 滚动条 CSS 仅到表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57258798/

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