<div class="container">
<div class="element"></div>
<div class="control control__top">
<label for="margin__top">margin-top:</label>
<input type="range" id="margin__top" name="margin" min="-100" max="100" value="0" step="5">
<span id="margin__top--per">0%</span>
(<strong id="margin__top--pix">0px</strong>)
</div>
<div class="control control__right">
<label for="margin__right">margin-right:</label>
<input type="range" id="margin__right" name="margin" min="-100" max="100" value="0" step="5">
<span id="margin__right--per">0%</span>
(<strong id="margin__right--pix">0</strong>)
</div>
<div class="control control__bottom">
<label for="margin__bottom">margin-bottom:</label>
<input type="range" id="margin__bottom" name="margin" min="-100" max="100" value="0" step="5">
<span id="margin__bottom--per">0%</span>
(<strong id="margin__bottom--pix">0px</strong>)
</div>
<div class="control control__left">
<label for="margin__left">margin-left:</label>
<input type="range" id="margin__left" name="margin" min="-100" max="100" value="0" step="5">
<span id="margin__left--per">0%</span>
(<strong id="margin__left--pix">0px</strong>)
</div>
</div>
<div class="actions">
<label for="width">width:</label>
<input type="range" id="width" name="width" min="10" max="100" value="50" step="5">
<span id="width-per">50%</span>
(<strong id="width-pix">250px</strong>)
<label for="height">height:</label>
<input type="range" id="height" name="height" min="10" max="100" value="50" step="5">
<span id="height-per">50%</span>
(<strong id="height-pix">150px</strong>)
</div>
@import url("https://fonts.googleapis.com/css?family=Gochi+Hand");
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
width: 100vw;
min-height: 100vh;
margin: 0;
background-color: #291642;
font-family: "Gochi Hand", sans-serif;
font-size: 100%;
letter-spacing: 0.1rem;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-blend-mode: hue;
}
.container {
width: 500px;
height: 300px;
display: flex;
position: relative;
margin-top: auto;
box-shadow: 0 0 2px 0 #f36;
}
.container::before {
content: "width: 500px";
position: absolute;
bottom: 100%;
right: 0;
}
.container::after {
content: "height: 200px";
position: absolute;
left: 100%;
top: 50%;
white-space: nowrap;
transform: translate(-40%, -50%) rotate(90deg);
}
.actions {
padding: 3vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
font-size: 2rem;
margin-top: auto;
}
label:nth-of-type(2) {
margin-left: 20px;
}
:root {
--width: 50%;
--height: 50%;
}
.element {
width: var(--width);
height: var(--height);
background-color: #09f;
margin: 0;
}
strong {
color: #f89;
}
.control {
position: absolute;
display: flex;
align-items: center;
white-space: nowrap;
}
.control__top {
left: 0;
right: 0;
bottom: calc(100% + 5px);
}
.control__bottom {
left: 0;
right: 0;
top: calc(100% + 5px);
}
.control__right {
top: 0;
bottom: 0;
left: 80%;
transform: rotate(90deg);
}
.control__left {
top: 0;
bottom: 0;
right: 75%;
transform: rotate(-90deg);
}
View Compiled
const rangeWidth = document.getElementById("width");
const rangeHeight = document.getElementById("height");
const rangeMarginTop = document.getElementById("margin__top");
const rangeMarginRight = document.getElementById("margin__right");
const rangeMarginBottom = document.getElementById("margin__bottom");
const rangeMarginLeft = document.getElementById("margin__left");
const widthPerVal = document.getElementById("width-per");
const heightPerVal = document.getElementById("height-per");
const marginTopPerVal = document.getElementById("margin__top--per");
const marginRightPerVal = document.getElementById("margin__right--per");
const marginBottomPerVal = document.getElementById("margin__bottom--per");
const marginLeftPerVal = document.getElementById("margin__left--per");
const widthPixVal = document.getElementById("width-pix");
const heightPixVal = document.getElementById("height-pix");
const marginTopPixVal = document.getElementById("margin__top--pix");
const marginRightPixVal = document.getElementById("margin__right--pix");
const marginBottomPixVal = document.getElementById("margin__bottom--pix");
const marginLeftPixVal = document.getElementById("margin__left--pix");
const containerElement = document.querySelector(".container");
const element = document.querySelector(".element");
rangeHeight.addEventListener("change", (etv) => {
document.documentElement.style.setProperty(
"--height",
`${etv.target.value}%`
);
const heightRangeValue = etv.target.value;
const heightPixValue =
(heightRangeValue * containerElement.getBoundingClientRect().height) / 100;
heightPerVal.textContent = `${heightRangeValue}%`;
heightPixVal.textContent = `${heightPixValue}px`;
});
rangeWidth.addEventListener("change", (etv) => {
document.documentElement.style.setProperty("--width", `${etv.target.value}%`);
const widthRangeValue = etv.target.value;
const widthPixValue =
(widthRangeValue * containerElement.getBoundingClientRect().width) / 100;
widthPerVal.textContent = `${widthRangeValue}%`;
widthPixVal.textContent = `${widthPixValue}px`;
});
rangeMarginTop.addEventListener("change", (etv) => {
element.style.marginTop = `${etv.target.value}%`;
const marginTopRangeValue = etv.target.value;
const marginTopPixValue =
(marginTopRangeValue * containerElement.getBoundingClientRect().width) /
100;
marginTopPerVal.textContent = `${marginTopRangeValue}%`;
marginTopPixVal.textContent = `${marginTopPixValue}px`;
});
rangeMarginRight.addEventListener("change", (etv) => {
element.style.marginRight = `${etv.target.value}%`;
const marginRightRangeValue = etv.target.value;
const marginRightPixValue =
(marginRightRangeValue * containerElement.getBoundingClientRect().width) /
100;
marginRightPerVal.textContent = `${marginRightRangeValue}%`;
marginRightPixVal.textContent = `${marginRightPixValue}px`;
});
rangeMarginBottom.addEventListener("change", (etv) => {
element.style.marginBottom = `${etv.target.value}%`;
const marginBottomRangeValue = etv.target.value;
const marginBottomPixValue =
(marginBottomRangeValue * containerElement.getBoundingClientRect().width) /
100;
marginBottomPerVal.textContent = `${marginBottomRangeValue}%`;
marginBottomPixVal.textContent = `${marginBottomPixValue}px`;
});
rangeMarginLeft.addEventListener("change", (etv) => {
element.style.marginLeft = `${etv.target.value}%`;
const marginLeftRangeValue = etv.target.value;
const marginLeftPixValue =
(marginLeftRangeValue * containerElement.getBoundingClientRect().width) /
100;
marginLeftPerVal.textContent = `${marginLeftRangeValue}%`;
marginLeftPixVal.textContent = `${marginLeftPixValue}px`;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.