クリックすると横に広がり、そのまま入力欄になるサイト内検索用の虫眼鏡型アイコンです。検索キーワードを入れ、enter(return)キーを押すか、何も入れずにアイコン以外をクリックすると閉じて元のアイコンに戻ります。

サンプルのhtmlソース

  1. <div class="flexbox">
  2. <div class="search">
  3. <h1>Search this site</h1>
  4. <h3>Click on search icon, then type your keyword.</h3>
  5. <div>
  6. <input type="text" placeholder=" Search . . ." required>
  7. </div>
  8. </div>
  9. </div>

サンプルのCSSソース

  1. .flexbox {
  2. background: linear-gradient(155deg, #37d, #59f, #7bf);
  3. font-family: Roboto, sans-serif;
  4. width: 600px;
  5. height:240px;
  6. margin:20px auto;
  7. display: flex;
  8. justify-content: center;
  9. align-items: center;
  10. }
  11. .search {
  12. margin: 20px;
  13. }
  14. .search > h3 {
  15. font-weight: normal;
  16. }
  17. .search > h1,
  18. .search > h3 {
  19. color: white;
  20. margin-bottom: 15px;
  21. text-shadow: 0 1px #0091c2;
  22. }
  23. .search > div {
  24. display: inline-block;
  25. position: relative;
  26. }
  27. .search > div:after {
  28. content: "";
  29. background: white;
  30. width: 4px;
  31. height: 20px;
  32. position: absolute;
  33. top: 40px;
  34. right: 2px;
  35. transform: rotate(135deg);
  36. box-shadow: 1px 0 #0091c2;
  37. }
  38. .search > div > input {
  39. color: white;
  40. font-size: 16px;
  41. background: transparent;
  42. width: 25px;
  43. height: 25px;
  44. padding: 10px;
  45. border: solid 3px white;
  46. outline: none;
  47. border-radius: 35px;
  48. box-shadow: 0 1px #0091c2;
  49. transition: width 0.5s;
  50. }
  51. .search > div > input::placeholder {
  52. color: #48e;
  53. opacity: 1;
  54. }
  55. .search > div > input::-ms-placeholder {
  56. color: #48e;
  57. }
  58. .search > div > input::-ms-input-placeholder {
  59. color: #48e;
  60. }
  61. .search > div > input:focus,
  62. .search > div > input:valid {
  63. width: 250px;
  64. }

 

 

引用と参考;https://codepen.io/takaneichinose/pen/gKVXXL
戻るボタン