Tab Gallery using HTML , CSS & JavaScript

Tab Gallery using HTML , CSS & JavaScript

Hello developers, today in this blog, you'll learn how to create a Tab Gallery using HTML, CSS & JavaScript.

The Tab Gallery is simply an online gallery that displays some images as a tab. In this Tab Gallery, there are three images at the top and the space below to it. When you click on any of the particular top images, that particular image will get displayed at the center of the webpage as the main image.

You can also change the main image, by click the other images. The image which is displayed at the center has the crossbar at the top-right corner which is used to close the tab. JavaScript code is used to make the Tab Gallery work functionally.

The source code of this Tab 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 Tab Gallery with your creativity and can take this project to the next level.

Tab Gallery using HTML, CSS & JavaScript [Source Code]

To make this website, you would like to make three files: an HTML file, a CSS file, and 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.

<!DOCTYPE html> <html> <head> <title>Tab gallery || Learning Robo</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="maincard"> <div class="row"> <div class="column"> <img src="https://cdn.pixabay.com/photo/2021/08/03/11/48/canal-6519196__340.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);"> </div> <div class="column"> <img src="https://cdn.pixabay.com/photo/2021/07/12/19/49/landscape-6421773__340.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);"> </div> <div class="column"> <img src="https://cdn.pixabay.com/photo/2021/08/08/10/34/ocean-6530523__340.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);"> </div> <div class="column"> <img src="https://cdn.pixabay.com/photo/2021/08/05/20/31/penguins-6524840__340.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);"> </div> </div> <div class="container"> <span onclick="this.parentElement.style.display='none'" class="closebtn">×</span> <img id="expandedImg"> <div id="imgtext"></div> </div> </div> <div class="credit">Made with <span style="color:tomato">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> <script src="script.js"> </script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and remember that you have to make a file with a .css extension.


* {
    box-sizing: border-box;
  }
  body {
    margin: 0;
    font-family: Arial;
    background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
  }
  .maincard{
      background-color: #fff;
      width: 90%;
  margin: 10px auto;
  padding:10px;
  border-radius: 10px;
  height:600px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  }
  .column {
    width: 25%;
    padding: 10px;
  }
  .column img {
    opacity: 1; 
    cursor: pointer; 
    width:25%;
    height:150px;
    border-radius: 10px;
    box-shadow: rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px;
  }
  .column img:hover {
    opacity: .9;
  }
  .row{
    display: flex;
  }
  .container {
    position: relative;
    display: none;
    margin: 5px auto;
    width: 70%;
  }
  .container img {
    width:100%;
    height:400px;
    border-radius: 10px;
    box-shadow: rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px;
  }
  #imgtext {
    position: absolute;
    bottom: 15px;
    left: 15px;
    color: white;
    font-size: 20px;
    background-color: #202124;
    padding:10px;
    border-radius: 10px;
  }
  .closebtn {
    position: absolute;
    top: 10px;
    right: 15px;
    color: white;
    font-size: 35px;
    cursor: pointer;
  }
  .credit{
    text-align: center;
    color: #000;
    font-weight: 900;
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.credit a{
    text-decoration: none;
    color:#202124;
    font-weight: bold;
} 
JavaScript makes the page work functionally. At last, create a JavaScript file with the name of script.js and remember that you've got need to make a file with a .js extension.


function myFunction(imgs) {
    var expandImg = document.getElementById("expandedImg");
    var imgText = document.getElementById("imgtext");
    expandImg.src = imgs.src;
    imgText.innerHTML = imgs.alt;
    expandImg.parentElement.style.display = "block";
  }
We hope you would like this Tab Gallery using HTML & CSS.

Thank you for reading our blog. If you face any problem in creating this Tab Gallery using HTML & CSS, 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

إرسال تعليق

Thank you
Learning robo team

Post a Comment (0)

أحدث أقدم
Learning Robo says...
code copied
Welcome