如何构建类似于物化水平FAB的菜单?

时间:2016-09-05 21:05:10

标签: html css twitter-bootstrap

我开始使用Materialize访问我的网站,但现在我想迁移到Bootstrap。

我将使用Starter模板引导程序作为构建我的网站的基础。

使用HTML和CSS设置类似菜单的最简单方法是什么,并保持相同的效果?

1 个答案:

答案 0 :(得分:0)

您可以在Bootstrap (you can find it on Github)

中使用Material design

您可以在纯CSS中创建菜单,以下是一个示例:



body {
    margin: 0;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 25%;
    background-color: #f1f1f1;
    position: fixed;
    height: 100%;
    overflow: auto;
}

li a {
    display: block;
    color: #000;
    padding: 8px 16px;
    text-decoration: none;
}

li a.active {
    background-color: #4CAF50;
    color: white;
}

li a:hover:not(.active) {
    background-color: #555;
    color: white;
}

<body>

<ul>
  <li><a class="active" href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>

<div style="margin-left:25%;padding:1px 16px;height:1000px;">
  <h2>Fixed Full-height Side Nav</h2>
  <h3>Try to scroll this area, and see how the sidenav sticks to the page</h3>
  <p>Notice that this div element has a left margin of 25%. This is because the side navigation is set to 25% width. If you remove the margin, the sidenav will overlay/sit on top of this div.</p>
  <p>Also notice that we have set overflow:auto to sidenav. This will add a scrollbar when the sidenav is too long (for example if it has over 50 links inside of it).</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
  <p>Some text..</p>
</div>
&#13;
&#13;
&#13;

code from W3schools

您可以使用 display:none 显示隐藏的元素,您可以使用Jquery函数.toggle()来显示它。 这是一个例子:

&#13;
&#13;
$(document).ready(function(){
    $("li.show > a").click(function(){
        $("li.hide").fadeToggle();
    });
});
&#13;
body {
    margin: 0;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 25%;
    background-color: #f1f1f1;
    position: fixed;
    height: 100%;
    overflow: auto;
}

li a {
    display: block;
    color: #000;
    padding: 8px 16px;
    text-decoration: none;
}

li:nth-child(2)
{
  display: none;
  background: #4CAF50;
  padding: 10px;
}
li a:active {
    background-color: #4CAF50;
    color: white;
}

li a:hover:not(.active) {
    background-color: #555;
    color: white;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li class="show">
    <a href="#">Click me to show.</a>
  </li>
  <li class="hide">
    This is an hidden element
  </li>
</ul>
&#13;
&#13;
&#13;