MaterialiseCSS NavBar和SideNav

时间:2016-10-07 03:58:14

标签: css css3 materialize

我正在创建一个sb admin 2 like page,其中有2个导航,如下所示:

enter image description here

到目前为止我所做的是:

enter image description here

如您所见,侧面导航在顶部栏处延伸。到目前为止我的代码是:

<!DOCTYPE html>
<html>
  <head>
    <!--Import Google Icon Font-->
    <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!--Import materialize.css-->
    <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

    <!--Let browser know website is optimized for mobile-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  </head>

  <body>

<div class="navbar-fixed">

<!-- Dropdown Structure -->
<ul id="dropdown1" class="dropdown-content">
  <li><a href="#!">User Profile</a></li>
  <li><a href="#!">Settings</a></li>
  <li class="divider"></li>
  <li><a href="#!">Logout</a></li>
</ul>
<nav class="light-blue lighten-1" role="navigation">
  <div class="nav-wrapper container">
    <a href="#!" class="brand-logo">Point of Sale</a>
    <ul class="right hide-on-med-and-down">
      <!-- Dropdown Trigger -->
      <li><a class="dropdown-button" href="#!" data-activates="dropdown1">Profile<i class="material-icons right">arrow_drop_down</i></a></li>
    </ul>
  </div>
</nav>


</div>

<ul id="slide-out" class="side-nav fixed">
  <li><a href="#!">First Sidebar Link</a></li>
  <li><a href="#!">Second Sidebar Link</a></li>
</ul>

    <!--Import jQuery before materialize.js-->
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/materialize.min.js"></script>
    <script>
      (function($){
        $(function(){

          $('.button-collapse').sideNav();

        }); // end of document ready
      })(jQuery); // end of jQuery name space
    </script>
  </body>
</html>

我想要实现的目标是:

enter image description here

这可能吗?

5 个答案:

答案 0 :(得分:9)

As the Side Nav documentations says:

您必须按侧边菜单的宽度偏移内容。 所以这样做

<style type="text/css">
.wrapper {
    padding-left: 300px;
}
</style>

并将您的代码包装在包装器div

<div class="wrapper">

    <div class="">
        <!-- Dropdown Structure -->
        <ul id="dropdown1" class="dropdown-content">
            <li><a href="#!">User Profile</a></li>
            <li><a href="#!">Settings</a></li>
            <li class="divider"></li>
            <li><a href="#!">Logout</a></li>
        </ul>

        <nav class="light-blue lighten-1" role="navigation">
            <div class="nav-wrapper container">
                <a href="#!" class="brand-logo">Point of Sale</a>
                <ul class="right hide-on-med-and-down">
                    <!-- Dropdown Trigger -->
                    <li><a class="dropdown-button" href="#!" data-activates="dropdown1">Profile<i class="material-icons right">arrow_drop_down</i></a></li>
                </ul>
            </div>
        </nav>
    </div>

</div>

<ul id="slide-out" class="side-nav fixed">
    <li><a href="#!">First Sidebar Link</a></li>
    <li><a href="#!">Second Sidebar Link</a></li>
</ul>

答案 1 :(得分:2)

你应该尝试:

draw(_:)

并将您的代码包装在标题中并放在一边:

<style type="text/css">
.side-nav{
    top: 65px;
    width: 250px;
}
</style>

答案 2 :(得分:0)

MaterialiseCSS建议他自己修改:

header, main, footer {
  padding-left: 300px;
}

@media only screen and (max-width : 992px) {
  header, main, footer {
    padding-left: 0;
  }
}

参考here

答案 3 :(得分:0)

有时候,当Nav溢出超出其包装器的宽度(在我的情况下为header标签)时,我遇到了一些问题,所以我使用了此方法,而不是MaterializeCSS建议的方法:

注意:虽然在无礼。

header, main, footer {
    margin-left: 300px;

    nav {
        left: 300px;
        right: 0;
        width: auto;
    }

    @media only screen and (max-width : 992px) {
        margin-left: 0;

        nav {
            left: 0;
            right: 0;
            width: auto;
        }
    }
}

答案 4 :(得分:0)

这是我的解决方法,以避免与顶部导航栏重叠,并隐藏在中小型屏幕上

添加:

<ul class="sidenav sidenav-fixed invesible-top" id="mobile-nav">

也可选,使其在小屏幕上再次显示在顶部:

<li class="hide-on-large-only">

样式:

  @media only screen and (min-width : 992px) {
  .invesible-top {
    top: 65px;
  }
}

enter image description here

enter image description here