繁体   English   中英

如何淡化我的背景而不是文字?

[英]how to fade my background but not the text?

我想开始我的博客,但我也想建立自己的网站。 我刚刚学习了如何使用Codecademy做到这一点。 我的问题是如何淡化背景,而不淡化文本? 我找到了很多解决方案,但没有一个对我有用。 我的网站: http : //beingatechnocrat.me/ HTML代码:

<article>
  <div class="post" style="background-image: url(http://www.planwallpaper.com/static/images/HD-Wallpapers1_FOSmVKg.jpeg)">
    <div class="product">
      <h3>The Monarch</h3>
      <p>The Monarch Bike is our original beach cruiser. It's perfect for strolling bike rides down beach promenades and small enough to stash just anywhere.</p>
      <a href="#" class="btn">Read More</a>
    </div>
  </div>
</article>

CSS代码:

.post {
  background-size: cover;
  background-attachment: fixed;
  height: 100%;
  position: relative;
  width: 100%;
  z-index: 1;
  background-position: center;
  opacity: 0.3;
}

您可以改为将背景应用于伪元素,并在伪元素上使用opacity

 .post { height: 100%; width: 100%; z-index: 1; } .background { position: relative; } .background:after { position: absolute; top: 0; left: 0; right: 0; bottom: 0; content: ''; background-image: url(http://www.planwallpaper.com/static/images/HD-Wallpapers1_FOSmVKg.jpeg); background-size: cover; background-attachment: fixed; background-position: center; opacity: 0.3; z-index: -1; } 
 <div class="post background"> <div class="product"> <h3>The Monarch</h3> <p>The Monarch Bike is our original beach cruiser. It's perfect for strolling bike rides down beach promenades and small enough to stash just anywhere.</p> <a href="#" class="btn">Read More</a> </div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM