About:
In this Blog , I will be designing responsive cards. I am implementing this using simple Html, Css and JavaScript , we are not using any frameworks.
For this, I took 5 images of Seven Wonders in the world. I am using three files here, You can find the source for this and for output , you can refer to the video below.
I am attaching images I used for your reference, You have to create a Assests folder and have to place these images in it.
Index.html -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Expanding Cards</title>
</head>
<body>
<div class="container">
<div class="panel active" style="background-image: url('./Assets/Christ_the_redeemer.jpg')">
<h3>Christ The Redeemer</h3>
</div>
<div class="panel" style="background-image: url('./Assets/colosseum.jpg')">
<h3>Colosseum</h3>
</div>
<div class="panel" style="background-image: url('./Assets/Great_wall_of_China.jpg')">
<h3>Great Wall Of China</h3>
</div>
<div class="panel" style="background-image: url('./Assets/TajMahal.jpg')">
<h3>Taj Mahal</h3>
</div>
<div class="panel" style="background-image: url('./Assets/MachiPicchu.jpg')">
<h3>Machi Picchu</h3>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Style.css -
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
font-family: 'Muli', sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.container {
display: flex;
width: 90vw;
}
.panel {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: #fff;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
-webkit-transition: all 700ms ease-in;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 20px;
left: 20px;
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;
}
}
script.js -
const panels = document.querySelectorAll('.panel')
panels.forEach(panel => {
panel.addEventListener('click', () => {
removeActiveClasses()
panel.classList.add('active')
})
})
function removeActiveClasses() {
panels.forEach(panel => {
panel.classList.remove('active')
})
}
OUTPUT:-
Images for Reference:
Super ra
ReplyDelete