<div class="device device-iphone-x">
<div class="device-frame">
<div class="device-content">
<div class="container">
<figure>
<figcaption>Card Title</figcaption>
<img src="https://picsum.photos/1200/300?random=5" alt="">
</figure>
<figure>
<figcaption>Card Title</figcaption>
<div class="box"></div>
</figure>
</div>
<div id="switch--wrapper">
<input type="checkbox" id="switch" name="switch" />
<label for="switch"></label>
</div>
</div>
</div>
<div class="device-stripe"></div>
<div class="device-header"></div>
<div class="device-sensors"></div>
<div class="device-btns"></div>
<div class="device-power"></div>
</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;
color: #fff;
display: grid;
place-content: center;
padding: 1rem;
gap: 1rem;
}
.device-iphone-x {
height: min(100vh - 2rem, 100vh);
min-height: 540px;
}
.device-iphone-x .device-frame,
.device-iphone-x .device-content {
height: 100%;
}
.device-iphone-x .device-content {
overflow: hidden auto;
}
.container {
padding: 3rem 1rem 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
justify-content: center;
align-items: center;
}
figure,
figcaption {
margin: 0;
padding: 0;
}
figure {
width: 100%;
padding: 1rem;
border: 1px solid rgb(0 0 0 / 0.125);
box-shadow: 0 0 1px 1px rgb(0 0 0 / 0.025);
background-color: #fff;
color: #444;
border-radius: 10px;
display: flex;
flex-direction: column;
}
figcaption {
font-size: clamp(1rem, 1vw + 1.125rem, 1.5rem);
margin-bottom: 0.25em;
text-shadow: 1px 1px 1px rgb(220 220 220 / 0.12);
}
figure img {
border-radius: 10px;
border: 1px solid rgb(0 0 0 / 0.125);
box-shadow: 0 0 1px 1px rgb(0 0 0 / 0.025);
aspect-ratio: 4 / 1;
}
figure .box {
aspect-ratio: 4 / 1;
background: rgb(145 39 39 / 50%);
border-radius: 10px;
border: 1px solid rgb(0 0 0 / 0.125);
box-shadow: 0 0 1px 1px rgb(0 0 0 / 0.025);
}
:root {
--white: #ffffff;
--light: #f0eff3;
--black: #000000;
--dark-blue: #1f2029;
--dark-light: #353746;
--red: #3c0076;
--yellow: #a500ff;
--grey: #ecedf3;
--width: 386px;
}
#switch--wrapper {
position: absolute;
left: 50%;
white-space: nowrap;
transform: translate3d(-50%, 0, 0);
z-index: 999;
bottom: 2rem;
text-align: center;
}
#switch--wrapper span {
margin-top: 1rem;
color: #444;
}
[type="checkbox"]:checked,
[type="checkbox"]:not(:checked) {
position: absolute;
left: -9999px;
width: 0;
height: 0;
visibility: hidden;
}
[type="checkbox"]:checked + label,
[type="checkbox"]:not(:checked) + label {
position: relative;
width: 70px;
display: inline-block;
padding: 0;
text-align: center;
height: 6px;
border-radius: 4px;
background-image: linear-gradient(298deg, var(--red), var(--yellow));
z-index: 100 !important;
}
[type="checkbox"]:checked + label:before,
[type="checkbox"]:not(:checked) + label:before {
position: absolute;
font-weight: 900;
cursor: pointer;
top: -17px;
z-index: 2;
font-size: 14px;
line-height: 40px;
text-align: center;
width: 40px;
height: 40px;
border-radius: 50%;
transition: all 300ms linear;
}
[type="checkbox"]:not(:checked) + label:before {
content: "Off";
left: 0;
color: var(--grey);
background-color: var(--dark-light);
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(26, 53, 71, 0.07);
}
[type="checkbox"]:checked + label:before {
content: "On";
left: 30px;
color: var(--yellow);
background-color: var(--dark-blue);
box-shadow: 0 4px 4px rgba(26, 53, 71, 0.25), 0 0 0 1px rgba(26, 53, 71, 0.07);
}
figure img,
figure .box {
transition: all 0.2s ease-in;
width: var(--width);
}
const checkedEle = document.querySelector("#switch--wrapper");
const rootEle = document.documentElement;
checkedEle.addEventListener("change", (e) => {
if (e.target.checked) {
rootEle.style.setProperty("--width", "min(100%, 386px)");
} else {
rootEle.style.setProperty("--width", "386px");
}
});
This Pen doesn't use any external JavaScript resources.