到达顶部标题时淡出的内容淡出
我正在尝试通过-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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mask-image
旨在与同一元素上的背景图像结合使用。我已经在下面的演示中添加了该图像,并清理了mask-image
语法。 (并进行了较小的修改以清理外观。)所有更改均在CSS中使用/*** ***/
进行评论。更新:更改了设置背景图像的方式。
参考:
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 themask-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: