Skip to content

Instantly share code, notes, and snippets.

@idahopotato1
Last active April 8, 2021 22:58
Show Gist options
  • Save idahopotato1/f1a7dcf42d6a1008b2a9a61c1de9719d to your computer and use it in GitHub Desktop.
Save idahopotato1/f1a7dcf42d6a1008b2a9a61c1de9719d to your computer and use it in GitHub Desktop.
Expanding Cards - use this for expanding ad pages
<div class="container">
<div class="panel panel-1">
<h3>Explore the word</h3>
</div>
<div class="panel panel-2">
<h3>Beautiful blue sky</h3>
</div>
<div class="panel panel-3 active">
<h3>Mountain</h3>
</div>
<div class="panel panel-4">
<h3>Sunrise</h3>
</div>
<div class="panel panel-5">
<h3>Night sky stars falling</h3>
</div>
</div>
const panels = document.querySelectorAll(".panel");
panels.forEach((panel) => {
panel.addEventListener("click", () => {
removeActiveClasses(panels);
panel.classList.add("active");
});
});
function removeActiveClasses(panels) {
panels.forEach((panel) => {
panel.classList.remove("active");
});
}
@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap");
* {
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
margin: 0;
background-color: #05070f;
}
.panel-1 {
background-image: url("https://images.unsplash.com/photo-1513002749550-c59d786b8e6c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
}
.panel-2 {
background-image: url("https://images.unsplash.com/photo-1436891620584-47fd0e565afb?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
}
.panel-3 {
background-image: url("https://images.unsplash.com/photo-1465080357990-d4bc259ec4a9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
}
.panel-4 {
background-image: url("https://images.unsplash.com/photo-1572003818138-19cf96ee15e7?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
}
.panel-5 {
background-image: url("https://images.unsplash.com/photo-1472552944129-b035e9ea3744?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80");
}
.container {
display: flex;
width: 90%;
}
.panel {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 30px;
cursor: pointer;
flex: 0.5;
margin: 5px;
position: relative;
transition: flex 0.7s ease-in;
}
.panel h3 {
position: absolute;
top: 30px;
left: 20px;
color: rgb(247, 251, 255);
font-size: 30px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
@media (max-width: 480px) {
.container {
width: 100vw;
}
.panel:nth-of-type(4),
.panel:nth-of-type(5) {
display: none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment