html - 如何让输入在两边展开?
问题描述
我有一个带有下面 css 的输入栏。每次选择它时,它都应该扩展。但是,它只向左侧扩展,而不向右侧扩展。(我希望它在右侧展开)这可能是重复的,所以如果是,请将其标记为一个。但是,我只是找不到任何告诉我如何做到这一点的东西?
html:
<input placeholder = "search something up"id = "searchbar" name = "search">
CSS:
#searchbar{
margin-left: 10px;
background: #FFF;
padding: 1px 1px 1px 5px;
position: relative; top: 0; left: 0;
width: 178px;
height: 21px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#searchbar:focus{
width: 100%;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
top: 0;
right: 100%;
}
解决方案
Wrap search input
with div and define text-align:center
on wrapped div.
Follow below snippet:
.input-wrap{
text-align: center;
}
#searchbar{
background: #FFF;
padding: 1px 1px 1px 5px;
position: relative; top: 0; left: 0;
width: 178px;
height: 21px;
outline: none;
border: 1px solid #CCCCCC;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
text-align: center;
}
#searchbar:focus{
width: 100%;
width: 300px;
}
<div class="input-wrap">
<input type="text" name="search" id="searchbar" placeholder="Search">
</div>
推荐阅读
- r - 根据预定义的列集从另一个数据框中填充值
- python - Python:无法将整数转换为字符串 JSON 的值
- node.js - 来自 AWS Lambda 的 Oauth2 请求令牌
- android - 进入/退出地理围栏时是否可以从后台开始播放音频?
- asp.net - Asp.net 在 Chrome 上显示 Pdf - 错误 ERR_HTTP2_PROTOCOL_ERROR
- pandas-groupby - Dask Dataframe groupby 和聚合列
- python - 如何在不使用 tkinter 打开控制台窗口的情况下运行 Python 脚本?
- python - 尝试在 on_message [discord.py] 中记录服务器聊天信息时出错
- c++ - 运行时的 C++ regex_error 消息
- amazon-web-services - DynamoDB API BatchWriteItem 是否会始终按照 RequestItems 中的 PutRequests 顺序写入表?