gpt4 book ai didi

html - 搜索框 bootstrap 4 无法定位在导航栏的中间

转载 作者:太空宇宙 更新时间:2023-11-03 22:13:10 24 4
gpt4 key购买 nike

我试图将搜索栏放在导航栏的中间。左侧有 Logo ,右侧有菜单。我哪里出错了,我该如何解决。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">


<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<div class="container-fluid">
<a class="navbar-brand" href="{% url 'home' %}">ATG</a>
<button class="navbar-toggler" 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>

<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{% url 'home' %}">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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% if not user.is_authenticated %}
<a class="dropdown-item" href="{% url 'signup' %}">Sign up</a>
<a class="dropdown-item" href="{% url 'login' %}">Log in</a> {% else %}
<a class="dropdown-item" href="{% url 'secret' %}">Profile</a>
<a class="dropdown-item" href="{% url 'password_change' %}">Change password</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}">Log out</a> {% endif %}
</div>
</li>
</ul>
<form class="navbar-form" id="search" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<!-- <button type="submit" class="btn btn-default">Submit</button> -->
</form>
<style>
#search {
text-align: center;
}
</style>
</div>
</div>
</nav>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>

这是 fiddle 的链接

最佳答案

希望对您有所帮助。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>


<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<div class="container-fluid">
<a class="navbar-brand" href="{% url 'home' %}">ATG</a>
<button class="navbar-toggler" 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>

<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">

<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{% url 'home' %}">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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
More
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% if not user.is_authenticated %}
<a class="dropdown-item" href="{% url 'signup' %}">Sign up</a>
<a class="dropdown-item" href="{% url 'login' %}">Log in</a>
{% else %}
<a class="dropdown-item" href="{% url 'secret' %}">Profile</a>
<a class="dropdown-item" href="{% url 'password_change' %}">Change password</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'logout' %}">Log out</a>
{% endif %}
</div>
</li>
</ul>
<form class="navbar-form col-lg-4 mx-lg-auto order-lg-first mb-0" id="search" role="search">
<div class="form-group mb-0">
<input type="text" class="form-control" placeholder="Search">
</div>
<!-- <button type="submit" class="btn btn-default">Submit</button> -->
</form>

</div>
</div>
</nav>

关于html - 搜索框 bootstrap 4 无法定位在导航栏的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58245566/

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