asimryu

side bar

Oct 20th, 2020
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.94 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Side Bar</title>
  7.     <style>
  8.         #side-bar {
  9.             height: 100%;
  10.             width: 0;
  11.             position: fixed;
  12.             z-index: 1;
  13.             top: 0;
  14.             left: 0;
  15.             background-color: #333;
  16.             transition: 0.5s;
  17.             padding-top: 50px;
  18.             overflow: hidden;
  19.         }
  20.         #side-bar a {
  21.             padding: 10px;
  22.             font-size: 20px;
  23.             color: #fff;
  24.             display: block;
  25.         }
  26.         #side-bar .btn-close {
  27.             position: absolute;
  28.             top: 10px;
  29.             right: 20px;
  30.             font-size: 30px;
  31.             color: #fff;
  32.             text-decoration: none;
  33.         }
  34.  
  35.         .btn-side-open {
  36.             font-size: 20px;
  37.             background-color: #333;
  38.             color: #fff;
  39.             padding: 5px 10px;
  40.             border: none;
  41.         }
  42.         #content {
  43.             transition: margin-left .5s;
  44.             padding: 15px;
  45.             z-index: 2;
  46.         }
  47.     </style>
  48. </head>
  49. <body>
  50.     <div id="side-bar">
  51.         <a href="#!" class="btn-close" onclick="closeSideBar();">X</a>
  52.         <a href="#!">HOME</a>      
  53.         <a href="#!">Services</a>      
  54.         <a href="#!">Products</a>  
  55.         <a href="#!">Downloads</a>
  56.         <a href="#!">Documents</a>
  57.     </div>
  58.     <div id="content">
  59.         <button class="btn-side-open" onclick="viewSideBar();">☰ View Side Bar</button>
  60.         <h1>Hello Side Bar</h1>
  61.         <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum in dignissimos minima, vel facere, ad provident, sapiente inventore voluptas fugiat dolore, debitis ab perspiciatis dolorem labore illo aperiam perferendis consequatur.</p>
  62.     </div>
  63.  
  64.     <script>
  65.         let sideBar = document.querySelector("#side-bar");
  66.         let content = document.querySelector("#content");
  67.         const viewSideBar = () => {
  68.             sideBar.style.width = "50%";
  69.             content.style.marginLeft = "50%";
  70.         }
  71.         const closeSideBar = () => {
  72.             sideBar.style.width = "0";
  73.             content.style.marginLeft = "0";
  74.         }
  75.     </script>
  76.     <!-- original code from "https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_collapse_sidebar"
  77. </body> -->
  78. </html>
Add Comment
Please, Sign In to add comment