最近在模仿写新浪微博的首页,其中搜索框的搜索按钮位于搜索框之内,突然想起刚刚接触前端的时候被这个给难住了,哎......实在是惭愧啊!
思想很简单:将input(type=text)和input(type=button)放入同一个div中,给这个div一个边框border,而input(type=text)不设置边框,这样就达到了效果。
代码如下:
<div class="search">
<input type="text" class="search_input" placeholder="请输入搜索词"/>
<input type="button" class="search_btn"/>
</div>
.search {
width: 568px;
height: 28px;
border: 1px solid #ccc;//设置边框
background-color: #f2f2f5;
margin: 10px 0;
}
.search_input {
width: 520px;
float: left;
height: 28px;
line-height: 28px \9;
padding: 0 8px;
}
.search_btn {
width: 18px;
height: 26px;
background: url(../img/s.jpg) left center no-repeat;
float: right;
margin-right: 10px;
}