码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • css 滚动贴合


    大部分人基本上都会使用JS实现页面的滚动贴合效果,在学习的过程中,偶然发现原生CSS实现滚动贴合效果的方法;

    html 代码

    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>滚动贴合title>
    6. <style>
    7. * {
    8. margin: 0;
    9. padding: 0;
    10. }
    11. .container {
    12. width: 1200px;
    13. height: 100vh;
    14. overflow-y: scroll;
    15. scroll-snap-type: y mandatory;
    16. margin: auto;
    17. }
    18. .container .item {
    19. width: 100%;
    20. height: 100%;
    21. padding: 30px;
    22. border: 1px dashed #cccccc;
    23. box-sizing: border-box;
    24. scroll-snap-align: start;
    25. border-radius: 10px;
    26. background: #f9f9f9;
    27. margin-bottom: 16px;
    28. }
    29. .container .item:last-child {
    30. margin-bottom: 0;
    31. }
    32. .container .item img {
    33. width: 100%;
    34. height: 100%;
    35. object-fit: cover;
    36. border: 1px solid #ffffff;
    37. transition: all 0.4s;
    38. }
    39. .container .item:hover img {
    40. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    41. border-radius: 10px;
    42. }
    43. style>
    44. head>
    45. <body>
    46. <div class="container">
    47. <div class="item">
    48. <img src="https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF" alt="">
    49. div>
    50. <div class="item">
    51. <img src="https://t7.baidu.com/it/u=949373678,2089110629&fm=193&f=GIF" alt="">
    52. div>
    53. <div class="item">
    54. <img src="https://t7.baidu.com/it/u=2196842896,2809445370&fm=193&f=GIF" alt="">
    55. div>
    56. <div class="item">
    57. <img src="https://t7.baidu.com/it/u=3779521506,3594871140&fm=193&f=GIF" alt="">
    58. div>
    59. <div class="item">
    60. <img src="https://t7.baidu.com/it/u=3360446468,3126444958&fm=193&f=GIF" alt="">
    61. div>
    62. <div class="item">
    63. <img src="https://t7.baidu.com/it/u=2749005241,3756993511&fm=193&f=GIF" alt="">
    64. div>
    65. <div class="item">
    66. <img src="https://t7.baidu.com/it/u=2928560209,826823219&fm=193&f=GIF" alt="">
    67. div>
    68. <div class="item">
    69. <img src="https://t7.baidu.com/it/u=3780014697,4013718301&fm=193&f=GIF" alt="">
    70. div>
    71. <div class="item">
    72. <img src="https://t7.baidu.com/it/u=832449998,3859178369&fm=193&f=GIF" alt="">
    73. div>
    74. <div class="item">
    75. <img src="https://t7.baidu.com/it/u=1710836566,438775692&fm=193&f=GIF" alt="">
    76. div>
    77. div>
    78. body>
    79. html>

  • 相关阅读:
    MySQL---权限控制和用户、角色管理详解
    快速入门ES6语法(ECMAScript 6)
    我们被一个 kong 的性能 bug 折腾了一个通宵
    高频面试题 | RabbitMQ如何防止重复消费?
    高层次人才申报
    Python 编程基础 | 第五章-类与对象 | 5.4、访问控制
    dht11温湿度传感器工作原理引脚功能电路接线图
    数电课程设计——课设二:交通信号灯
    【21天学习挑战赛—经典算法】LeetCode 26. 删除有序数组中的重复项
    MySQL时间差函数 TimeStampDiff 怎么用
  • 原文地址:https://blog.csdn.net/qq_35350009/article/details/133694693
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号