如何只显示菜单的汉堡包图标而不是背景栏,并在顶部中间显示菜单选项?

How to just show hamburger icon of menu not the background bar and have the menu options in top-middle?

我有一个如下所示的菜单,但我遇到了一些问题。例如,在全尺寸屏幕中,菜单选项不在它所在部分的中间顶部。另一个问题是,当屏幕位于单元格 phone 中时,我不知道如何删除黑条尺寸和汉堡包图标可见。

Demo

   <!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
    href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<script
    src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>


</head>

<body>

<header>
    <div class="container-fluid">
        <div class="row">

            <div class="container">
                <div class="row">
                    <div class=" col-md-12 col-sm-12 col-xs-12 search-container">
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>


                    </div>
                </div>
            </div>
            <nav class="navbar-inverse navbar-static-top" role="navigation">

    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#portfolio">Portfolio</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </div>
    </div>
</nav>  


        </div>
    </div>
</header>
</body>
</html>

对于中间对齐菜单使用 css 就像

.navbar-inverse .navbar-nav > li > a:hover, .navbar-inverse .navbar-nav > li > a:focus, .navbar-inverse .navbar-nav > li > a{
  padding: 10px !important;
}
.navbar-inverse {
  position: absolute;
  top:50%;
  width:100%;
  left: 0
}

如果要删除背景色,请使用 css

        @media only screen and (max-width : 480px) {
.navbar-inverse{
  background: transparent;
}
  .navbar-inverse .navbar-toggle:hover, .navbar-inverse .navbar-toggle:focus{
    background: transparent;
  }
  .navbar-inverse .navbar-toggle{
    border: 0px none;
  }
    .navbar-inverse .navbar-toggle .icon-bar {
    background: #666;
}
}

此媒体查询仅适用于移动屏幕

不确定中间顶部,但其他部分应该可以。

.navbar-inverse .navbar-nav > li > a:hover, .navbar-inverse .navbar-nav > li > a:focus, .navbar-inverse .navbar-nav > li > a{
  padding: 10px !important;
} 

.navbar-header {
    background-color: white; //or inherit whatever you like
}


.navbar-toggle.collapsed {
    background-color: black;
}

Completed Demo by Niklas Brunberg

希望这对您有所帮助

我让菜单项在桌面上显示时居中,然后在最小化到单元格时 phone 大小背景栏变为白色,然后汉堡包图标将变为黑色

link 到 plunker

Demo

我已经在 bootstrap 方面做了很多工作,所以我建议您用自己的 类 扩展他们的原始风格,而不是覆盖所有内容。 我的建议基于 flexbox 并使用自定义 类 作为使事情按需要工作的方式。

查看一下,希望对您有所帮助。 (:

JSFiddle Link: https://jsfiddle.net/ce7L0nez/

CSS:

.center-md-content {
    display: flex!important;
    align-items: center;
    justify-content: center;
}
.center-md-content .navbar-nav {
    float: none;
}

@media only screen and (max-width : 768px) {
    .sm-no-background {
        background-color: transparent;
    }
    .sm-no-background .navbar-header {
        margin-left: auto;
    }
    .sm-no-background .navbar-toggle .icon-bar {
        background-color: #333;
    }
    .sm-no-background .navbar-toggle {
        border: 0;
    }
    .sm-no-background .navbar-toggle:hover .icon-bar {
        background-color: #FFF;
    }
}

HTML:

  <header>
    <div class="container-fluid">
        <div class="row">
            <div class="container">
                <div class="row">
                    <div class=" col-md-12 col-sm-12 col-xs-12 search-container">
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                        <p>THIS IS A TEST</p>
                    </div>
                </div>
            </div>
            <nav class="navbar-inverse navbar-static-top sm-no-background" role="navigation">
                <div class="container center-md-content">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>

                        </button>
                    </div>
                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li><a href="#">Home</a>

                            </li>
                            <li><a href="#">About</a>

                            </li>
                            <li><a href="#portfolio">Portfolio</a>

                            </li>
                            <li><a href="#">Contact</a>

                            </li>
                        </ul>
                    </div>
                </div>
            </nav>