One way to do this is to make everything in the container except the h1 text into an image which can then be used to mask the cloned text (which we make the required color rather than transparent).
As the requirement was to have any sort of content beneath the text, html2canvas is used to make a canvas and then convert it to an image. This is then used to mask the cloned text.
There are questions around whether it is required that opacity be carried over to the intersection color. I assumed not because it looked rather washed out, but it can be kept if required. Also, html2canvas may not cope with absolutely all the formatting in any underlying HTML - whether this matters depends on the use-case.
Here is the code. Note that element shape can contain HTML. Remember to replace the copy of the html2canvas library with a copy of your own. Downloadable to your machine from github for example.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ahweb.org.uk/html2canvas.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
text-transform: uppercase;
overflow: hidden;
}
#container {
font-family: sans-serif;
font-size: 6vw;
display: flex;
height: 100vh; /* 100vh doesn't work on Safari IOS because of its definition of vh (not same as innerHeight). See hack in the JS code. */
justify-content: center;
align-items: center;
}
#con {
position: relative;
overflow: hidden;
}
#con h1 {
top: 0;
left: 0;
}
#text {
position: relative;
color: blue;
}
#cloned {
position: absolute;
color: lime; /* THE COLOR YOU WANT THE OVERLAPPING BIT OF TEXT TO BE */
}
#shape {
display: inline-block;
height: 18.7vw;
width: 18.7vw;
border-radius: 50%;
position: absolute;
top: 5%;
right: 10%;
background-color: red;
opacity: 0.5;
}
</style>
</head>
<body>
<div id="container">
<div id="con">
<h1 id="text">this is<br>awesome</h1>
<div id="shape"></div>
<h1 id="cloned">this is<br>awesome</h1>
</div>
</div>
<script>
const container = document.getElementById('container');
const con = document.getElementById('con');
function resize() {
container.style.height = window.innerHeight + 'px';
let w = con.offsetWidth;
let h = con.offsetHeight;
const textel = document.querySelector('#text');
const cloned = document.querySelector('#cloned');
const shape = document.querySelector('#shape');
//get an image of everything except the masking text so we can use it to mask the cloned
textel.style.opacity = 0;
cloned.style.opacity = 0;
shape.style.opacity = 1;
html2canvas(document.querySelector("#con"), {backgroundColor: null, scale: 1, width: w, height: h, allowTaint: true, useCORS: true}).then(canvas => {
// now we set the cloned to be masked by all the shape
cloned.style.opacity = 1;
shape.style.opacity = 0;
cloned.style.maskImage = 'url(' + canvas.toDataURL() + ')';
cloned.style.WebkitMaskImage = 'url(' + canvas.toDataURL() + ')';
textel.style.opacity = 1;
shape.style.opacity = '';
});
}
resize();
window.addEventListener('resize', resize);
</script>
</body>
</html>