CSS层级小技巧!如何在滚动时自动添加头部阴影? 折腾教程

站长 折腾 2022-8-24 3867

完整 CSS 代码
  1. header{
  2. position: sticky;
  3. background: #fff;
  4. top: 0;
  5. font-size: 20px;
  6. padding: 10px;
  7. z-index: 1;
  8. }
  9. shadow::before{
  10. content: '';
  11. box-shadow: 0 0 10px 1px #333;
  12. position: fixed;
  13. width: 100%;
  14. }
  15. shadow::after{
  16. content: '';
  17. width: 100%;
  18. height: 30px;
  19. background: linear-gradient(to bottom, #fff 50% , transparent);
  20. position: absolute;
  21. }

HTML 结构也很简单

  1. <header>LOGO</header>
  2. <shadow></shadow>
  3. <main>很多内容文本</main>

 

──── 0人觉得很赞 ────
最新回复 (2)
  • Lv.3 able324 2022-10-11
    0 2
    感谢分享
  • Lv.2 lv1314521 2022-11-8
    0 3
    教程很好,值得学习。
返回