背景模糊的 div 没有覆盖整个屏幕。

huangapple go评论161阅读模式
英文:

Backdrop blurred div is not covering entire screen

问题

我有一个叫做overlay的div,然后有一个叫做signupContainer的容器。我想让overlay div覆盖整个屏幕,但在背景中进行模糊处理。这是我的代码:

  1. <!-- begin snippet: js hide: false console: true babel: false -->
  2. <!-- language: lang-css -->
  3. html, body {
  4. background-image: url('https://host.stcollier.repl.co/img.png');
  5. background-position: center;
  6. background-attachment: fixed;
  7. background-repeat: no-repeat;
  8. background-size: 1000px;
  9. background-color: rgba(255, 255, 255, 0.5);
  10. }
  11. .blur {
  12. width: 100%;
  13. height: 100%;
  14. padding: 0;
  15. margin: 0;
  16. z-index: -99;
  17. backdrop-filter: blur(10px);
  18. position: fixed;
  19. top: 0;
  20. left: 0;
  21. }
  22. .signupContainer {
  23. padding-top: 75px;
  24. display: flex;
  25. flex-direction: column;
  26. justify-content: center;
  27. align-items: center;
  28. width: 100%;
  29. z-index: 99;
  30. color: white;
  31. }
  32. <!-- language: lang-html -->
  33. <div class="blur"></div>
  34. <div class="signupContainer">
  35. <h1>Sign Up</h1>
  36. </div>
  37. <!-- end snippet -->

这是它的外观:
背景模糊的 div 没有覆盖整个屏幕。

请注意,背景滤镜模糊效果未覆盖整个屏幕,而只到其他元素的位置。这是为什么,如何修复这个问题?

英文:

I have a div called overlay and then a container called signupContainer. I want the overlay div to cover the entire screen but be blurred in the background. This is my code:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

  1. html, body {
  2. background-image: url(&#39;https://host.stcollier.repl.co/img.png&#39;);
  3. background-position: center;
  4. background-attachment: fixed;
  5. background-repeat: no-repeat;
  6. background-size: 1000px;
  7. background-color: rgba(255, 255, 255 0.5);
  8. }
  9. .blur {
  10. width: 100%;
  11. height: 100%;
  12. padding: 0;
  13. margin: 0;
  14. z-index: -99;
  15. backdrop-filter: blur(10px);
  16. position: fixed;
  17. top: 0;
  18. left: 0;
  19. }
  20. .signupContainer {
  21. padding-top: 75px;
  22. display: flex;
  23. flex-direction: column;
  24. justify-content: center;
  25. align-items: center;
  26. width: 100%;
  27. z-index: 99;
  28. color: white;
  29. }

<!-- language: lang-html -->

  1. &lt;div class=&quot;blur&quot;&gt;&lt;/div&gt;
  2. &lt;div class=&quot;signupContainer&quot;&gt;
  3. &lt;h1&gt;Sign Up&lt;/h1&gt;
  4. &lt;/div&gt;

<!-- end snippet -->
Here's how that looks:
背景模糊的 div 没有覆盖整个屏幕。
Notice how the backdrop filter blur is not covering the entire screen, but only the point to where other element is. Why is this and how can I fix this?

答案1

得分: 2

只需从第一个规则中删除HTML选择器,然后它就会起作用。您不必要地应用了两个背景图像,似乎这导致了错误的渲染。

  1. body {
  2. background-image: url('https://host.stcollier.repl.co/img.png');
  3. background-position: center;
  4. background-attachment: fixed;
  5. background-repeat: no-repeat;
  6. background-size: 1000px;
  7. background-color: rgba(255, 255, 255, 0.5);
  8. }
英文:

Just remove the html selector from the first rule, and then it will work. You're applying two background images unnecessarily and it seems that this is causing a wrong rendering.

  1. body {
  2. background-image: url(&#39;https://host.stcollier.repl.co/img.png&#39;);
  3. background-position: center;
  4. background-attachment: fixed;
  5. background-repeat: no-repeat;
  6. background-size: 1000px;
  7. background-color: rgba(255, 255, 255 0.5);
  8. }

答案2

得分: 1

因为背景位置是相对的,所以它没有覆盖整个页面。

你可以使用这个代码:

  1. .blur {
  2. position: absolute;
  3. width: 100vw;
  4. height: 100vh;
  5. padding: 0;
  6. margin: 0;
  7. z-index: -99;
  8. backdrop-filter: blur(10px);
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. }
英文:

It's because the backdrop position is relative so it's not covering the entire page.

you could use this:

  1. .blur {
  2. position: absolute;
  3. width: 100vw;
  4. height: 100vh;
  5. padding: 0;
  6. margin: 0;
  7. z-index: -99;
  8. backdrop-filter: blur(10px);
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. }

huangapple
  • 本文由 发表于 2023年3月7日 02:59:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654787.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定