gpt4 book ai didi

html - 导航标题中带有图标的 Bootstrap 搜索字段未正确显示

转载 作者:太空宇宙 更新时间:2023-11-04 10:10:18 25 4
gpt4 key购买 nike

我正在尝试将带有标题的搜索框添加到我的 Bootstrap 3 模板。我使用的模板是从 Bootstrap 主题页面购买的并且是 Light UI Dashboard主题。

我在 Stack Overflow 上找到了这个答案,但它没有正确显示(它在 Chrome 和 Edge 中都显示不正确)。

How to add a search box with icon to the navbar in Bootstrap 3?

我修改了我的代码以在我的标题中包含搜索框,但是字形不显示并且搜索框未对齐。这是屏幕截图。

enter image description here

我的代码如下:

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
<form runat="server">
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Crown Ent.</a>
</div>
<div id="navbar" class="navbar-collapse collapse">

<ul class="nav navbar-nav navbar-left">
<li role="presentation" id="dashboard"><a href="./">Dashboard</a></li>
<li role="presentation" id="workorders"><a href="workorders.aspx">Work Orders</a></li>
<li role="presentation" id="invoices"><a href="invoices.aspx">Invoices</a></li>
<li role="presentation" id="accounts"><a href="accounts.aspx">Accounts</a></li>
<li role="presentation" id="people"><a href="people.aspx">People</a></li>
</ul>

<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/admin">Settings</a></li>
<li><a runat="server" href="~/admin">Help</a></li>
</ul>

<form class="navbar-form" style="padding-top:5px;">
<div class="form-group" style="display:inline;margin-top:5px;">
<div class="input-group" style="display:table;">
<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
<input class="form-control" name="search" placeholder="Search Here" id="crown-search" autocomplete="off" autofocus="autofocus" type="text">
</div>
</div>
</form>

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

我看不出代码有什么问题。调整 CSS 边距以试图固定位置也是无效的。

最佳答案

更新。我删除了第一行 <form runat="server">并使用代码

  <form class="navbar-form" role="search">
<div class="form-group">
<div class="input-group">

代替

  <form class="navbar-form" style="padding-top:5px;">
<div class="form-group" style="display:inline;margin-top:5px;">
<div class="input-group" style="display:table;">

我还添加了一些 CSS 来使表单变宽。请检查结果。

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');

#navbar .navbar-form {
overflow: hidden;
}
#navbar .form-group,
#navbar .input-group {
width: 100%;
}
#navbar .input-group-addon {
width: 39px;
}
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Crown Ent.</a>
</div>
<div id="navbar" class="navbar-collapse collapse">

<ul class="nav navbar-nav navbar-left">
<li role="presentation" id="dashboard"><a href="./">Dashboard</a></li>
<li role="presentation" id="workorders"><a href="workorders.aspx">Work Orders</a></li>
<li role="presentation" id="invoices"><a href="invoices.aspx">Invoices</a></li>
<li role="presentation" id="accounts"><a href="accounts.aspx">Accounts</a></li>
<li role="presentation" id="people"><a href="people.aspx">People</a></li>
</ul>

<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/admin">Settings</a></li>
<li><a runat="server" href="~/admin">Help</a></li>
</ul>

<form class="navbar-form" role="search">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
<input class="form-control" name="search" placeholder="Search Here" id="crown-search" autocomplete="off" autofocus="autofocus" type="text">
</div>
</div>
</form>

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

关于html - 导航标题中带有图标的 Bootstrap 搜索字段未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37665535/

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