How do I add a top and bottom shadow while scrolling but only when needed?

前端 未结 3 872
半阙折子戏
半阙折子戏 2020-12-23 12:08

How do I add a shadow when a container overflows but only when needed?

What I mean by this is:

  • if there is content available to scroll
3条回答
  •  温柔的废话
    2020-12-23 12:32

    I think your looking for something like this;

    Reference : LINK

    html {
      background: white;
      font: 120% sans-serif;
    }
    
    .scrollbox {
      overflow: auto;
      width: 200px;
      max-height: 200px;
      margin: 50px auto;
      background: /* Shadow covers */
      linear-gradient(white 30%, rgba(255, 255, 255, 0)), linear-gradient(rgba(255, 255, 255, 0), white 70%) 0 100%, /* Shadows */
      radial-gradient(50% 0, farthest-side, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0)), radial-gradient(50% 100%, farthest-side, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0)) 0 100%;
      background: /* Shadow covers */
      linear-gradient(white 30%, rgba(255, 255, 255, 0)), linear-gradient(rgba(255, 255, 255, 0), white 70%) 0 100%, /* Shadows */
      radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0)), radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, .2), rgba(0, 0, 0, 0)) 0 100%;
      background-repeat: no-repeat;
      background-color: white;
      background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px;
      /* Opera doesn't support this in the shorthand */
      background-attachment: local, local, scroll, scroll;
    }
    • I Show Below Shadow. Go Down Now
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • The end!
    • No shadow here. See Above. Go Up

提交回复
热议问题