0

I tried searching the web for various answers and tried everything that solved other people problem, but my CSS just doesn't want to cooperate.

Here you can find a JSFiddle where I recreated the issue: I would like the side navigation to be visible on the black sections too.

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;
}
TheRedMan
  • 7
  • 4

1 Answers1

0

did you want something like this?

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>

you need it add mix-blend-mode to parent element like sidenav, than change backround, color and border-color in a

sueno
  • 163
  • 7
  • Great, thank you very much! I get the problem regarding the colors (black - black = black), but can you please explain why the mix-blend-mode doesn't work if it's in the children? – TheRedMan Mar 07 '21 at 10:01
  • I think it's because mix-blend-mode defines how specific element blend with the background of this element - so if you add it to h1 which is inside sidenav tag, it will treat sidebar as background - it will blend with sidenav not with section. check this article https://css-tricks.com/almanac/properties/m/mix-blend-mode/ – sueno Mar 07 '21 at 20:29