前言
給大家分享一下前端用處很多的帶小圖標的搜索框的制作方法。
效果展示
基本思路
1、搜索圖像用絕對定位放到搜索框的上方
2、input框設置文本縮進,大小為搜索圖像大小加上圖像左右兩邊的外邊距
準備
只需一個搜索圖標圖片,類似于下圖
代碼
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>搜索框demo</title> <style type="text/css"> *{ margin: 0; padding: 0; } body{ width: 100vw; height: 100vh; background: radial-gradient(at center, #3498db,#2980b9); display: flex; justify-content: center; align-items: center; } div.search{ height: 40px; width: 500px; } div.search form{ width: 100%; height: 100%; } div.search form input:nth-child(2){ width: 400px; height: 100%; font-size: 16px; text-indent: 40px; border: none; float: left; } div.search form input:nth-child(3){ width: 100px; height: 100%; font-size: 16px; letter-spacing: 5px; border: none; } div.search form img{ position: absolute; left: 50vw; transform: translateX(-250px); margin-top: 10px; margin-left: 10px; height: 20px; } </style></head><body> <div class="search"> <form action="#" method="post"> <img src="./search_ico.png" alt=""> <input type="text" name="condition" placeholder="請輸入搜索條件"> <input type="submit" value="搜索"> </form> </div></body></html>
總結
以上所述是小編給大家介紹的基于html css實現帶搜索圖標的搜索框功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
新聞熱點
疑難解答