如何解决导航栏中带有引导的Bootstrap搜索栏
所以我有两个问题:
#searchbar-top-nav:focus {
width: 450px;
-webkit-transition: width 0.5s ease-in-out;
-moz-transition:width 0.5s ease-in-out;
-o-transition: width 0.5s ease-in-out;
transition: width 0.5s ease-in-out;
float: left;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="mb-1 shadow-sm">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="/">BRAND</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul id="navbar-collapse-ul" class="navbar-nav mr-auto">
<li class="nav-item active-search-blue">
<input id="searchbar-top-nav" class="form-control" type="text" placeholder="Search" aria-label="Search">
</li>
<li class="nav-item">
<a id="sign-up-link" class="nav-link" href="/accounts/signup/">Sign Up</a>
</li>
<li class="nav-item">
<a id="log-in-link" class="nav-link" href="/accounts/login/?next=/">Sign In</a>
</li>
</ul>
</div>
</nav>
</div>
<script src="http://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvcwpIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
我尝试了一些像这样的CSS选择器:
#searchbar-top-nav:not(.collapsed):focus {
width: 100%;
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none;
}
https://jsfiddle.net/acwpython/gd8t04nh/ 任何帮助都会很棒!
解决方法
首先将边距添加到搜索栏以正确对齐,将引导程序类#file Makefile
include ${MY_RUN_DIR}/common.mk
run:
# do something,such as
@echo my version is $$MY_VERSION
添加到搜索栏mt-lg-0 mt-md-2
。
li
还添加过渡
<li class="nav-item active-search-blue mt-lg-0 mt-2">
.navbar-collapse{
transition: 0s ease-in-out !important;
}
#searchbar-top-nav:focus {
width: 450px;
-webkit-transition: width 0.5s ease-in-out;
-moz-transition:width 0.5s ease-in-out;
-o-transition: width 0.5s ease-in-out;
transition: width 0.5s ease-in-out;
float: left;
}
.navbar-collapse{
transition: 0s ease-in-out !important;
}
,
简单,只需添加最小宽度:100%;到您的.form-control类,并 就是这样。
.form-control {最小宽度:100%;}
,
.form-control{min-width:100%;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="mb-1 shadow-sm">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="/">BRAND</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul id="navbar-collapse-ul" class="navbar-nav mr-auto">
<li class="nav-item active-search-blue">
<input id="searchbar-top-nav" class="form-control" type="text" placeholder="Search" aria-label="Search">
</li>
<li class="nav-item">
<a id="sign-up-link" class="nav-link" href="/accounts/signup/">Sign Up</a>
</li>
<li class="nav-item">
<a id="log-in-link" class="nav-link" href="/accounts/login/?next=/">Sign In</a>
</li>
</ul>
</div>
</nav>
</div>
<script src="http://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。