当前位置:Gxlcms > css > 纯CSS3实现搜索框功能实例展示

纯CSS3实现搜索框功能实例展示

时间:2021-07-01 10:21:17 帮助过:7人阅读

本文通过实例代码给大家分享8款纯CSS3实现的搜索框功能,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友参考下吧

效果图:


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>8款纯CSS3搜索框</title>
  7. <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  8. <link rel="stylesheet" href="style.css">
  9. <style>
  10. * {
  11. box-sizing: border-box;
  12. }
  13. body {
  14. margin: 0;
  15. padding: 0;
  16. background: #494A5F;
  17. font-weight: 500;
  18. font-family: "Microsoft YaHei","宋体","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif, FreeSans, Arimo;
  19. }
  20. #container {
  21. width: 500px;
  22. height: 820px;
  23. margin: 0 auto;
  24. }
  25. p.search {padding: 30px 0;}
  26. form {
  27. position: relative;
  28. width: 300px;
  29. margin: 0 auto;
  30. }
  31. input, button {
  32. border: none;
  33. outline: none;
  34. }
  35. input {
  36. width: 100%;
  37. height: 42px;
  38. padding-left: 13px;
  39. padding-right:46px;
  40. }
  41. button {
  42. height: 42px;
  43. width: 42px;
  44. cursor: pointer;
  45. position: absolute;
  46. }
  47. /*搜索框1*/
  48. .bar1 {background: #A3D0C3;}
  49. .bar1 input {
  50. border: 2px solid #7BA7AB;
  51. border-radius: 5px;
  52. background: #F9F0DA;
  53. color: #9E9C9C;
  54. }
  55. .bar1 button {
  56. top: 0;
  57. right: 0;
  58. background: #7BA7AB;
  59. border-radius: 0 5px 5px 0;
  60. }
  61. .bar1 button:before {
  62. content: "\f002";
  63. font-family: FontAwesome;
  64. font-size: 16px;
  65. color: #F9F0DA;
  66. }
  67. /*搜索框2*/
  68. .bar2 {background: #DABB52;}
  69. .bar2 input, .bar2 button {
  70. border-radius: 3px;
  71. }
  72. .bar2 input {
  73. background: #F9F0DA;
  74. }
  75. .bar2 button {
  76. height: 26px;
  77. width: 26px;
  78. top: 8px;
  79. right: 8px;
  80. background: #F15B42;
  81. }
  82. .bar2 button:before {
  83. content: "\f105";
  84. font-family: FontAwesome;
  85. color: #F9F0DA;
  86. font-size: 20px;
  87. font-weight: bold;
  88. }
  89. /*搜索框3*/
  90. .bar3 {background: #F9F0DA;}
  91. .bar3 form {background: #A3D0C3;}
  92. .bar3 input, .bar3 button {
  93. background: transparent;
  94. }
  95. .bar3 button {
  96. top: 0;
  97. right: 0;
  98. }
  99. .bar3 button:before {
  100. content: "\f002";
  101. font-family: FontAwesome;
  102. font-size: 16px;
  103. color: #F9F0DA;
  104. }
  105. /*搜索框4*/
  106. .bar4 {background: #F15B42;}
  107. .bar4 form {
  108. background: #F9F0DA;
  109. border-bottom: 2px solid #BE290E;
  110. }
  111. .bar4 input, .bar4 button {
  112. background: transparent;
  113. }
  114. .bar4 button {
  115. top: 0;
  116. right: 0;
  117. }
  118. .bar4 button:before {
  119. content: "\f178";
  120. font-family: FontAwesome;
  121. font-size: 20px;
  122. color: #be290e;
  123. }
  124. /*搜索框5*/
  125. .bar5 {background: #683B4D;}
  126. .bar5 input, .bar5 button {
  127. background: transparent;
  128. }
  129. .bar5 input {
  130. border: 2px solid #F9F0DA;
  131. }
  132. .bar5 button {
  133. top: 0;
  134. right: 0;
  135. }
  136. .bar5 button:before {
  137. content: "\f002";
  138. font-family: FontAwesome;
  139. font-size: 16px;
  140. color: #F9F0DA;
  141. }
  142. .bar5 input:focus {
  143. border-color: #311c24
  144. }
  145. /*搜索框6*/
  146. .bar6 {background: #F9F0DA;}
  147. .bar6 input {
  148. border: 2px solid #c5464a;
  149. border-radius: 5px;
  150. background: transparent;
  151. top: 0;
  152. right: 0;
  153. }
  154. .bar6 button {
  155. background: #c5464a;
  156. border-radius: 0 5px 5px 0;
  157. width: 60px;
  158. top: 0;
  159. right: 0;
  160. }
  161. .bar6 button:before {
  162. content: "搜索";
  163. font-size: 13px;
  164. color: #F9F0DA;
  165. }
  166. /*搜索框7*/
  167. .bar7 {background: #7BA7AB;}
  168. .bar7 form {
  169. height: 42px;
  170. }
  171. .bar7 input {
  172. width: 250px;
  173. border-radius: 42px;
  174. border: 2px solid #324B4E;
  175. background: #F9F0DA;
  176. transition: .3s linear;
  177. float: right;
  178. }
  179. .bar7 input:focus {
  180. width: 300px;
  181. }
  182. .bar7 button {
  183. background: none;
  184. top: -2px;
  185. right: 0;
  186. }
  187. .bar7 button:before{
  188. content: "\f002";
  189. font-family: FontAwesome;
  190. color: #324b4e;
  191. }
  192. /*搜索框8*/
  193. .bar8 {background: #B46381;}
  194. .bar8 form {
  195. height: 42px;
  196. }
  197. .bar8 input {
  198. width: 0;
  199. padding: 0 42px 0 15px;
  200. border-bottom: 2px solid transparent;
  201. background: transparent;
  202. transition: .3s linear;
  203. position: absolute;
  204. top: 0;
  205. right: 0;
  206. z-index: 2;
  207. }
  208. .bar8 input:focus {
  209. width: 300px;
  210. z-index: 1;
  211. border-bottom: 2px solid #F9F0DA;
  212. }
  213. .bar8 button {
  214. background: #683B4D;
  215. top: 0;
  216. right: 0;
  217. }
  218. .bar8 button:before {
  219. content: "\f002";
  220. font-family: FontAwesome;
  221. font-size: 16px;
  222. color: #F9F0DA;
  223. }
  224. </style>
  225. </head>
  226. <body>
  227. <p id="container">
  228. <p class="search bar1">
  229. <form>
  230. <input type="text" placeholder="请输入您要搜索的内容...">
  231. <button type="submit"></button>
  232. </form>
  233. </p>
  234. <p class="search bar2">
  235. <form>
  236. <input type="text" placeholder="请输入您要搜索的内容...">
  237. <button type="submit"></button>
  238. </form>
  239. </p>
  240. <p class="search bar3">
  241. <form>
  242. <input type="text" placeholder="请输入您要搜索的内容...">
  243. <button type="submit"></button>
  244. </form>
  245. </p>
  246. <p class="search bar4">
  247. <form>
  248. <input type="text" placeholder="请输入您要搜索的内容...">
  249. <button type="submit"></button>
  250. </form>
  251. </p>
  252. <p class="search bar5">
  253. <form>
  254. <input type="text" placeholder="请输入您要搜索的内容...">
  255. <button type="submit"></button>
  256. </form>
  257. </p>
  258. <p class="search bar6">
  259. <form>
  260. <input type="text" placeholder="请输入您要搜索的内容...">
  261. <button type="submit"></button>
  262. </form>
  263. </p>
  264. <p class="search bar7">
  265. <form>
  266. <input type="text" placeholder="请输入您要搜索的内容...">
  267. <button type="submit"></button>
  268. </form>
  269. </p>
  270. <p class="search bar8">
  271. <form>
  272. <input type="text" placeholder="请输入您要搜索的内容...">
  273. <button type="submit"></button>
  274. </form>
  275. </p>
  276. </p>
  277. </body>
  278. </html>

以上就是纯CSS3实现搜索框功能实例展示的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行