【问题标题】:opacity on parallax images视差图像上的不透明度
【发布时间】:2020-03-24 14:37:23
【问题描述】:

我有一个用于视差图像滚动功能的父 div。我希望视差图像的不透明度在 opactiy: 45% 左右;且其中所有内容不透明:100%; 我一直在寻找,但还没有找到一种方法来做到这一点?他们是直接在背景图像上设置不透明度的一种方式吗?

html

<div class="img1">
        <div class="container img1-container">
            <!-- <div class="card"> -->
            <img id="head-shot" src="./assets/images/john-headshots-5.jpg" alt="head-shot">
            <br><br>
            <h1 class="intro-text web-dev"> Front-End Web Developer</h1>

            <h4 class="intro-text john-sass">John</h4>


            <!-- </div> -->
        </div>
    </div>

css

.img1 {
    background-image: url(/assets/images/skyline-1402050_1920.jpg);
    min-height: 100%;
    min-width: 100%;
    opacity: 45%;
}
/* headshot img */
#head-shot {
    text-align: center;
    border-radius: 100%;
    height: 300px;
    width: 350px;
}

【问题讨论】:

    标签: html css inheritance parallax


    【解决方案1】:

    这是一个建议的解决方案,目前我不知道可以实现的解决方案只有容器不透明度到45%,我通常实现的唯一方法是使用单独的&lt;img /&gt;自己的 CSS 位置设置为absolute 和不透明度45%,如下面的sn-p:

    .img1 {
      min-height: 100%;
      min-width: 100%;
      position: relative;
      overflow: hidden;
    }
    
    .parallex-bg {
      position: absolute;
      left: 0px;
      top: 0px;
      right: 100%;
      bottom: 100%;
      z-index: -1;
      opacity: 45%;
    }
    
    
    /* headshot img */
    
    #head-shot {
      text-align: center;
      border-radius: 100%;
      height: 300px;
      width: 350px;
    }
    <div class="img1">
       <img src="https://www.w3schools.com/css/img_forest.jpg" class="parallex-bg" />
       <div class="container img1-container">
          <!-- <div class="card"> -->
          <img id="head-shot" src="./assets/images/john-headshots-5.jpg" alt="head-shot">
          <br><br>
          <h1 class="intro-text web-dev"> Front-End Web Developer</h1>
          <h4 class="intro-text john-sass">John</h4>
          <!-- </div> -->
       </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 2018-12-07
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      相关资源
      最近更新 更多