Bootstrap 5 导航栏中的错误

发布于 2025-01-09 02:52:56 字数 1111 浏览 1 评论 0原文

我正在开发一个简单的网络开发项目。我正在使用 Bootstrap 5,并且正在努力创建导航栏。导航栏的代码位于 header.html 中。

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">
    <img src="/Users/morgan/Documents/12_london_app_brewery/london_app_brew/88-cafe-wifi/img/free_wifi.png" alt="Free Wifi" style="width:40px;" class="rounded-pill">
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item active">
          <a class="nav-link" href="{{ url_for('home') }}">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="{{ url_for('add_cafe') }}">Add</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

我的 index.html 和 add.html 文件中有 {% include "header.html" %}

导航栏如下所示

在此处输入图像描述

请注意,照片未显示,并且“主页”和“添加”未右对齐。

I'm working on a simple web-dev project. I'm using bootstrap 5 and I'm struggling to create the navbar. The code for the navbar is in header.html.

<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">
    <img src="/Users/morgan/Documents/12_london_app_brewery/london_app_brew/88-cafe-wifi/img/free_wifi.png" alt="Free Wifi" style="width:40px;" class="rounded-pill">
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item active">
          <a class="nav-link" href="{{ url_for('home') }}">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="{{ url_for('add_cafe') }}">Add</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

I have {% include "header.html" %} in my index.html and add.html files.

The navbar looks like the following

enter image description here

Note that the photo is not displaying and "Home" and "Add" are not aligned to the right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2025-01-16 02:52:56

检查您的 Bootstrap 文件包。

如果您有 custom.scss (或任何其他名称),您在其中导入 Bootstrap 的源 Sass 文件,请检查是否错过了导航栏导入:

...
@import "~bootstrap/scss/nav";
@import "~bootstrap/scss/navbar";
...

navbar-nav 移至右侧,使用“ms-auto”代替“mr-auto”(BS 5.1);

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">



<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">
    <img src="/Users/morgan/Documents/12_london_app_brewery/london_app_brew/88-cafe-wifi/img/free_wifi.png" alt="Free Wifi" style="width:40px;" class="rounded-pill">
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <!-- to move navbar-nav use "ms-auto" -->
      <ul class="navbar-nav ms-auto">
        <li class="nav-item active">
          <a class="nav-link" href="{{ url_for('home') }}">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="{{ url_for('add_cafe') }}">Add</a>
        </li>
      </ul>
    </div>
  </div>
</nav>


我看到您的左侧有工件文本“-->”。可能你只是遇到了打开/关闭标签或注释的问题,因此你的 DOM 被破坏了。

输入图片此处描述

Check your bundle of Bootstrap file.

If you have your custom.scss (or any other name), where you importing Bootstrap’s source Sass files, check if missed navbar imports:

...
@import "~bootstrap/scss/nav";
@import "~bootstrap/scss/navbar";
...

To move navbar-nav to right side, use "ms-auto" instead of "mr-auto" (BS 5.1);

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">



<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
  <div class="container">
    <img src="/Users/morgan/Documents/12_london_app_brewery/london_app_brew/88-cafe-wifi/img/free_wifi.png" alt="Free Wifi" style="width:40px;" class="rounded-pill">
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <!-- to move navbar-nav use "ms-auto" -->
      <ul class="navbar-nav ms-auto">
        <li class="nav-item active">
          <a class="nav-link" href="{{ url_for('home') }}">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="{{ url_for('add_cafe') }}">Add</a>
        </li>
      </ul>
    </div>
  </div>
</nav>


I see you have artifact text on the left "-->". May be you just have issues with open/closing tags or comments and because of that your DOM is broken.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文