How to Create a Portfolio Filter Gallery using HTML CSS & JavaScript

Hello friends, today we will be going to Create a Portfolio Filter Gallery using HTML CSS & JavaScript. I have posted many videos and articles before related to the JavaScript project, now this the something new that we are going to build.

Demo Tutorial of How To Create a Portfolio Filter Gallery using HTML CSS & JavaScript


As you have seen on the given demo tutorial of  How To Create a Portfolio Filter Gallery using HTML CSS & JavaScript, 

If you are feeling bored watching the given demo tutorial of How To Create a Portfolio Filter Gallery using HTML CSS & JavaScript then you can copy or download the given codes below:


How To Create a Portfolio Filter Gallery using HTML CSS & JavaScript | Free Source Code

To create this program (Filter Gallery). First, you need to create two Files one HTML File and another one is CSS File. After creating these files just paste the following codes in your file.

In the first place, make a HTML document with the name of index.html and glue the given codes in your HTML record. Keep in mind, you've to make a document with .html extension.
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <link rel='stylesheet' href='style.css'>
    <title>Portfolio Filter Gallery| Created by S-Tech04</title>
    <!-- S-Tech04 | www.youtube.com/STech04 -->
</head>
<body>
    <section>
        <ul>
            <li class="list active" data-filter="all">All</li>
            <li class="list" data-filter="mobile">Mobile</li>
            <li class="list" data-filter="watch">Watch</li>
            <li class="list" data-filter="shoe">Shoe</li>
            <li class="list" data-filter="camera">Camera</li>
            <li class="list" data-filter="headphone">Headphone</li>
        </ul>
        <div class="product">
            <div class="item-box" data-item="mobile"><img src="./images/mobile1.jpg"></div>
            <div class="item-box" data-item="watch"><img src="./images/watch1.jpg"></div>
            <div class="item-box" data-item="shoe"><img src="./images/shoe1.jpg"></div>
            <div class="item-box" data-item="camera"><img src="./images/camera1.jpg"></div>
            <div class="item-box" data-item="headphone"><img src="./images/headphone1.jpg"></div>
            <div class="item-box" data-item="mobile"><img src="./images/mobile2.jpg"></div>
            <div class="item-box" data-item="watch"><img src="./images/watch2.jpg"></div>
            <div class="item-box" data-item="shoe"><img src="./images/shoe2.jpg"></div>
            <div class="item-box" data-item="camera"><img src="./images/camera2.jpg"></div>
            <div class="item-box" data-item="headphone"><img src="./images/headphone2.jpg"></div>
            <div class="item-box" data-item="headphone"><img src="./images/headphone1.jpg"></div>
            <div class="item-box" data-item="mobile"><img src="./images/mobile3.jpg"></div>
            <div class="item-box" data-item="watch"><img src="./images/watch3.jpg"></div>
            <div class="item-box" data-item="shoe"><img src="./images/shoe3.jpg"></div>
            <div class="item-box" data-item="camera"><img src="./images/camera3.jpg"></div>
            <div class="item-box" data-item="headphone"><img src="./images/headphone3.jpg"></div>
            <div class="item-box" data-item="mobile"><img src="./images/mobile4.jpg"></div>
            <div class="item-box" data-item="watch"><img src="./images/watch4.jpg"></div>
            <div class="item-box" data-item="shoe"><img src="./images/shoe4.jpg"></div>
            <div class="item-box" data-item="camera"><img src="./images/camera4.jpg"></div>
            <div class="item-box" data-item="headphone"><img src="./images/headphone4.jpg"></div>
        </div>
    </section>
    <script src="./script.js"></script>
</body>
</html>
Second, make a CSS record with the name of style.css and glue the given codes in your CSS document. Keep in mind, you've to make a record with .css extension.
*
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: sans-serif;
}
section
{
    margin: 40px auto;
    padding: 30px;
    width: 100%;
}
section ul
{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom:10px;
}
section ul li
{
    list-style: none;
    padding: 10px 20px;
    background: #eee;
    border-radius: 20px;
    font-size: 16px;
    letter-spacing: 1;
    cursor: pointer;
    margin: 5px;
}
section ul li.active
{
    background: #03a9f4;
    color: #fff;
}
section .product
{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}
section .product .item-box
{
    width: 300px;
    height: 300px;
    position: relative;
    overflow: hidden;
    margin: 5px;
}
section .product .item-box.hide
{
    display: none;
}
section .product .item-box img
{
    position: absolute;
    top: 0%;
    left: 0%;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: 0.3s;
}
section .product .item-box:hover img
{
    transform: scale(1.3);
}
last, create a JavaScript file with the name of script.js and paste the given codes in your JavaScript file. Remember, you’ve to create a file with .js extension.
const list = document.querySelectorAll('.list')
const itemBox = document.querySelectorAll('.item-box')

list.forEach((elem)=>{
    elem.addEventListener('click',function(){
        list.forEach((elem)=>{
            elem.classList.remove('active');
        });
        this.classList.add('active');

        let value = this.getAttribute('data-filter');
        itemBox.forEach(element=>{
            element.classList.add('hide');
            if(element.getAttribute('data-item') == value || value == "all"){
                element.classList.remove('hide');
            }
        })

    })

})
That’s all, now you’ve successfully created a program to create a Portfolio Filter Gallery using HTML CSS & JavaScript. If your code doesn’t work or you’ve faced any error/problem, please download the source code files from the given download button. It’s free and a .zip file will be downloaded then you’ve to extract it.
Click on the following download button to download all source code files.


Download Now
Please Wait...
Direct Link click here.

How can I help you

Post a Comment

How can I help you

Post a Comment (0)

Previous Post Next Post