検索ボックスに虫眼鏡を入れる方法
検索ボックスを二つに分ける
はじめ、検索ボックスの中に虫眼鏡を入れる方法は、言葉のとおりtextboxのなかにimageを入れるものだと思っていた。
もちろん、asoluteを使ったりすることで可能になるかもしれないが、個人的にはabsoluteを使ったりして強引に作るのは好きではない。
そこで、ボックスを二つ作ることにした。
一つは、textboxでもう一つはbuttonだ。
具体的なhtmlのソースは以下のとおりである。
<div >
<input type="text" class="form-control" style="width: 130px; height:25px; border-right:none; border-radius:0px;">
<button style="border-radius:0px; width: 30px; height:25px;border-left:none; border:1px solid #ccc;background-color:transparent;">
<img src="ここに虫眼鏡アイコン" alighn="center"></i>
</button>
</div>
なお、form-controlはbootstrapを使っており、
cssの中身は、
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
-webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
である。