【问题标题】:Mix-blend-mode not affecting any component混合混合模式不影响任何组件
【发布时间】:2021-06-05 05:54:31
【问题描述】:

我尝试在网上搜索各种答案并尝试了所有解决其他人问题的方法,但我的 CSS 就是不想合作。

Here 你可以找到一个 JSFiddle,我在其中重新创建了问题:我希望侧面导航也能在黑色部分可见。

HTML
<div class="sidenav">
  <a href="#" class="selected">Section 1</a>
  <a href="#">Section 2</a>
  <a href="#">Section 3</a>
</div>

<div class="content">
  <div>
    <p>Some text<p>
  </div>
  <div class="blk">
    <p>Some text<p>
  </div>
  <div>
    <p>Some text<p>
  </div>
</div>


CSS
.sidenav {
  width: auto;
  position: fixed;
  z-index: 1;
  top: 150px;
  padding: 8px 0;
}

.sidenav a {
  clear: both;
  float: left;
  position: relative;
  left: -20%;
  padding: 10px;
  margin-bottom: 15px;
  transition: 0.3s;

  text-decoration: none;
  text-align: right;
  font-size: 24px;

  border-style: solid;
  border-width: 2px;
  border-color: #0D0D0D;
  border-radius: 0 5px 5px 0;

  color: #0D0D0D;
  mix-blend-mode: difference;
}

.blk {
  background-color: #0d0d0d;
  color: #ffffff;
}

【问题讨论】:

    标签: css menu mix-blend-mode


    【解决方案1】:

    你想要这样的东西吗?

    html {
      scroll-behavior: smooth;
      background: #fff;
    }
    
    body {
      margin: 0;
      padding: 0;
      width: 100%;
      max-width: 100%;
    
      background-color: #ffffff;
      color: #0d0d0d;
    }
    
    /**********************************************/
    
    .section {
      width: 100vw;
      max-width: 100%;
      background-color: #ffffff;
      text-align: center;
    
      margin: 0;
      padding: 15vh 0;
      position: relative;
    }
    
    .blk {
      background-color: #0d0d0d;
      color: #ffffff;
    }
    
    /**********************************************/
    
    .sidenav {
      width: auto;
      position: fixed;
      z-index: 1;
      top: 150px;
      padding: 8px 0;
      mix-blend-mode: difference;
    }
    
    .sidenav a {
      clear: both;
      float: left;
      position: relative;
      left: -20%;
      padding: 10px;
      margin-bottom: 15px;
      transition: 0.3s;
    
      text-decoration: none;
      text-align: right;
      font-size: 24px;
    
      border-style: solid;
      border-width: 2px;
      border-color: #fff;
      border-radius: 0 5px 5px 0;
    
      color: #fff;
      background-color: #000;
    
    }
    
    .sidenav a:hover {
      left: -2px;
    }
    
    .sidenav a.selected {
      left: -2px;
      color: #000;
      background-color: #fff;
      cursor: default;
    }
    <!doctype html>
    <html>
    <head></head>
    
      <body>
    
        <div class="sidenav">
          <a href="#" class="selected">&emsp;&emsp;Section 1</a>
          <a href="#">&emsp;&emsp;Another Section</a>
          <a href="#">&emsp;&emsp;Last One</a>
        </div>
    
        <div class="content" onclick="closeMenu()">
          <div class="section" id="works">
            <p>Some text<p>
          </div>
          <div class="section blk" id="works">
            <p>Some text<p>
          </div>
          <div class="section" id="works">
            <p>Some text<p>
          </div>
          <div class="section blk" id="works">
            <p>Some text<p>
          </div>
          <div class="section" id="works">
            <p>Some text<p>
          </div>
        </div>
      </body>
    </html>

    您需要将mix-blend-mode 添加到sidenav 等父元素,而不是更改a 中的背景、颜色和边框颜色

    【讨论】:

    • 太好了,非常感谢!我遇到了关于颜色的问题(黑色 - 黑色 = 黑色),但您能否解释一下为什么混合模式在儿童中不起作用?
    • 我认为这是因为 mix-blend-mode 定义了特定元素如何与该元素的背景混合 - 所以如果你将它添加到 sidenav 标签内的 h1 中,它会将侧边栏视为背景 - 它将与 sidenav 融合而不是与部分融合。查看这篇文章css-tricks.com/almanac/properties/m/mix-blend-mode
    猜你喜欢
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多