引导按钮未正确显示

Posted

技术标签:

【中文标题】引导按钮未正确显示【英文标题】:Bootstrap button doesn't appear correctly 【发布时间】:2021-03-07 04:16:10 【问题描述】:

我的按钮目前是这样的:

正如你们从上面的图片中看到的那样。按钮后面有一些奇怪的东西。我该如何解决这个问题?

我正在使用 Django 和引导程序做一个迷你项目。提前致谢!

这是我的 html 文件。

base.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

    <!-- Nav Bar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <li class="nav-item active">
              <a class="nav-link" href="#">TimeSheet <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Leave</a>
            </li>
            <li class="nav-item">
              <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
            </li>
          </ul>
        </div>
        <div class="navbar-nav">
          <a class="nav-item nav-link" href="#">Login</a>
          <a class="nav-item nav-link" href="#">Register</a>
        </div>
      </nav>

    % if title %
        <title>WorkTime -  title </title>
    % else %
        <title>WorkTime</title>
    % endif %
</head>
<body>
    <div class="container">
        % block content %% endblock content %
    </div>


    <!-- JS, Popper.js, and jQuery -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>

登录.html

% extends "base.html" %
% load crispy_forms_tags % 

% block content %
<form method="post" style="margin: 0 auto; width: 250px;">
    % csrf_token %
     form|crispy 
    <div  class="text-center"> 
        <button type="submit" class="btn btn-primary center-block">Login<button></button>
    </div>
</form>
% endblock content %

【问题讨论】:

【参考方案1】:

按钮的结束标签有问题。

<button type="submit" class="btn btn-primary center-block">Login<button></button>

登录文本之后删除&lt;button&gt;,因此按钮的最终HTML应该是

<button type="submit" class="btn btn-primary center-block">Login</button>

【讨论】:

天哪!我怎么没看到这个。非常感谢!

以上是关于引导按钮未正确显示的主要内容,如果未能解决你的问题,请参考以下文章

引导面板边框未正确显示

引导列在 Firefox 中未正确显示

引导导航选项卡未加载正确的页面

引导缩略图未正确对齐

引导样式未正确应用于应用程序中的所有元素

jquery 事件按钮显示正确的响应,但视图未在 django 中正确呈现