CSS背景模糊+去白边效果

更新于 2023-11-03 21:10 59
专栏: 前端文章 标签: css

正在做一个导航页,想要背景图模糊处理,找了很多教程,总结的

基础代码

html代码

  1. <div class="sun-main">
  2. <!-- 背景图片以及模糊层 -->
  3. <div class="cover" />
  4. <div class="content">
  5. <!-- 其他代码 -->
  6. </div>
  7. </div>
  8. <!-- 固定的style -->
  9. <style>
  10. .content{
  11. position:absolute;
  12. height:100%;
  13. width:100%;
  14. }
  15. .sun-main{
  16. height:100%;
  17. width:100%;
  18. }
  19. body,html{
  20. overflow: hidden;
  21. }
  22. </style>

实现效果

其他css代码

方式1:

  1. .cover{
  2. width:100%;
  3. height:100%;
  4. position:absolute;
  5. overflow: hidden;
  6. }
  7. .cover::before{
  8. content:'';
  9. position:absolute;
  10. width:100%;
  11. height:100%;
  12. background: url(@/assets/start_sky.jpg) no-repeat;
  13. background-size:cover;
  14. background-attachment:fixed;
  15. background-position: center;
  16. filter:blur(5px); // 模糊代码
  17. transform: scale(1.05);// 防止白边
  18. z-index:-1;
  19. }

方式2: 自己尝试总结的有效果

  1. .cover{
  2. content:'';
  3. position:absolute;
  4. width:100%;
  5. height:100%;
  6. overflow: hidden;
  7. background: url(@/assets/start_sky.jpg) no-repeat;
  8. background-size:cover;
  9. background-attachment:fixed;
  10. background-position: center;
  11. filter:blur(1px); // 模糊代码
  12. transform: scale(1.05);// 防止白边
  13. }

BLOG

搜索文章