Bootstrap 4:布局无法在浏览器中正确呈现
Bootstrap 4: Layout does not render properly in browser
我用 harp.js 创建了基本的静态网站项目。项目确实编译成功,没有错误,我已经为 bootstrap 添加了必需的文件和依赖项 4.Problem 是我的模板布局没有正确呈现。
这是我的布局html。
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<title></title>
</head>
<body>
<%- partial("partial/_header") %>
<%- yield %>
<%- partial("partial/_footer") %>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
crossorigin="anonymous"></script>
<script src="/js/bootstrap.min.js"></script>
</body>
_header 局部视图html
<nav class="navbar navbar-light bg-faded">
<a class="navbar-brand" href="#">Learning Bootstrap 4</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>
我在每个浏览器中得到相同的输出。
JsFiddle for problem
谁能指出我做错了什么?
您错过了 navbar-expand
导航元素。检查更新后的 fiddle:
https://jsfiddle.net/cjhnsouf/2/
<nav class="navbar navbar-expand navbar-light bg-faded">
<a class="navbar-brand" href="#">Learning Bootstrap 4</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>
我用 harp.js 创建了基本的静态网站项目。项目确实编译成功,没有错误,我已经为 bootstrap 添加了必需的文件和依赖项 4.Problem 是我的模板布局没有正确呈现。
这是我的布局html。
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<title></title>
</head>
<body>
<%- partial("partial/_header") %>
<%- yield %>
<%- partial("partial/_footer") %>
<script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
crossorigin="anonymous"></script>
<script src="/js/bootstrap.min.js"></script>
</body>
_header 局部视图html
<nav class="navbar navbar-light bg-faded">
<a class="navbar-brand" href="#">Learning Bootstrap 4</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>
我在每个浏览器中得到相同的输出。
JsFiddle for problem 谁能指出我做错了什么?
您错过了 navbar-expand
导航元素。检查更新后的 fiddle:
https://jsfiddle.net/cjhnsouf/2/
<nav class="navbar navbar-expand navbar-light bg-faded">
<a class="navbar-brand" href="#">Learning Bootstrap 4</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>