Hello developers, today in this blog, you'll learn how to create an Expandable Image Gallery using HTML, CSS & JavaScript.
The Expandable Image Gallery contains a wide variety of content, including images, text, list groups, links, etc. The images are stacked vertically in narrow cards and depending on the screen size the image will appear. When you click on a narrow image it expands and the existing image will shrink.
In this blog (Expandable Image Gallery) on the webpage, there are five images where there is one expanded image and, four shrunk images. When you click on the shrunk image, the image will get expand. You can view all the shrunk images by clicking each of them. The expanded image contains some text about the image or the title of the image which is at the left bottom of the image. In this Expandable Image Gallery, you can give the image as much you need.
The source code of these Expandable Image Gallery using HTML, CSS & JavaScript is given below, if you want the source code of this program, you can copy it. You can use this code of Expandable Image Gallery with your creativity and, can take this project to the next level.
Expandable Image Gallery [Source Code]
To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html, and remember, you have to create a file with a .html extension.
@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;
background: -webkit-linear-gradient(to right, #38ef7d, #11998e);
background: linear-gradient(to right, #38ef7d, #11998e);
}
.container {
display: flex;
width: 100%;
margin: 10px;
}
.panel {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 12px;
color: #fff;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
-webkit-transition: all 700ms ease-in;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 60px;
left: 20px;
margin: 0;
opacity: 0;
color: #000;
background-color: #fff;
padding: 5px;
border-radius:5px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.panel.active {
flex: 8;
}
.panel.active h3 {
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
.credit a{
text-decoration: none;
color: #000;
text-decoration: underline;
}
.credit {
color:#000;
margin-top: 10px;
opacity: 0;
position: absolute;
bottom: 20px;
left: 20px;
}
.panel.active .credit {
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
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')
})
}
Thank you for reading our blog. If you face any problem in creating these Expandable Image Gallery using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.
إرسال تعليق
Thank you
Learning robo team