<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>溢出滚动渐变</title>
<style>
.box {
position: relative;
}
.box::after {
content: '';
position: absolute;
width: 250px;
height: 50px;
bottom: 0;
background-image: linear-gradient(
rgba(255, 255, 255, 0.001),
white
);
pointer-events: none;
}
.obj {
width: 250px;
height: 200px;
overflow-y: scroll;
background: white;
padding: 0 15px;
line-height: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<div class="obj">
position: relative 在父级上为伪元素建立笛卡尔定位上下文。
::after 定义伪元素。
background-image: linear-gradient(...) 添加从透明渐变为白色(从上到下)的线性渐变。
position: absolute 从文档流中取出伪元素,并将其相对于父元素定位。
width: 240px 匹配滚动元素的大小(它是具有伪元素的父元素的子元素)。
height: 25px 是衰落梯度伪元素的高度,应当保持相对较小。
bottom: 0 将伪元素定位在父元素的底部。
pointer-events: none 指定伪元素不能是鼠标事件的目标,允许其后面的文本仍然是可选/交互式的。
</div>
</div>
</body>
</html>
css视觉--溢出滚动渐变
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 现在好多app(喜马拉雅,新浪微博等)都有类似UIPageViewController的效果,实际开发中我们要进行...
- 阻止移动端窗体滚动的JS/CSS处理 首先CSS层面,在 标签上增加一个类名,例如noscroll,然后配合如下C...