<div class="box"></div>
<div class="form">
<label for="background-position">background-position:</label>
<select name="background-position" id="background-position">
<optgroup label="Keyword values">
<option value="left top">left top</option>
<option value="top left">top left</option>
<option value="left bottom">left bottom</option>
<option value="bottom left">bottom left</option>
<option value="right top">right top</option>
<option value="top right">top right</option>
<option value="right bottom">right bottom</option>
<option value="bottom right">bottom right</option>
<option value="left center">left center</option>
<option value="center left">center left</option>
<option value="right center">right center</option>
<option value="center right">center right</option>
<option value="top center">top center</option>
<option value="center top">center top</option>
<option value="bottom center">bottom center</option>
<option value="center bottom">center bottom</option>
<option value="center center">center center</option>
</optgroup>
<optgroup label="<length> + keyword values">
<option value="left 0">left 0</option>
<option value="right 50px">right 50px</option>
<option value="5rem top">5rem top</option>
<option value="5vw bottom">5vw bottom</option>
<option value="5em center">5em center</option>
<option value="center 5ch">center 5ch</option>
</optgroup>
<optgroup label="<percentage> + keyword values">
<option value="left 5%">left 5%</option>
<option value="right 50%">right 50%</option>
<option value="35% top">35% top</option>
<option value="15% bottom">15% bottom</option>
<option value="center 75%">center 75%</option>
<option value="3% center">3% center</option>
</optgroup>
<optgroup label="Invalid values">
<option value="left right">left right</option>
<option value="right left">right left</option>
<option value="top bottom">top bottom</option>
<option value="bottom top">bottom top</option>
<option value="50px left">50px left</option>
<option value="30% left">30% left</option>
<option value="10em right">10em right</option>
<option value="10% right">10% right</option>
<option value="top 50rem">top 50rem</option>
<option value="top 10%">bottom 10%</option>
<option value="bottom 10vw">bottom 10vw</option>
<option value="bottom 10%">bottom 10%</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: #557;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
padding: 1rem;
gap: 1rem;
}
.box {
width: min(100%, 600px);
background-color: #fff;
aspect-ratio: 16 / 9;
box-shadow: 0 0 10px 1px rgb(0 0 0 / 25%);
border: 1.625em solid rgb(220 20 20 / 38%);
}
:root {
--position: left top;
}
.box {
background: #fff
url("//www.w3cplus.com/sites/default/files/blogs/2022/2207/avatar.svg") left
top / 100px 100px no-repeat;
background-position: var(--position);
overflow: hidden;
resize: both;
}
.form {
padding: 1rem;
background-color: rgb(0 0 0 / 0.6);
backdrop-filter: blur(20px);
position: fixed;
top: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}
.form select {
padding: 0.25em 0.5em;
font-size: inherit;
}
const rootElement = document.documentElement;
const repeatHander = document.getElementById("background-position");
repeatHander.addEventListener("change", (etv) => {
rootElement.style.setProperty("--position", etv.target.value);
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.