-2

I have created a side navigation for a website, but I don't want it to overlay on top of my website. I want it to pushover the rest of the site. For example how they do it on this website. The code i have is below.


<div id="mainbox" onclick="openFunction()">&#9776; </div>
        <div id="menu" class="sidemenu">
            <a href="#">Home</a>
            <a href="#">Shop</a>
            <a href="#">About</a>
            <a href="#">Contact</a>
        <a href="#" class="closebtn" onclick="closeFunction()">&times;</a>
 </div>

<script type="text/javascript">
        function openFunction(){
            document.getElementById("menu").style.width="400px";
            document.getElementById("mainbox").style.marginLeft="400px";
 }
        function closeFunction(){
             document.getElementById("menu").style.width="0px";
             document.getElementById("mainbox").style.marginLeft="0px";
}
</script>

CSS:

#mainbox{
 position: fixed;
 font-size: 40px;
 cursor: pointer;
 transition: all .6s;
 transform: translate(3750%, -1600%);
}

.sidemenu{
 position: fixed;
 top: 0px;
 right: 0px;
 height: 100%;
 width: 0px;
 background-color: #FFEECA;
 z-index: 1;
 padding-top: 100px;
 overflow-x: hidden;
 transition: all .5s;
}

.sidemenu a{
 padding: 8px 8px 8px 64px;
 text-decoration: none;
 font-size: 20px;
 color: #222;
 display: block;
}

.sidemenu a:hover{
  color: white;
}

.sidemenu .closebtn{
 position: absolute;
 top: 0px;
 right: 25px;
 font-size: 36px;
 margin-left: 32px;
}
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Does this answer your question? https://stackoverflow.com/questions/31722839/flex-layout-with-fixed-position-no-scrolling-sidebar – Ozgur Sar Nov 07 '20 at 21:17

2 Answers2

0

laatste...

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
  font-family: "Lato", sans-serif;
}

.sidenav {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  overflow-x: hidden;
  transition: 0.5s;
  padding-top: 60px;
}

.sidenav a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 25px;
  color: #818181;
  display: block;
  transition: 0.3s;
}

.sidenav a:hover {
  color: #f1f1f1;
}

.sidenav .closebtn {
  position: absolute;
  top: 0;
  right: 25px;
  font-size: 36px;
  margin-left: 50px;
}

#main {
  transition: margin-left .5s;
  padding: 16px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}
</style>
</head>
<body>

<div id="mySidenav" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <a href="#">hey</a>
  <a href="#">alles</a>
  <a href="#">oke</a>
  <a href="#">?</a>
</div>

<div id="main">
  <h2>Sidenav Push Example</h2>
  <p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
  <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>
</div>

<script>
function openNav() {
  document.getElementById("mySidenav").style.width = "250px";
  document.getElementById("main").style.marginLeft = "250px";
}

function closeNav() {
  document.getElementById("mySidenav").style.width = "0";
  document.getElementById("main").style.marginLeft= "0";
}
</script>
   
</body>
</html> 
my profile
  • 37
  • 9
-2

here you go, i hope its the thing you wanted...lol https://codepen.io/schliflo/pen/Eawzzw

my profile
  • 37
  • 9