Responsive template with menu top fixed

HTML
<!DOCTYPE html> <html lang="zxx"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes"> <link rel="stylesheet" href="css.css"> <title>M3nu</title> </head> <body> <div class="wr"> <div id="topmenu"> <a class="logo" href="/">Logo</a> <div id="menu"></div> </div> <ul id="nav" class="nav hid"> <li> <a href="#products">Products</a> </li> <li> <a href="#contacts">Contacts</a> </li> <li> <a href="#calcwrap">Calculator</a> </li> <li> <a href="#about">About Us</a> </li> <li> <a href="https://www.google.com/">External link</a> </li> </ul> <div class="wrap"> <div class="content"> <div class="item1"> <h1 id="contacts">Contacts</h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <div id="calcwrap"> <div id="calculator"> <input type="text" id="src" data-ekr="ekr" value="0" disabled> <input data-fun="clr" type="button" value="C"> <div></div> <div></div> <input data-fun="div" type="button" value="/"> <input data-num="7" type="button" value="7"> <input data-num="8" type="button" value="8"> <input data-num="9" type="button" value="9"> <input data-fun="mul" type="button" value="*"> <input data-num="4" type="button" value="4"> <input data-num="5" type="button" value="5"> <input data-num="6" type="button" value="6"> <input data-fun="min" type="button" value="-"> <input data-num="1" type="button" value="1"> <input data-num="2" type="button" value="2"> <input data-num="3" type="button" value="3"> <input data-num="0" type="button" value="0"> <input data-fun="dot" type="button" value=","> <input data-fun="equ" type="button" value="="> <input data-fun="plu" type="button" value="+"> </div> </div> </div> <div class="item2"> <h1 id="about">about us</h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <h1 id="others">about others</h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. <h1 id="products">products</h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </div> </div> </div> </div> </body> </html>
CSS
html,body{ height:100%; box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } body{ color: #333; font: 16px/1.5em Arial, Geneva, Tahoma, sans-serif; margin:0; position:relative; overflow-y:hidden; } .slide{width:100px;height:24px;background:#777;position:relative;margin:24px 0 0 0;z-index:3;} .slider{width:24px;height:24px;background:#000;position:absolute;top:0;} .slideNum{background:#fff;padding:0 6px;height:24px;min-width:12px;max-width:48px;position:relative;} input, p, blockquote, pre, td, th, label { font-size: 1em; /* 16px */ line-height: 1.5000em; /* 24px */ margin: 0; } h1 { font-size: 1.5000em; /* 24px */ line-height: 1.0000em; /* 24px */ color:#777; margin: 0; margin-top:24px; text-align:center; text-transform:uppercase; } h2 { font-size: 1.2500em; /* 20px */ line-height: 1.2000em; /* 24px */ margin: 0; } h3,h4,h5 { font-size: 1.0000em; /* 16px */ line-height: 1.5000em; /* 24px */ margin: 0; } .wr{ height: 100%; overflow-y:scroll; pointer-events: all; } .wrap { display: block; top:0; position: absolute; height:inherit; width: 100%; background: #eee; background: repeating-linear-gradient(45deg, rgba(200, 200, 200, 0.1) 300px, rgba(200, 200, 200, 0.3) 301px, rgba(200, 200, 200, 0.5) 1000px, rgba(200, 200, 200, 0.2) 1001px), repeating-linear-gradient(135deg, rgba(200, 200, 200, 0.2) 300px, rgba(200, 200, 200, 0.5) 301px, rgba(200, 200, 200, 0.2) 1000px, rgba(200, 200, 200, 0.1) 1001px); overscroll-behavior-y: inherit; overflow-x:hidden; backface-visibility:hidden; scroll-behavior:smooth; } .content{ margin:0 auto; padding: 48px 24px; box-shadow: 0 0 2px 2px #bbb; background: #fafafa; } #topmenu{ box-shadow:0 0 0 1px #777 inset, 0 0 2px 1px #777; height:48px; width:100%; display:block; z-index:100; position:relative; background:#000; overflow:hidden; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -moz-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; standard-user-select: none; color:#fafafa; line-height:48px; font-family:sans-serif; } #topmenu a{ text-decoration:none; color:#fafafa; padding:0 12px; } #menu { left:0; top:0; position:absolute; width:48px; height:48px; z-index:9; overflow:hidden; cursor:pointer; will-change: transform; text-align:center; font-size: 1.2500em; /* 20px */ box-shadow:-1px 0 0 0 #777 inset; } #menu.exp::after{ content:"X"; color: #777; } #menu:after{ content:"iii"; display:block; width:48px; height:48px; position:absolute; transform:rotateZ(-90deg); line-height:48px; transition:0.2s all; pointer-events:none; text-transform:uppercase; } #nav{ top:2px; counter-reset:num; background:#fff; transition:.2s all; padding:0; margin:0 auto; list-style:none; z-index:1; width:100%; overflow-y: auto; overscroll-behavoir:contain; max-height:100%; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -moz-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; standard-user-select: none; box-shadow: 0 -1px 0 1px #eee inset, 0 0 2px 0 #aaa; position:relative; backface-visibility:hidden; will-change: transform; } .nav:not(a) { font-size: 0; } #nav li a{ line-height: 4em; color:#333; text-decoration:none; box-shadow:0 -1px 0 0 #eee inset; display:block; padding:0 0 0 12px; text-transform:uppercase; font-size:12px; } #nav li a:hover{ background: #aaa; color:#f00; } #nav li a:before{ counter-increment:num; content:counter(num)"{ "; text-transform:lowercase; } #nav li a:after{ content:" }"; } .hid{ visibility:hidden; transform:translateY(-105%); } .logo{position:absolute;right:0;} @media only screen and (max-width:900px) { #nav { padding-right:0; text-align:left; } #nav li a{ font-size:10px; line-height: 4.8; } } @media only screen and (min-width:640px) { #nav:after{ content:""; display:inline-block; width:10%; height:48px; float:right; } #topmenu { display:none; } #nav li a{ outline:none; background: linear-gradient(100deg, rgba(0, 0, 0 , 0) 11px, rgba(0, 0, 0 , .1) 12px, rgba(0, 0, 0 , 0) 13px, rgba(0, 0, 0 , 0) 100%); } #nav li a:hover{ background: linear-gradient(100deg, rgba(0, 0, 0 , 0) 11px, rgba(0, 0, 0 , .1) 12px, rgba(0, 0, 0 , 0) 13px, rgba(0, 0, 0 , 0) 100%); color:#f00; } #nav{ visibility:visible; transform:translate(0); top:0; text-align:right; } #nav li{ display:inline-block; } .content { display: flex; /* or inline-flex */ flex-direction: row; justify-content:center; align-items: stretch; align-content: center; max-width:1000px; position:relative; } .item1{ flex: 0 0 120px; } .item2{ flex: 1; } .item2{ padding:0 0 0 24px; } } .item1,.item2{ text-align:justify; } #calcwrap *{ border-radius:3px; } #calcwrap{ width:100%; padding-bottom:100%; position:relative; margin:24px auto 0; } #calculator{ display:inline-grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(6, 1fr); justify-items: center; align-items: center; margin:0 auto; text-align:center; width:100%; height:100%; background:#aaa; height:min-content; grid-gap:2px; box-shadow:0 0 0 4px #aaa; position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #calculator input{ background:#fafafa; box-shadow:0 0 0 1px #fff inset; width:100%; height:100%; min-height:1em; position:relative; cursor:pointer; border:0; outline:0; font-family:serif; } #calculator:focus, #calculator input:focus{ outline:0; -moz-outline:0; border:0; } input::-moz-focus-inner { border: 0; } #calculator>[data-fun="clr"]{ background: #f54; } #calculator>[data-fun="plu"]{ grid-row-start: 5; grid-row-end: 7; grid-column-start:4; background:#fde; } #calculator div:empty { background: #999; } #calculator input[data-ekr="ekr"] {grid-column-start:1; grid-column-end:5; height:100%; text-align:right; margin:0; border: 2px solid #fff; box-sizing: border-box; padding: 0; background:#fafafa; box-shadow:none; }
JAVASCRIPT
(function() { "use strict"; let main = document.getElementsByClassName("wrap")[0]; let nav = document.getElementById("nav"); let menu = document.getElementById("menu"); document.addEventListener("click", function(e) { if (e.target.id === "menu") { nav.classList.toggle("hid"); menu.classList.toggle("exp"); } else { nav.classList.add("hid"); menu.classList.remove("exp"); let link = e.target.getAttribute("href"); if (link.indexOf("#") !== -1) { e.preventDefault(); let pos = document.getElementById(link.substr(1)).offsetTop; main.scrollTop = pos - 72; } } }); })();
Expand for more options Login