bootstrap navbar垂直显示而不是水平显示

时间:2017-05-23 13:46:23

标签: html css bootstrap-4 twitter-bootstrap-4

在我的页面上navbar垂直显示而不是水平显示。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>
            Home | Bootstrap
        </title>
        <link rel="stylesheet" href="css/bootstrap.min.css">
    </head>
    <body>
        <nav class="navbar navbar-light bg-faded">
            <a class="navbar-brand" href="#">My bootstrap application</a>
            <ul class="nav navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link" href="index.html">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="about.html">About</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="contact.html">Contact</a>
                </li>
            </ul>
            <form class="form-inline pull-xs-right">
                <input class="form-control" type="text" placeholder="Search" />
                <button class="btn btn-primary" type="submit">Search</button>
            </form>
        </nav>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h1>hello world!</h1>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    Bootstrap 4
                </div>
            </div>
        </div>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>

Sample

为什么?根据文档,默认情况下它应该是水平的。

1 个答案:

答案 0 :(得分:2)

navbar-toggleable-md元素中添加nav类,使其在md视图中水平显示:

See this fiddle

Docs

原始答案适用于Bootstrap 4 alpha。对于 Bootstrap 4.0 + navbar-toggleable-*类已更改为navbar-expand-*。使用其中一个navbar-expand-*类来保持Navbar水平。