laciikee

LAKY

Jun 7th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.77 KB | None | 0 0
  1.  
  2. <meta name="viewport" content="width=device-width, initial-scale=1">
  3. <style>
  4. * {
  5.   box-sizing: border-box;
  6. }
  7.  
  8. body {
  9.   background-color: #f1f1f1;
  10.   padding: 20px;
  11.   font-family: Arial;
  12. }
  13.  
  14. /* Center website */
  15. .main {
  16.   max-width: 1000px;
  17.   margin: auto;
  18. }
  19.  
  20. h1 {
  21.   font-size: 50px;
  22.   word-break: break-all;
  23. }
  24.  
  25. .row {
  26.   margin: 10px -16px;
  27. }
  28.  
  29. /* Add padding BETWEEN each column */
  30. .row,
  31. .row > .column {
  32.   padding: 8px;
  33. }
  34.  
  35. /* Create three equal columns that floats next to each other */
  36. .column {
  37.   float: left;
  38.   width: 33.33%;
  39.   display: none; /* Hide all elements by default */
  40. }
  41.  
  42. /* Clear floats after rows */
  43. .row:after {
  44.   content: "";
  45.   display: table;
  46.   clear: both;
  47. }
  48.  
  49. /* Content */
  50. .content {
  51.   background-color: white;
  52.   padding: 10px;
  53. }
  54.  
  55. /* The "show" class is added to the filtered elements */
  56. .show {
  57.   display: block;
  58. }
  59.  
  60. /* Style the buttons */
  61. .btn {
  62.   border: none;
  63.   outline: none;
  64.   padding: 12px 16px;
  65.   background-color: white;
  66.   cursor: pointer;
  67. }
  68.  
  69. .btn:hover {
  70.   background-color: #ddd;
  71. }
  72.  
  73. .btn.active {
  74.   background-color: #666;
  75.   color: white;
  76. }
  77. </style>
  78. </head>
  79. <body>
  80.  
  81. <!-- MAIN (Center website) -->
  82. <div class="main">
  83.  
  84.  
  85. <div id="myBtnContainer">
  86.   <button class="btn active" onclick="filterSelection('all')"> Zobraziť všetko</button>
  87.   <button class="btn" onclick="filterSelection('nature')"> Najlepšie zisky</button>
  88.   <button class="btn" onclick="filterSelection('cars')"> Zisky</button>
  89.   <button class="btn" onclick="filterSelection('people')"> Mínusy</button>
  90. </div>
  91.  
  92. <!-- Portfolio Gallery Grid -->
  93. <div class="row">
  94.   <div class="column nature">
  95.     <div class="content">
  96.       <img src="/w3images/mountains.jpg" alt="Mountains" style="width:100%">
  97.       <h4>Mountains</h4>
  98.       <p>Lorem ipsum dolor..</p>
  99.     </div>
  100.   </div>
  101.   <div class="column nature">
  102.     <div class="content">
  103.     <img src="/w3images/lights.jpg" alt="Lights" style="width:100%">
  104.       <h4>Lights</h4>
  105.       <p>Lorem ipsum dolor..</p>
  106.     </div>
  107.   </div>
  108.   <div class="column nature">
  109.     <div class="content">
  110.     <img src="/w3images/nature.jpg" alt="Nature" style="width:100%">
  111.       <h4>Forest</h4>
  112.       <p>Lorem ipsum dolor..</p>
  113.     </div>
  114.   </div>
  115.  
  116.   <div class="column cars">
  117.     <div class="content">
  118.       <img src="/w3images/cars1.jpg" alt="Car" style="width:100%">
  119.       <h4>Retro</h4>
  120.       <p>Lorem ipsum dolor..</p>
  121.     </div>
  122.   </div>
  123.   <div class="column cars">
  124.     <div class="content">
  125.     <img src="/w3images/cars2.jpg" alt="Car" style="width:100%">
  126.       <h4>Fast</h4>
  127.       <p>Lorem ipsum dolor..</p>
  128.     </div>
  129.   </div>
  130.   <div class="column cars">
  131.     <div class="content">
  132.     <img src="/w3images/cars3.jpg" alt="Car" style="width:100%">
  133.       <h4>Classic</h4>
  134.       <p>Lorem ipsum dolor..</p>
  135.     </div>
  136.   </div>
  137.  
  138.   <div class="column people">
  139.     <div class="content">
  140.       <img src="/w3images/people1.jpg" alt="Car" style="width:100%">
  141.       <h4>Girl</h4>
  142.       <p>Lorem ipsum dolor..</p>
  143.     </div>
  144.   </div>
  145.   <div class="column people">
  146.     <div class="content">
  147.     <img src="/w3images/people2.jpg" alt="Car" style="width:100%">
  148.       <h4>Man</h4>
  149.       <p>Lorem ipsum dolor..</p>
  150.     </div>
  151.   </div>
  152.   <div class="column people">
  153.     <div class="content">
  154.     <img src="/w3images/people3.jpg" alt="Car" style="width:100%">
  155.       <h4>Woman</h4>
  156.       <p>Lorem ipsum dolor..</p>
  157.     </div>
  158.   </div>
  159. <!-- END GRID -->
  160. </div>
  161.  
  162. <!-- END MAIN -->
  163. </div>
  164.  
  165. <script>
  166. filterSelection("all")
  167. function filterSelection(c) {
  168.   var x, i;
  169.   x = document.getElementsByClassName("column");
  170.   if (c == "all") c = "";
  171.   for (i = 0; i < x.length; i++) {
  172.    w3RemoveClass(x[i], "show");
  173.    if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
  174.   }
  175. }
  176.  
  177. function w3AddClass(element, name) {
  178.   var i, arr1, arr2;
  179.   arr1 = element.className.split(" ");
  180.   arr2 = name.split(" ");
  181.   for (i = 0; i < arr2.length; i++) {
  182.    if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
  183.  }
  184. }
  185.  
  186. function w3RemoveClass(element, name) {
  187.  var i, arr1, arr2;
  188.  arr1 = element.className.split(" ");
  189.  arr2 = name.split(" ");
  190.  for (i = 0; i < arr2.length; i++) {
  191.    while (arr1.indexOf(arr2[i]) > -1) {
  192.       arr1.splice(arr1.indexOf(arr2[i]), 1);    
  193.     }
  194.   }
  195.   element.className = arr1.join(" ");
  196. }
  197.  
  198.  
  199. // Add active class to the current button (highlight it)
  200. var btnContainer = document.getElementById("myBtnContainer");
  201. var btns = btnContainer.getElementsByClassName("btn");
  202. for (var i = 0; i < btns.length; i++) {
  203.  btns[i].addEventListener("click", function(){
  204.    var current = document.getElementsByClassName("active");
  205.    current[0].className = current[0].className.replace(" active", "");
  206.    this.className += " active";
  207.  });
  208. }
  209. </script>
  210.  
Advertisement
Add Comment
Please, Sign In to add comment