<div class="container">
<h2>display:none(前)</h2>
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
</div>
<div class="container">
<h2>display:none(后)</h2>
<div class="box">1</div>
<div class="box is-toggle">2</div>
<div class="box">3</div>
<button class="toggle-display">Toggle Display</button>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
display: grid;
gap: 2vw;
grid-template-columns: repeat(auto-fill, minmax(40vw, 1fr));
place-items: center;
}
.container {
display: grid;
grid-template-columns: repeat(3, minmax(30vh, 1fr));
gap: 2vw;
place-items: center;
&:nth-child(2) .box {
background: #f36;
color: #fff;
}
}
.box {
background: #fff;
border-radius: 3px;
min-height: 30vh;
width: 100%;
box-shadow: 0 0 16px rgba(0,0,0,0.07);
font-size: 2rem;
display: flex;
align-items: center;
justify-content: center;
color: rgba(0,0,0,0.2);
font-weight: 700;
transition: all .28s ease;
&.is-hidden {
display: none;
}
}
h2 {
grid-column: 1 / 4;
}
.toggle-display {
background: #327def;
padding: 0.5rem 1rem;
border: none;
color: #fff;
font-weight: 700;
position: fixed;
top: 20px;
left: 50%;
transform: translate(-50%, 0);
cursor: pointer;
transition: 0.25s ease;
&:hover,
&:active,
&:focus {
background: darken(#327def, 5%);
transition: 0.25s ease;
}
}
View Compiled
document.querySelector('.toggle-display').addEventListener('click', function() {
document.querySelector('.box.is-toggle').classList.toggle('is-hidden');
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.