【发布时间】:2019-03-09 07:22:11
【问题描述】:
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 25px;
font-size: 16px;
background-color: white;
padding: 5px 0px 5px 10px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
right: 10px;
position: fixed;
}
input[type=text]:focus {
width: 96%;
}
.navbar {
background: #fff;
border: none;
border-bottom-left-radius: 25px;
border-bottom-right-radius: 25px;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light fixed-top" style="background-color:#6d7fcc;">
<div class="container-fluid">
<button type="button" id="sidebarCollapse" class="btn btn-info">
<i class="fas fa-align-left"></i>
<span>Table Of Contents</span>
</button>
<input type="text" name="search" placeholder="Search...">
</div>
</nav>
有人可以帮帮我吗?如何通过转换(从右到左)缩小按钮,直到输入成为焦点时它消失。当焦点不在输入上时,随着过渡(从左到右)增长。谢谢。
【问题讨论】:
-
And btw, how can I remove the suggestions of previous values on this input.查看输入上的autocomplete属性,如果您搜索它,那里有很多信息 -
哦,谢谢。我会删除那个额外的问题。 :)
-
如果您希望您的“目录”按钮响应用户关注搜索栏(这是我理解您的问题的方式),那么您需要 Javascript。例如,您可以将“.addEventListener()”添加到搜索栏,并让回调函数触发按钮的动画。
-
嗨@Jensei,我已经像这样尝试过
$('input[name="search"]').on('click', function(){ $('#sidebarCollapse').css('width',0); });和css#sidebarCollapse{ -webkit-transition: width 0.4s ease-in-out; transition: width 0.4s ease-in-out; },但仍然没有运气。我只是 html、css 和 jquery 的新手