I found this code on the web. Essentially you start with black and white. Your background can be any pattern of black and white, then your foreground (text) is styled with color: white; mix-blend-mode: difference
. Then over both entire thing you position an overlay with a background color of your choice, styled with mix-blend-mode: screen
.
div {
position:absolute;
height:200px
}
#whitebg {
background: white;
width:400px;
z-index:1;
}
#blackbg {
background: black;
width:100px;
z-index:2;
}
span {
position:absolute;
font-family: Arial, Helvetica;
font-size: 100px;
mix-blend-mode: difference;
color: white;
z-index: 3;
}
#makered {
background-color: red;
mix-blend-mode: screen;
width:400px;
z-index:4;
}
<div id="whitebg"></div>
<div id="blackbg"></div>
<div id="makered"></div>
<span>test</span>
You could apply it to your design as per the snippet below. But the overlay technique will mean you can only really use it in areas where you just want white plus a single color of your choice.
body {
margin: 1em;
}
.wrapper {
position: relative;
}
.section-1,.section-2 {
height: 30vh;
background: white;
}
.section-2 {
background: black;
}
.menu {
color: white;
position: fixed;
mix-blend-mode: difference;
font-size: 2em;
}
.wrapper::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #f95b03;
mix-blend-mode: screen;
}
<div class="wrapper">
<div class="menu">MENU</div>
<div class="section-1"></div>
<div class="section-2"></div>
<div class="section-1"></div>
<div class="section-2"></div>
<div class="section-1"></div>
<div class="section-2"></div>
<div class="section-1"></div>
<div class="section-2"></div>
</div>