到达顶部标题时淡出的内容淡出

发布于 2025-02-10 06:42:15 字数 2081 浏览 3 评论 0原文

我正在尝试通过-webkit-gradient创建一个渐变PNG,以使幻想说内容在滚动时逐渐删除,以使内容不在标题后面。

这是我尝试的:

.wrapper {
  background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png");
  background-attachment: fixed;
}
.menu {
  position: fixed;
  width: 100%;
  z-index: 98;
  height: 80px;
}
.gradient-png {
  -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
  height: 80px;
}
.hamburger {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 50px;
}
.site-logo {
  position: absolute;
  right: 30px;
  top: 30px;
  width: 170px;
}
.content {
  padding-top: 100px;
}
      <div class="wrapper">
        <div class="menu gradient-png">
          <img class="hamburger" alt="menu" />
          <div class="site-logo">Logo</div>
        </div>
        <div class="content">
          <p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p>
        </div>
      </div>

不知何故,掩模图像没有生效,我仍然可以看到我的内容在菜单后面。

我正在尝试实现这样的目标,其中以下文本是内容:

I am trying to create a gradient png via -webkit-gradient to make an illusion that the content is being faded out when it reaches the top header on scroll so that the content doesn't go behind the header.

Here is what I attempted:

.wrapper {
  background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png");
  background-attachment: fixed;
}
.menu {
  position: fixed;
  width: 100%;
  z-index: 98;
  height: 80px;
}
.gradient-png {
  -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
  height: 80px;
}
.hamburger {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 50px;
}
.site-logo {
  position: absolute;
  right: 30px;
  top: 30px;
  width: 170px;
}
.content {
  padding-top: 100px;
}
      <div class="wrapper">
        <div class="menu gradient-png">
          <img class="hamburger" alt="menu" />
          <div class="site-logo">Logo</div>
        </div>
        <div class="content">
          <p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p>
        </div>
      </div>

Somehow the mask image is not taking effect, I can still see that my content is behind my menu.

I am trying to achieve something like this, where the text below is the content:
fadeout

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2025-02-17 06:42:15

mask-image旨在与同一元素上的背景图像结合使用。我已经在下面的演示中添加了该图像,并清理了mask-image语法。 (并进行了较小的修改以清理外观。)所有更改均在CSS中使用/*** ***/进行评论。

更新:更改了设置背景图像的方式。

参考:

:root {
  --background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png"); /*** added ***/
}
body {
  margin:0; /*** optional addition ***/
}
.wrapper {
  background-image: var(--background-image); /*** modified ***/
  background-attachment: fixed;
}
.menu {
  position: fixed;
  width: 100%;
  z-index: 98;
  height: 80px;
}
.gradient-png {
  mask-image: linear-gradient(white 75%, transparent); /*** added; non-chrome ***/
  -webkit-mask-image: linear-gradient(white 75%, transparent); /*** corrected; chrome ***/
  background-image: var(--background-image); /*** added ***/
  height: 90px; /*** optional modification ***/
}
.hamburger {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 50px;
}
.site-logo {
  position: absolute;
  right: 30px;
  top: 30px;
  width: 170px;
}
.content {
  padding-top: 100px;
}
<div class="wrapper">
  <div class="menu gradient-png">
    <img class="hamburger" alt="menu" />
    <div class="site-logo">Logo</div>
  </div>
  <div class="content">
    <p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p>
  </div>
</div>

mask-image is meant to work in conjunction with a background image on the same element. I've added that image in the demo below and cleaned up the mask-image syntax. (And made minor modifications to clean up the look.) All changes are commented in the CSS with /*** ***/.

Update: Changed how background images are set.

References:

:root {
  --background-image: url("https://amymhaddad.s3.amazonaws.com/morocco-blue.png"); /*** added ***/
}
body {
  margin:0; /*** optional addition ***/
}
.wrapper {
  background-image: var(--background-image); /*** modified ***/
  background-attachment: fixed;
}
.menu {
  position: fixed;
  width: 100%;
  z-index: 98;
  height: 80px;
}
.gradient-png {
  mask-image: linear-gradient(white 75%, transparent); /*** added; non-chrome ***/
  -webkit-mask-image: linear-gradient(white 75%, transparent); /*** corrected; chrome ***/
  background-image: var(--background-image); /*** added ***/
  height: 90px; /*** optional modification ***/
}
.hamburger {
  position: absolute;
  left: 30px;
  top: 30px;
  width: 50px;
}
.site-logo {
  position: absolute;
  right: 30px;
  top: 30px;
  width: 170px;
}
.content {
  padding-top: 100px;
}
<div class="wrapper">
  <div class="menu gradient-png">
    <img class="hamburger" alt="menu" />
    <div class="site-logo">Logo</div>
  </div>
  <div class="content">
    <p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p><p>Example content</p>
  </div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文