CSS将图像与混合混合模式差异隔离

时间:2019-10-01 09:22:53

标签: html css image overlay mix-blend-mode

我正在使用mix-blend-mode:差异在HTML上应用深色模式效果。一切正常,除了图像,图像也受覆盖影响。我尝试使用以下方法隔离元素:

img {
    isolation: isolate;
}

或在容器内

.img-wrap {
    width: 45%;
    padding: 1%;
    position: relative;
    isolation: isolate;
    margin: 0 auto;
}

我想要原始图像。这样看起来: enter image description here

这是完整的HTML

#blender {
    width: 100vw;
    height: 100vh;
    left: 0pt;
    top: 0pt;
    position: fixed;
    background: white;
    transition: all 1s ease;
    mix-blend-mode: difference;
    pointer-events: none;
}

.img-wrap {
    width: 45%;
    padding: 1%;
    position: relative;
    isolation: isolate;
    margin: 0 auto;
}

img {
    isolation: isolate;
}

.darkmode-background {
    position: fixed;
    background: white;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
}
<div>
    <div style="font-size: 16pt; font-weight: bold"><font face="Comic Sans MS">1. Words marathon</font>
        <div></div>
    </div>
</div>
<div>
    <div class="img-wrap"><img src="https://cdn.pixabay.com/photo/2012/04/13/13/19/clock-32380_960_720.png"></div>
    <br>
    <div><font face="Comic Sans MS">Ask students to make 5 cards each with any word in English. As a rule, it cannot be a name. If you are revising a certain chapter, the words can be from a category previously stated. Then put all the cards together and devide the students in 2 or 3 teams. One student from the first team comes to the front and picks a card and he/she has to describe it to his team. He/she has to describe as many words/cards as possible in 1 minute. The students from the other teams have to watch the time.&nbsp;</font></div>
    <div><font face="Comic Sans MS"><br></font></div>
    <div style="font-size: 16pt; font-weight: bold">
        <div><font face="Comic Sans MS">2. Bingo</font></div>
        <div><font face="Comic Sans MS"><br></font></div>
        <div></div>
    </div>
    <div><font face="Comic Sans MS"><img src="https://image.shutterstock.com/image-photo/bingo-filled-red-pencil-600w-773393032.jpg" alt="Bingo lot is filled in with red pencil"></font></div>
    <div><font face="Comic Sans MS">This is just like the traditional game of bingo, but instead of numbers, you have words. Students draw a table on their notebook and the teacher sets the topic. Then students write a word in each box. Teacher starts the game by saying words and students cross them out on their notebook. The student who has all the boxes crossed, shouts BINGO and is the winner. The game continues until all students get to Bingo.&nbsp;</font></div>
    <div><font face="Comic Sans MS"><br></font></div>
</div>
<div id="darkmode-container">
    <div class="darkmode-background"></div>
    <div id="blender"></div>
</div>

如果可能的话,可以分离出图像的片段将是很棒的。

1 个答案:

答案 0 :(得分:1)

孤立不会与您一起使用。只需增加图像的z-index即可使其位于图层上方

#blender {
  width: 100vw;
  height: 100vh;
  left: 0pt;
  top: 0pt;
  position: fixed;
  background: white;
  transition: all 1s ease;
  mix-blend-mode: difference;
  pointer-events: none;
}

.img-wrap {
  width: 45%;
  padding: 1%;
  position: relative;
  margin: 0 auto;
  z-index: 2;
}

img {
  position: relative;
  z-index: 2;
}

.darkmode-background {
  position: fixed;
  background: white;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
}
<div>
  <div style="font-size: 16pt; font-weight: bold">
    <font face="Comic Sans MS">1. Words marathon</font>
    <div></div>
  </div>
</div>
<div>
  <div class="img-wrap"><img src="https://cdn.pixabay.com/photo/2012/04/13/13/19/clock-32380_960_720.png"></div>
  <br>
  <div>
    <font face="Comic Sans MS">Ask students to make 5 cards each with any word in English. As a rule, it cannot be a name. If you are revising a certain chapter, the words can be from a category previously stated. Then put all the cards together and devide the students in 2 or
      3 teams. One student from the first team comes to the front and picks a card and he/she has to describe it to his team. He/she has to describe as many words/cards as possible in 1 minute. The students from the other teams have to watch the time.&nbsp;</font>
  </div>
  <div>
    <font face="Comic Sans MS"><br></font>
  </div>
  <div style="font-size: 16pt; font-weight: bold">
    <div>
      <font face="Comic Sans MS">2. Bingo</font>
    </div>
    <div>
      <font face="Comic Sans MS"><br></font>
    </div>
    <div></div>
  </div>
  <div>
    <font face="Comic Sans MS"><img src="https://image.shutterstock.com/image-photo/bingo-filled-red-pencil-600w-773393032.jpg" alt="Bingo lot is filled in with red pencil"></font>
  </div>
  <div>
    <font face="Comic Sans MS">This is just like the traditional game of bingo, but instead of numbers, you have words. Students draw a table on their notebook and the teacher sets the topic. Then students write a word in each box. Teacher starts the game by saying words and students
      cross them out on their notebook. The student who has all the boxes crossed, shouts BINGO and is the winner. The game continues until all students get to Bingo.&nbsp;</font>
  </div>
  <div>
    <font face="Comic Sans MS"><br></font>
  </div>
</div>
<div id="darkmode-container">
  <div class="darkmode-background"></div>
  <div id="blender"></div>
</div>

有关isolation的工作方式的更多详细信息,请参见:How to use CSS combination of mix-blend-mode and isolation?