<div class="container">
<div class="box">font-size: 100%(16px)</div>
<h1>font-size: <span id="val">100</span>% (<strong>16px</strong>) <i id="line-height">line-height: 120% (19.2px)</i></h1>
</div>
<div class="actions">
<label for="percentage">font-size:</label>
<input type="range" id="percentage" name="percentage" min="10" max="300" value="100" step="5">
<span>%</span>
</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%;
line-height: 150%;
letter-spacing: 0.1rem;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-blend-mode: hue;
}
body::before {
content: "<body> ❯ line-height: 150% x 16px = 24px";
}
.container {
min-height: 0;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
margin-top: auto;
}
.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;
}
:root {
--font-size: 100%;
}
h1 {
display: inline-flex;
font-size: var(--font-size);
background: linear-gradient(to right, #44ea76 0%, #39fad7 80%, #39fad7 100%)
no-repeat,
url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/slider-2.jpg")
no-repeat fixed;
background-size: cover;
background-clip: text;
-webkit-text-fill-color: transparent;
}
.container {
width: 50vmax;
height: 50vmin;
border: 1px dashed #f36;
position: relative;
font-size: var(--font-size);
}
.box {
background-color: #f36;
position: absolute;
right: 0;
bottom: 100%;
padding: 4px 6px;
font-size: 16px;
border-radius: 4px 4px 0 0;
font-size: 16px;
}
.container::before {
content: '<div class="container"></div> | 基本字号: 16px';
position: absolute;
left: 0;
bottom: 100%;
font-size: 16px;
}
h1 {
border: 1px dotted #0ff;
padding: 20px 50px;
border-radius: 5px;
position: relative;
line-height: 120%;
}
h1::before {
content: "<h1>";
position: absolute;
left: 0;
bottom: 100%;
color: #fff;
-webkit-text-fill-color: #fff;
z-index: 2;
font-size: 16px;
line-height: 1.15;
}
h1 i {
position: absolute;
left: 50%;
top: 100%;
transform: translate(-50%, 0);
-webkit-text-fill-color: #fff;
white-space: nowrap;
}
const rangeElement = document.getElementById("percentage");
const spanElement = document.getElementById("val");
const boxElement = document.querySelector(".box");
const strongElement = document.querySelector("strong");
const iElement = document.getElementById("line-height");
rangeElement.addEventListener("change", (etv) => {
document.documentElement.style.setProperty(
"--font-size",
`${etv.target.value}%`
);
val.textContent = etv.target.value;
const containerComputedVal = (etv.target.value * 16) / 100;
boxElement.textContent = `font-size:${etv.target.value}% (${containerComputedVal}px) || line-height: 24px`;
const strontComputedVal =
(((etv.target.value * 16) / 100) * etv.target.value) / 100;
strongElement.textContent = `${strontComputedVal}px`;
const lineHeightValue =
(((((etv.target.value * 16) / 100) * etv.target.value) / 100) * 120) / 100;
iElement.textContent = `line-height: 120% (${lineHeightValue}px)`;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.