gpt4 book ai didi

css - 滚动时粘性表格列右侧出现阴影

转载 作者:行者123 更新时间:2023-12-05 07:08:07 26 4
gpt4 key购买 nike

我目前通过将 border-collapse: separate 应用到 tableborder-right: dashed 1px #dddddd 以及 position: stickyleft: 0td:

enter image description here

当水平滚动时,有没有纯CSS方式让阴影出现如下:

enter image description here

最佳答案

没有纯 CSS 方法来检测 position: sticky 元素。但是有一种方法可以用 JS 检测它并与它上面的任何元素进行交互。

var observer = new IntersectionObserver(function(entries) {
if(entries[0].intersectionRatio === 0)
document.querySelector("#nav-container").classList.add("nav-container-sticky");
else if(entries[0].intersectionRatio === 1)
document.querySelector("#nav-container").classList.remove("nav-container-sticky");
}, { threshold: [0,1] });

observer.observe(document.querySelector("#nav-container-top"));
body {
margin: 0px;
font-family: Roboto, Tahoma;
}

#logo-container {
background-color: #bdc3c7;
height: 100px;
}

#nav-container-top {
background-color: #bdc3c7;
height: 1px;
}

#nav-container {
background-color: #2980b9;
height: 60px;
line-height: 60px;
color: white;
text-align: center;
font-size: 25px;
position: sticky;
top: 0;
font-weight: 700;
transition: font-size 0.2s ease-out;
}

.nav-container-sticky {
background-color: #e74c3c !important;
font-size: 18px !important;
box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

#main-container {
background-color: #ecf0f1;
height: 2000px;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo-container"></div>
<div id="nav-container-top"></div>
<div id="nav-container">Navigation Container</div>
<div id="main-container"></div>
</body>
</html>

从这里获取手册 https://usefulangle.com/post/108/javascript-detecting-element-gets-fixed-in-css-position-sticky

关于css - 滚动时粘性表格列右侧出现阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61944277/

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