I was wondering if there is a way to place a background-image behind the background-color.
I have this color picker with sliders and when I iterate on the alpha channel I want the checkered image to display under the color
I guess I could add the image in html and then position it under the div but isn't there a "cleaner" solution without having to add position: absolute;
? I really want to avoid that if possible
I tried using ::before
and ::after
but so far to no success, the image won't display. I tried with content: url("")
but it always stays on top and can't seem to bring it below with z-index
let red = document.querySelector("#red");
let green = document.querySelector("#green");
let blue = document.querySelector("#blue");
let alpha = document.querySelector("#alpha");
let paletteColor = document.querySelector(".paletteColor")
paletteColor.style.backgroundColor = `rgba(${red.value}, ${green.value}, ${blue.value}, ${alpha.value/100})`
red.addEventListener("input", rgbaValue);
green.addEventListener("input", rgbaValue);
blue.addEventListener("input", rgbaValue);
alpha.addEventListener("input", rgbaValue);
function rgbaValue() {
let rgba = `rgba(${red.value}, ${green.value}, ${blue.value}, ${alpha.value/100})`
paletteColor.style.backgroundColor = rgba
}
.palette {
border: 3px solid black;
}
.sliders {
list-style: none;
left: 80px;
display: inline-block;
}
.paletteColor {
height: 100px;
width: 100px;
display: inline-block;
}
.paletteColor::after {
height: 100px;
width: 100px;
display: inline-block;
background-color: black;
}
.paletteColor::before {
height: 100px;
width: 100px;
display: inline-block;
background-image: url("./checkered.jpg");
}
<div class="palette">
<div class="paletteColor"></div>
<ul class="sliders">
<li><input id="red" type="range" min="0" max="255" value="150"></li>
<li><input id="green" type="range" min="0" max="255" value="222"></li>
<li><input id="blue" type="range" min="0" max="255" value="22"></li>
<li><input id="alpha" type="range" min="0" max="100" value="100"></li>
</ul>
<div>