So es ist neu hochgeladen
style.css
.image-gallery {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
}
.image-gallery>figure {
margin: 0;
flex-basis:350px;
/* width: 350px; */
position: relative;
cursor: pointer;
}
.image-gallery::after {
content: "";
flex-basis: 350px;
}
.image-gallery figure img {
object-fit: cover;
max-width: 100%;
height: auto;
vertical-align: middle;
border-radius: 5px;
}
figure.hidden {
flex-basis: 0;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
background: rgba(57, 57, 57, 0.502);
top: 0;
left: 0;
transform: scale(0);
transition: all 0.2s 0.1s ease-in-out;
color: #fff;
border-radius: 5px;
/* center overlay text */
display: flex;
align-items: center;
justify-content: center;
}
/* hover */
.image-gallery figure:hover .overlay {
transform: scale(1);
}
Alles anzeigen
filter.css
/* body,h1,ul,li{
margin: 0;
padding: 0;
} */
body{
background-color: #667d8e;
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
#filter{
width: 85%;
margin: 50px auto;
}
#filter>ul{
width: 100%;
display: flex;
justify-content: center;
margin-top: 10px;
border-bottom: 2px solid rgba(2, 2, 2, 0.57);
padding-bottom: 10px;
box-sizing: border-box;
margin-bottom: 10px;
}
#filter>ul>li{
list-style: none;
background-color: rgb(191, 155, 230);
padding: 5px 10px;
margin: 0 10px;
cursor: pointer;
font-size: 1.2em;
}
#filter>ul>li.active{
background-color: rgba(41, 255, 41, 0.897);
}
.photo{
width: 85%;
padding: 0 10px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.photo img{
width: 300px;
height: 180px;
margin-bottom: 10px;
}
Alles anzeigen
und das script
const liItem = document.querySelectorAll('ul li');
const figureItem = document.querySelectorAll('div.image-gallery figure');
liItem.forEach(li => {
li.onclick = function() {
//active
liItem.forEach(li => {
li.classList.remove('active');
})
li.classList.add("active");
//Filter
const value = li.textContent;
figureItem.forEach(figure => {
if (figure.dataset.filter == value.toLowerCase() || value == "All") {
figure.classList.remove('hidden');
} else {
figure.classList.add('hidden');
}
});
}
});
Alles anzeigen
noch ist aber der Wurm drin