CSS:将背景渐变添加到 div 底部时,背景渐变不跟随滚动条

问题描述 投票:0回答:1

我正在尝试在 a 的底部添加白色淡入淡出效果,乍一看似乎效果很好。但是当我向下滚动时,我可以看到这种淡入淡出不再位于底部。有谁知道为什么会发生这种情况以及如何解决它?

我在 postimg.cc` 上上传了 2 张图片,所以你可以看看它是什么样子的: 图片1图2

.details {
    position: relative;
    padding: 10px;
    overflow-y: scroll;
    &::-webkit-scrollbar {
        background-color: $c-grey-50;
        width: 0.375rem;
        border-radius: $br-4;
    }
    &::-webkit-scrollbar-thumb {
        background-color: $c-grey-200;
        border-radius: $br-4;
        transition: $tr-smooth;
    }
    &::before {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 20px;
        background: linear-gradient(
            to bottom,
            rgba(255, 255, 255, 0),
            #ffffffda
        );
        z-index: 1;
    }
}
html css sass styles
1个回答
0
投票

正确的方法是在

.details
背景本身中处理它。在 linear-gradient 中使用
色标

body {
  background: skyblue;
}

.details {
  width: 300px;
  height: 100px;
  overflow: auto;
  border: 1px solid blue;
  &::-webkit-scrollbar {
    background-color: $c-grey-50;
    width: 0.375rem;
    border-radius: $br-4;
  }
  &::-webkit-scrollbar-thumb {
    background-color: $c-grey-200;
    border-radius: $br-4;
    transition: $tr-smooth;
  }
  
  background : 
    linear-gradient( 
      to bottom,
      transparent 0 70%,
      white
    );
}
<div class="details">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

© www.soinside.com 2019 - 2024. All rights reserved.