javascript - 如何淡化我的背景而不是文本?

标签 javascript jquery html css

我想开始我的博客,但我也想建立自己的网站。我刚刚学会了如何使用 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>

关于javascript - 如何淡化我的背景而不是文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44166187/

相关文章:

javascript - 为 Google Adsense 找到预加载链接,但浏览器未使用

javascript - 删除和添加 css 类 onclick

c# - 使用 jQuery 选项卡时无效的 ViewState

jquery - .attr方法如何工作(我不明白API)

javascript - 如何通过它的类使用 jQuery 实现悬停的 div 效果?

javascript - React Modal - 在单击时使用参数调用函数,而不是在渲染时调用函数

javascript - 使用 Google Analytics,是否可以使用 API 创建自定义维度(以编程方式)

javascript - 如何动态设置一个JS对象的属性名

jquery - curvetext.js 不适用于任何文本动画

html - 如何避免默认的 -webkit 属性