简体   繁体   English

某些Bootstrap 4类在我的Angular 8项目中不起作用

[英]Some Bootstrap 4 classes don't work in my Angular 8 project

I am creating a header where the elements are supposed to be next to each other, but just one element appears in the browser and the others don't, and I wrote the code for them. 我正在创建一个标头,其中的元素应该彼此相邻,但是浏览器中仅出现一个元素,而其他元素则不出现,我为它们编写了代码。

I came to the conclusion that the problem is the bootstrap classes I am using because when I inspected the elements in the browser, they appeared gray, like this: 我得出的结论是问题是我正在使用的引导程序类,因为当我检查浏览器中的元素时,它们显示为灰色,如下所示: 像这样 I am using Bootstrap 4, my browser is Firefox and I am not an expert in Angular, so please be considerate. 我正在使用Bootstrap 4,我的浏览器是Firefox,但我不是Angular的专家,所以请体谅。

This is my HTML code 这是我的HTML代码

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
        <a href="#" class="navbar-brand">Recipe Book</a>
    </div>

    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            <li><a href="#">Recipes</a></li>
            <li><a href="#">Shopping List</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" role="button">Manage</a>
                <ul class="dropdown-menu">
                    <li><a href="#">Save Data</a></li>
                    <li><a href="#">Fetch Data</a></li>
                </ul>
            </li>
        </ul>
    </div>
  </div>
</nav>

And I added Bootstrap by installing it with npm and then adding this in the angular.json file 我通过使用npm安装它来添加Bootstrap,然后将其添加到angular.json文件中

"styles": [
  "src/styles.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/bootstrap/dist/js/bootstrap.min.js"
]

Ok, so I fixed whatever was going on in my project's header. 好的,所以我修复了项目标头中发生的一切。 So, it turned out I didn't need to use these classes: navbar-default, navbar-header, collapse, navbar-collapse, and nav. 因此,事实证明,我不需要使用以下类:navbar-default,navbar-header,collapse,navbar-collapse和nav。 Instead, i added these classes: navbar-expand-sm, bg-light, navbar-light, nav-item, nav-link. 相反,我添加了以下类:navbar-expand-sm,bg-light,navbar-light,nav-item,nav-link。 The code turned out like this: 代码原来是这样的:

<nav class="navbar navbar-expand-sm bg-light navbar-light">
  <div class="container-fluid">

    <a href="#" class="navbar-brand">Recipe Book</a>

    <ul class="navbar-nav">
        <li class="nav-item"><a class="nav-link" href="#">Recipes</a></li>
        <li class="nav-item"><a class="nav-link" href="#">Shopping List</a></li>
    </ul>

    <ul class="navbar-nav navbar-right">
        <li class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" role="button">Manage</a>
            <ul class="dropdown-menu">
                <li class="nav-item"><a href="#">Save Data</a></li>
                <li class="nav-item"><a href="#">Fetch Data</a></li>
            </ul>
        </li>
    </ul>

  </div>
</nav>

I read the usage of the bootstrap navbar by w3schools This how the project looks so far, the header looks almost exactly like the instructor's, but I am satisfied with it. 我阅读了w3schools的bootstrap navbar的用法到目前为止,该项目的样子,标题看起来几乎与教师的样子完全一样,但我对此感到满意。 Sorry for the trouble, and thanks for the insight. 很抱歉给您带来麻烦,感谢您的见解。 最后结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM