<div class="overflow__box" id="box">
<div class="element">
<h2>Should a classic scrollbar’s scrollbar gutter be present?</h2>
<p>What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<p dir="rtl" class="content">الكلمة الافتتاحية للمدير العام لمنظمة الصحة العالمية في جلسة الاستماع العامالمتعلقة بوضع صك دولي جديد بشأن التأهب والاستجابة للجائحة - 12 نيسان/ نيسان/أبريل 2022. ولكن حتى ونحن نعمل على القضاء على هذه الجائحة، فإننا ندين لأولئك الذين لقوا حتفهم بسببها وأولئك الذين تضرروا منها بتعلم الدروس المؤلمة التي تقدمها لنا وإدخال التغييرات التي يجب أن نجريها للتأكد من أن العالم متأهب على نحو أفضل للجائحة التالية.</p>
</div>
</div>
<form>
<div class="control">
<label for="overflow">CSS溢出属性:</label>
<div class="wrapper">
<select name="overflow" id="overflow">
<option value="overflow" selected>overflow</option>
<optgroup label="物理属性">
<option value="overflow-x">overflow-x</option>
<option value="overflow-y">overflow-y</option>
</optgroup>
<optgroup label="逻辑属性">
<option value="overflow-inline">overflow-inline</option>
<option value="overflow-block">overflow-block</option>
</optgroup>
</select>
<span>:</span>
<select name="value" id="value">
<optgroup label="Keyword values">
<option value="visible" selected>visible</option>
<option value="hidden">hidden</option>
<option value="clip">clip</option>
<option value="scroll">scroll</option>
<option value="auto">auto</option>
</optgroup>
<optgroup label="Global values">
<option value="inherit">inherit</option>
<option value="initial">initial</option>
<option value="revert">revert</option>
<option value="revert-layer">revert-layer</option>
<option value="unset">unset</option>
<option value="all">all</option>
</optgroup>
</select>
</div>
</div>
<div class="control">
<label for="direction">direction:</label>
<select name="direction" id="direction">
<option value="ltr" selected>ltr</option>
<option value="rtl">rtl</option>
</select>
</div>
<div class="control">
<label for="writing-mode">writing-mode:</label>
<select name="writing-mode" id="writing-mode">
<option value="horizontal-tb">horizontal-tb</option>
<option value="vertical-rl">vertical-rl</option>
<option value="vertical-lr">vertical-lr</option>
</select>
</div>
<div class="control">
<label for="scrollbar-gutter">scrollbar-gutter:</label>
<select name="scrollbar-gutter" id="scrollbar-gutter">
<option value="auto">auto</option>
<option value="stable">stable</option>
<option value="stable both-edges">stable both-edges</option>
</select>
</div>
<div class="control">
<div class="button button--change" id="change">Toggle Size and Content</div>
</div>
</form>
@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: grid;
grid-template-columns: 1fr auto;
gap: var(--gap);
}
form {
padding: 1rem;
background-color: rgb(0 0 0 / 0.6);
backdrop-filter: blur(20px);
}
.control {
display: grid;
grid-template-columns: 8em 1fr;
gap: 5px;
align-items: center;
}
.control:not(:last-child) {
margin-bottom: 1rem;
}
.control label {
width: min(8em, 100%);
text-align: right;
}
form select {
width: clamp(4em, 100%, 9em);
background: rgb(255 255 255 / 0.3);
outline: none;
padding: 10px 2px 10px 10px;
font-size: 1rem;
color: #fff;
text-shadow: 1px 1px 1px rgb(0 0 0 / 30%);
border: 1px solid rgba(0, 0, 0, 0.3);
font-family: "Exo", Arial, sans-serif;
border-radius: 4px;
box-shadow: inset 0 -5px 45px rgb(100 100 100 / 20%),
0 1px 1px rgb(255 255 255 / 20%);
transition: box-shadow 0.5s ease;
}
form select:focus {
box-shadow: inset 0 -5px 45px rgb(100 100 100 / 40%),
0 1px 1px rgb(255 255 255 / 20%);
border-color: #0c69f3;
}
.overflow__box {
inline-size: 400px;
max-block-size: 360px;
border: 1px solid #f9f9f9;
border-radius: 4px;
box-shadow: 0 0 1px rgb(0 0 0 / 0.4);
padding: 2rem;
margin: auto;
background-color: rgb(90 120 111 / 0.5);
}
.element {
padding: 1.2em;
background: linear-gradient(rgba(255, 255, 255, 0.6) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.6) 1px, transparent 1px),
linear-gradient(rgba(255, 255, 255, 0.6) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.6) 1px, transparent 1px),
linear-gradient(
135deg,
rgba(84, 232, 220, 1) 0%,
rgba(241, 231, 103, 1) 25%,
rgba(240, 229, 104, 1) 50%,
rgba(254, 182, 69, 1) 75%,
rgba(250, 118, 47, 1) 100%
);
background-size: 20px 20px, 20px 20px, 20px 20px, 20px 20px, 100% 100%;
background-blend-mode: hard-light, overlay, screen, saturation;
color: #000;
letter-spacing: 0.0125em;
hyphens: auto;
text-shadow: 1px 1px 0 rgb(255 255 255 / 50%);
font-size: 1.25em;
}
h2 {
font-size: clamp(1.2rem, 2vw + 1.5rem, 2rem);
}
.element > * + * {
margin-block-start: 2rem;
line-height: 1.6;
}
.overflow__box {
--direction: ltr;
--writing-mode: horizontal-tb;
--scrollbar-gutter: auto;
direction: var(--direction);
writing-mode: var(--writing-mode);
scrollbar-gutter: var(--scrollbar-gutter);
}
.content {
display: none;
}
.element--wide {
width: 45vmax;
}
.element--wide .content {
display: block;
}
.button {
--background-color: #1b86f9;
appearance: button;
background-color: var(--background-color);
border: none;
color: #fff;
border-radius: 8px;
padding: 1em 2em;
box-shadow: 0 0 0.2em var(--background-color);
cursor: pointer;
font-family: "Exo", Arial, sans-serif;
transition: all 0.28s ease-in-out;
grid-column: 2 / -1;
margin-right: auto;
}
.button:focus,
.button:hover {
--background-color: #3f51b5;
}
@media screen and (max-width: 768px) {
body {
grid-template-columns: auto;
grid-template-rows: 1fr auto;
}
form {
width: 100%;
}
}
const keyDom = document.querySelector("#overflow");
const valueDom = document.querySelector("#value");
const boxDom = document.querySelector("#box");
const dirDom = document.querySelector("#direction");
const writingMode = document.querySelector("#writing-mode");
const scrollbarGutter = document.querySelector("#scrollbar-gutter");
const toggleButton = document.querySelector(".button");
const ele = document.querySelector(".element");
let key, value;
function setStyle() {
boxDom.style = {};
boxDom.style.setProperty(`${key}`, `${value}`);
}
window.addEventListener("load", () => {
key = keyDom.value;
value = valueDom.value;
setStyle();
});
keyDom.addEventListener("change", () => {
key = keyDom.value;
console.log("key===>", key);
setStyle();
});
valueDom.addEventListener("change", () => {
value = valueDom.value;
setStyle();
});
[dirDom, writingMode, scrollbarGutter].forEach((selector) => {
selector.addEventListener("change", (etv) => {
boxDom.style.setProperty(`--${etv.target.id}`, `${etv.target.value}`);
});
});
toggleButton.addEventListener("click", () => {
ele.classList.toggle("element--wide");
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.