我目前有这个输入和div彼此相邻:
正如您所看到的,输入的边框比包含搜索图标的div要薄得多。这是代码:
HTML
.location_input {
width: 150px;
height: 20px;
float: left;
padding-left: 3px;
display: inline-block;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
padding: 3px 15px;
font: normal 16px/normal"Open Sans", sans-serif;
-o-text-overflow: clip;
text-overflow: clip;
-webkit-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
-moz-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
-o-transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
transition: all 200ms cubic-bezier(0.42, 0, 0.58, 1);
margin-left: 6px;
position: relative;
top: 42%;
transform: translateY(-42%);
}
.update_location_wrapper {
float: left;
height: 30px;
width: 30px;
position: relative;
border-left: none;
display: inline-block;
background-color: none;
border-top: 1px solid #bbb;
border-right: 1px solid #bbb;
border-bottom: 1px solid #bbb;
position: relative;
top: 42%;
transform: translateY(-42%);
}
<input type='text' class='location_input' placeholder='Enter a location' id='location_input'>
<div class='update_location_wrapper'>
<div class='update_location_text'>
<img src="//i.imgur.com/0p5bSIO.png" alt="Search" height="20" width="20">
</div>
</div>
有没有办法让div的边框与输入边框匹配?
答案 0 :(得分:2)
由于输入边框在不同的浏览器上看起来有些不同,您可以添加带边框的包装,或者您可以这样做,在此处增加输入的右边距并在其中移动搜索按钮。
.location_input {
width: 150px;
height: 20px;
float: left;
padding-left: 3px;
display: inline-block;
box-sizing: content-box;
padding: 3px 35px 3px 15px;
font: normal 16px/normal "Open Sans", sans-serif;
margin-left: 6px;
position: relative;
}
.update_location_wrapper{
margin-top: 4px;
margin-left: -25px;
float: left;
height: 30px;
width: 30px;
border-left: none;
display: inline-block;
position: relative;
}
&#13;
<input type='text' class='location_input' placeholder='Enter a location' id='location_input'>
<div class='update_location_wrapper'>
<div class='update_location_text'><img src="http://placehold.it/20x20" alt="Search" height="20" width="20"></div>
</div>
&#13;