如您所见,图标与输入框不完全对齐:
我只想让图标与输入框对齐而不能使用position absolute
,因为输入框会溢出其他内容。
我能做些什么来做对吗?
header.toplogo {
overflow: hidden;
margin-top: 10px;
position: relative;
display: grid;
grid-template-columns: 170px 1fr 100px
}
header.toplogo div {
width: 100%;
margin: 0 auto;
line-height: 150px;
vertical-align: middle;
grid-column: 2/3;
}
header.toplogo div i {
background-color: #ff3232;
padding: 10px 12px 14px 12px;
border-radius: 5px 0 0 5px;
color: white;
font-size: 18px;
transition: 0.6s;
}

<header class="toplogo" style="direction:ltr">
<div><i class="fa fa-search"></i><input type="text" name="search" placeholder="Search ..."></div>
</header>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
&#13;
答案 0 :(得分:0)
这是我的解决方案
将此添加到ur css
input {
box-sizing: border-box;
height: 42px;
}
将vertical align:middle
添加到i
代码
header.toplogo {
overflow: hidden;
margin-top: 10px;
position: relative;
display: grid;
grid-template-columns: 170px 1fr 100px
}
header.toplogo div {
width: 100%;
margin: 0 auto;
line-height: 150px;
vertical-align: middle;
grid-column: 2/3;
}
header.toplogo div i {
background-color: #ff3232;
padding: 10px 12px 14px 12px;
border-radius: 5px 0 0 5px;
color: white;
font-size: 18px;
transition: 0.6s;
vertical-align: middle;
}
input {
box-sizing: border-box;
height: 42px;
}
&#13;
<link href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" rel="stylesheet" />
<header class="toplogo" style="direction:ltr">
<div><i class="fas fa-search"></i><input type="text" name="search" placeholder="Search ..."></div>
</header>
&#13;