<div class="container">
<section class="contents">
我是 section 元素的文本节点(文本内容)
<p>我是一个 p 元素,同时是 section 元素的子元素</p>
</section>
</div>
<div class="container">
<section class="pseudo-elements">
<p>我是一个 p 元素,同时是 section 元素的子元素</p>
</section>
</div>
<div class="form">
<span>display:</span>
<label for="block">
<input type="radio" id="block" name="display" value="block" checked />
block
</label>
<label for="contents">
<input type="radio" name="display" value="contents" id="contents">
contents
</label>
</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;
padding: 2rem 0;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 20px;
font-size: clamp(20px, 3vw + 2rem, 40px);
}
.container {
border: 1px dotted #fff;
}
.contents {
border: 6px solid #f44336;
padding: 2rem;
background-image: linear-gradient(to right, #09f, #90f);
text-shadow: 1px 1px 0 rgb(0 0 0 / 0.85);
filter: drop-shadow(8px 8px 1px rgb(0 0 0 / 0.85));
display: var(--display, block);
transition: all 0.28s ease-in-out;
}
p {
background-color: #607d8b;
padding: 2rem 1rem;
font-size: 80%;
color: #cddc39;
}
.pseudo-elements::before {
content: "我是 section 元素的文本(伪元素生成)!";
}
.form {
display: flex;
justify-content: center;
gap: 10px;
font-size: 1.5rem;
}
label {
display: inline-flex;
align-items: center;
gap: 5px;
}
input {
width: 18px;
height: 18px;
}
const rootEle = document.documentElement;
const inputs = document.querySelectorAll('input[type="radio"]');
inputs.forEach((input) => {
input.addEventListener("click", (etv) => {
rootEle.style.setProperty("--display", etv.target.value);
});
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.