I'm trying to highlight some words inside a h1
header.
And I'm using a CSS pseudo-element to achieve that.
But how do I make the CSS pseudo element appear behind the word "Piece of Cake" and nothing else?
At the moment it stretches across the entire heading, which I do not want.
.yellow-highlight {
white-space: nowrap;
}
.yellow-highlight:before {
content: " ";
position: absolute;
width: 100%;
height: 1em;
left: -0.25em;
top: 0.1em;
padding: 0 0.25em;
background-color: #FEFDBD;
transform: rotate(-2deg);
z-index: -1;
}
<h1>Blah Blah Blah Blah Blah Blah Blah <span class="yellow-highlight">Piece of Cake</span></h1>