Bootstrap响应式导航

时间:2017-05-27 09:35:35

标签: html css twitter-bootstrap responsive-design navbar

我希望使用Twitter bootstrap

实现这样的html布局

我希望它在桌面和移动两种模式下都具有响应能力,例如下面的示例

桌面模式

desktop

移动模式

MOBILE

这是我到目前为止尝试的代码



<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header>
    <div id="navbar-main">
        <!-- Fixed navbar -->
        <div class="navbar navbar-inverse navbar-fixed-top navbar-custom">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">
                        <img src="https://i.stack.imgur.com/G2Xgp.png">
                    </a>
                </div>
                <div class="navbar-collapse collapse navbar-right">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href='#'>FR</a></li>
                        <li><a href='#'>EN</a></li>
                        <li><a href='#'>KR</a></li>
                    </ul>
                </div>
                <!--/.nav-collapse -->
                <ul class="nav navbar-nav navbar-right">
                    <ul class="nav navbar-nav navbar-right" role="menu">
                        <li><a href='#'>HOME</a></li>
                        <li><a href='#'>ABOUT US</a></li>
                        <li><a href='#'>TEST</a></li>
                        <li><a href='#'>TEST</a></li>
                        <li><a href='#'>TEST</a></li>
                        <li><a href='#'>TEST</a></li>
                    </ul>
                </ul>
            </div>
        </div>
    </div>
</header>
</body>
</html>
&#13;
&#13;
&#13;

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

试试这个......!可能这会帮助你..!我已经添加了一些自定义css,看看..!

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
  .navbar{
	  background: #540d1f;
    padding: 25px 0;
  }
  .container-fluid{
  	background:#bcaa60 !important;
  }
  .navbar-inverse .navbar-nav > li > a {
    color: #fff;
}
    .navbar-brand{
    position: relative;
    top: -45px;
}
@media only screen and (max-width: 767px) {
    .navbar-brand{
    position: relative;
    top: -45px;
    left:30%;
}
}
    </style>
</head>
<body>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
       <a class="navbar-brand" href="#">
                        <img width="90px" src="https://i.stack.imgur.com/G2Xgp.png">
                    </a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li class="dropdown">
          <a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Page 1-1</a></li>
            <li><a href="#">Page 1-2</a></li>
            <li><a href="#">Page 1-3</a></li>
          </ul>
        </li>
        <li><a href="#">Page 2</a></li>
        <li><a href="#">Page 3</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>
  
<div class="container">
  <h3>Collapsible Navbar</h3>
  <p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
  <p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>

</body>
</html>

enter image description here