文本在侧面菜单上折叠关闭

时间:2018-01-02 19:27:05

标签: javascript html css

如何防止文本在侧面菜单关闭时折叠。检查代码簿,当菜单关闭时,您将看到菜单项/文本相互重叠。我已经尝试过隐藏在菜单项上的溢出但是没有用。有什么想法吗?

请参阅codepen:https://codepen.io/zepzia/pen/vpZQxz

<header>
  <div class="container-fluid">
    <div class="row">
      <nav class="navbar bg-faded fixed-top" id="slide-nav">
        <div class="nav-wrapper">
              <div class="nav-logo">

                <span class="navbar-text menu-toggle" onclick="openNav()"><i class="fa fa-bars" aria-hidden="true"></i></span>
             </div>


              <div id="mySidenav" class="sidenav">
                <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
                <br>
                <br>
                <a href="#">Home</a>
                <a href="#">This Is Link One</a>
                <a href="#">This Is Link Two</a>
                <a href="#">This Is Link Three</a>
                <a href="#">This IsLink Three</a>
                <a href="#">Link Three</a>
              </div>
       </div>

      </nav>
  </div>
</div>

    </nav>
</header>



    /* NAVIGATION */
.menu-toggle {
cursor:pointer;
float:right;
line-height: 60px;
}

.fa-bars {
  color: #fff;
  font-size: 30px;
}


.nav-wrapper {
  width: 83%;
  margin: 0 auto;
}


.navbar {
  height: 75px;
  background-color: gray;
}



/* The side navigation menu */
.sidenav {
    height: 100%; /* 100% Full-height */
    width: 0; /* 0 width - change this with JavaScript */
    position: fixed; /* Stay in place */
    z-index: 1; /* Stay on top */
    top: 0; /* Stay at the top */
    right: 0;
    background:rgba(75,156,211,0.9) url('../img/unc_pine_cb.svg') no-repeat;
    background-size: 200%;
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 60px; /* Place content 60px from the top */
    transition: 0.5s; /* 0.5 second transition effect to slide in the sidenav */
    overflow: hidden;
}

/* The navigation menu links */
.sidenav a {
    padding: 15px 8px 10px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #fff;
    display: block;
    transition: 0.3s;
}


/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
    color: #13284a;
    font-weight: 600;
}

/* Position and style the close button (top right corner) */
.sidenav .closebtn {
    position: absolute;
    top: 0;
    left: 0;
    font-size: 36px;
}




 /* Set the width of the side navigation to 250px */
function openNav() {
    document.getElementById("mySidenav").style.width = "400px";
}

/* Set the width of the side navigation to 0 */
function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
}


// FADE OUT ON SCROLL DOWN
$(window).scroll(function(){
    $(".fade-to-top").css("opacity", 1 - $(window).scrollTop() / 350);
  });

1 个答案:

答案 0 :(得分:1)

一种解决方案是更改right属性而不是宽度。因此,您可以将sidebar的开头设置为right: -400px,并在单击按钮时将其更改为right: 0px。然后在关闭菜单时反转。

请参阅我的codepen here

这样文本永远不会崩溃。