【问题标题】:How do i make my side menu push my website over?我如何让我的侧边菜单推动我的网站?
【发布时间】:2020-11-08 14:34:59
【问题描述】:

我为网站创建了侧边导航,但我不希望它覆盖在我的网站之上。我希望它推翻网站的其余部分。例如他们如何在this website 上做到这一点。我的代码如下。


<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;
}

【问题讨论】:

标签: javascript html css


【解决方案1】:

最后...

<!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> 

【讨论】:

    【解决方案2】:

    给你,我希望它是你想要的...lol https://codepen.io/schliflo/pen/Eawzzw

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 2021-05-19
    • 1970-01-01
    • 2014-08-16
    • 1970-01-01
    • 2021-10-30
    相关资源
    最近更新 更多