html - 无法让我的搜索图标位于搜索文本区域旁边
问题描述
我敢肯定这很简单,但我已经筋疲力尽地试图弄清楚了。我尝试了很多不同的变体,只是无法让搜索按钮与搜索栏位于同一行。我无计可施。为什么他们在两条不同的线路上???
.container-inner {
width: 100%;
position: relative;
display: flex;
}
#search-bar {
width: 90%;
border: 2px solid #fff200;
border-right: none;
padding: 5px;
height: 40px;
border-radius: 5px 0 0 5px;
outline: none;
color: #9DBFAF;
}
#search-bar:focus{
color: black;
}
.searchButton {
width: 40px;
height: 36px;
border: 2px solid #fff200;
background: grey;
text-align: center;
color: black;
border-radius: 0 5px 5px 0;
cursor: pointer;
font-size: 20px;
}
.searchButton:hover{
background: darkslategrey
}
.container {
width: 50%;
position: absolute;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<div class="container-inner">
<form id="search-form">
<div class="input-group input-group-lg">
<input id="search-bar" class="form-control search-bar" placeholder="Search for a song...">
<button type="submit" class="searchButton">
<i class="fa fa-search" aria-hidden="true"></i>
</div>
</div>
</form>
</div>
解决方案
您应该更改添加一个带有 display 的包装器flex
,将属性 flex 设置#search-bar
为并从以下示例中1
删除高度。#search-bar
.container-inner {
width: 100%;
position: relative;
display: flex;
}
#search-bar {
border: 2px solid #fff200;
border-right: none;
padding: 5px;
border-radius: 5px 0 0 5px;
outline: none;
color: #9DBFAF;
flex: 1;
}
#search-bar:focus {
color: black;
}
.searchButton {
width: 40px;
height: 36px;
border: 2px solid #fff200;
background: grey;
text-align: center;
color: black;
border-radius: 0 5px 5px 0;
cursor: pointer;
font-size: 20px;
}
.searchButton:hover {
background: darkslategrey
}
.container {
width: 50%;
position: absolute;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);
}
.input-wrapper {
display: flex;
}
<div class="container">
<div class="container-inner">
<form id="search-form">
<div class="input-group input-group-lg input-wrapper">
<input id="search-bar" class="form-control search-bar" placeholder="Search for a song...">
<button type="submit" class="searchButton">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
</div>
</form>
</div>
</div>
推荐阅读
- java - java - 如何拥有资源文件
- php - ftp_get():下载大文件时打开BINARY模式数据连接
- javascript - 将随机值从数组复制到对象无法获得稳定的结果
- spring - Spring拦截器拦截较晚
- java - 点击通知后如何正确地将新活动添加到堆栈顶部
- express - UnauthorizedError:身份验证时出现 jwt 格式错误的错误
- typeorm - 如何从 typeorm 修复“TypeError:relatedEntities.forEach 不是函数”
- zend-framework - [完成]我需要从 Zend Framework 1 开始,但我有点做不到
- typescript - 我可以在 Typescript 中将此数组转换为 List 或 Set 吗?
- django - request.user 无法正常工作,无法分配给隐藏模型字段