0

我正在使用 mix-blend-mode: 差异对 HTML 应用暗模式效果。一切都很好,除了图像,它们也受叠加层的影响。我尝试使用以下方法隔离元素:

img {
    isolation: isolate;
}

或在容器内

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

我要原图。这是它的外观: 在此处输入图像描述

这是完整的 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>

如果可能的话,隔离图像的工作片段会很棒。

4

1 回答 1

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工作的更多详细信息:如何使用混合混合模式和隔离的 CSS 组合?

于 2019-10-01T09:33:57.657 回答