gpt4 book ai didi

angular - Bootstrap Navbar 无法正常工作 : AngularCLI

转载 作者:太空狗 更新时间:2023-10-29 17:17:30 25 4
gpt4 key购买 nike

我将 bootstrap 包含到我的 angularcli 项目中,但是当我尝试包含导航栏时,所有元素都无法正常工作。我正在使用网站上的标准 boostrap 导航栏示例,但它看起来很奇怪:

enter image description here

我的项目有什么问题导致导航栏无法正确加载?

navbar.component.html

enter image description here

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>

.angular-cli.json

"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],

最佳答案

bootstrap 4 中存在一些已知问题,尤其是在导航栏实现中

因此你必须安装 bootstrap bootstrap@3.3.7

如果您正在使用 npm,那么最好推荐以下库

 npm install bootstrap@3.3.7 --save

npm install bootstrap@3.3.7 tether jquery --save

在 .angular-cli.json 文件中添加依赖项

"styles":[
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],

"scripts":[
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
],

使用下面的 HTML

 <nav class="navbarnavbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-togglecollapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Togglenavigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Angular5Website</a>
</div>
<div id="navbar" class="collapsenavbar-collapse">
<ul class="navnavbar-nav">
<li class="active"> <a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse-->
</div>
</nav>

关于angular - Bootstrap Navbar 无法正常工作 : AngularCLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48735689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com