<div class="element">
<div class="box primary">Primary Box</div>
<div class="box secondary">Secondary Box</div>
</div>
<div class="form">
<div class="control">
<label for="h">H:</label>
<input type="range" min="0" max="360" name="color" step="1" id="h" value="80" />
</div>
<div class="control">
<label for="s">S:</label>
<input type="range" min="0" max="100" name="color" step="1" id="s" value="20" />
</div>
<div class="control">
<label for="l">L:</label>
<input type="range" min="0" max="100" name="color" step="1" id="l" value="60" />
</div>
</div>
@import url("https://fonts.googleapis.com/css?family=Gochi+Hand");
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: #291642;
font-family: "Gochi Hand", sans-serif;
font-size: 130%;
letter-spacing: 0.1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.element {
padding: 10vmin 20vmin;
display: flex;
justify-content: center;
background-image: radial-gradient(circle at center, hsl(var(--h) calc(var(--s) * 1%) calc(var(--l) * 1%)), #291642),
linear-gradient(to bottom, #291642, #291642);
background-repeat: no-repeat;
background-position: center;
background-clip: padding-box;
border-radius: 8px;
background-blend-mode: multiply, screen;
margin-bottom: 10px;
}
.box {
border-radius: 2vmin;
padding: 5vmin;
margin:0 3vmin;
white-space: nowrap;
font-size: 2rem;
}
.form {
display: flex;
align-items: center;
color: #fff;
}
.control {
margin: 4vmin;
display: flex;
align-items: center;
font-size: 3rem;
}
:root {
--h: 80;
--s: 20;
--l: 60;
--threshold: 65;
--border-threshold: 80;
}
.box {
--hue: var(--h);
--switch: calc((var(--l) - var(--threshold)) * -100%);
--border-light: calc(var(--l) * 0.7%);
--border-alpha:calc((var(--l) - var(--border-threshold)) * 10);
background: hsl(var(--hue), calc(var(--s) * 1%), calc(var(--l) * 1%));
color: hsl(0, 0%, var(--switch));
border:.2em solid hsla(var(--hue), calc(var(--s) * 1%), var(--border-light), var(--border-alpha));
}
.secondary {
--hue: calc(var(--h) + 60);
}
View Compiled
const inputs = document.querySelectorAll("input");
const color = [...inputs].map((input, index) => {
input.addEventListener("change", function (e) {
handleUpdate(e, index);
});
return input.value;
});
function handleUpdate(e, index) {
color[index] = e.target.value;
document.documentElement.style.setProperty(
`--${e.target.id}`,
`${e.target.value}`
);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.