<div class="control">
<label for="angle">Angle:</label>
<input type="range" id="angle" name="angle" value="0" min="0" max="360" step="1" />
<output id="output">0deg</output>
</div>
<div class="control">
<label for="position">position:</label>
<select name="position" id="position">
<optgroup label="bg-position">
<option value="top">top</option>
<option value="right">right</option>
<option value="bottom">bottom</option>
<option value="left">left</option>
<option value="center" selected>center</option>
<option value="top left">top left</option>
<option value="top center">top center</option>
<option value="top right">top right</option>
<option value="center center">center center</option>
<option value="center right">center right</option>
<option value="left center">let center</option>
<option value="bottom left">bottom left</option>
<option value="bottom center">bottom center</option>
<option value="bottom right">bottom right</option>
</optgroup>
<optgroup label="length-percentage">
<option value="10px 50px">10px 50px</option>
<option value="10em 50em">10em 50em</option>
<option value="10rem 50rem">10rem 50rem</option>
<option value="10vw 50vw">10vw 50vw</option>
<option value="10vh 50vh">10vh 50vh</option>
<option value="10% 50%">10% 50%</option>
<option value="10%">10%</option>
<option value="10px 50%">10px 50%</option>
<option value="10% 50px">10% 50px</option>
</optgroup>
</select>
</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: #222;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
}
:root {
--angle: 0deg;
--position: center;
}
body {
background-image: conic-gradient(
from var(--angle) at var(--position),
#09f,
#f36
);
}
.control {
margin: 0 5px;
}
const rootElement = document.documentElement;
const angleInput = document.getElementById("angle");
const angleOutput = document.getElementById("output");
const position = document.getElementById("position");
angleInput.addEventListener("input", (etv) => {
rootElement.style.setProperty("--angle", `${etv.target.value}deg`);
angleOutput.innerText = `${etv.target.value}deg`;
});
position.addEventListener("change", (etv) => {
rootElement.style.setProperty("--position", etv.target.value);
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.