13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

検索フォームの虫眼鏡アイコンをcssのみで作成

Last updated at Posted at 2018-01-09

このようなよくある虫眼鏡の検索フォームをcssだけで再現しました。
searchForm.png

擬似要素のbeforeで虫眼鏡の円を、afterで右下の線を書いています。
beforeとafterを使うことでこれぐらいならそれほどのコード量にもならずに描けます。

<div class="searchForm">
 <input class="searchForm-input" type="text">
 <button class="searchForm-submit" type="submit"></button>
</div>
input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 10px;
  margin: 5px 0;
  border: 1px solid #999;
  border-radius: 5px;
}
.searchForm {
  position: relative;
}
.searchForm-input {
  width: 100%;
}
.searchForm-submit {
  position: absolute;
  width: 38px;
  height: 38px;
  top: calc(50% - 19px);
  right: 0;
  border-radius: 0 4px 4px 0;
  background: #999;
}
.searchForm-submit::before {
  position: absolute;
  content: '';
  width: 15px;
  height: 15px;
  top: calc(50% - 9px);
  left: calc(50% - 9px);
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff;
}
.searchForm-submit::after {
  position: absolute;
  content: '';
  width: 8px;
  height: 6px;
  top: calc(50% + 6px);
  left: calc(50% + 2px);
  border-top: solid 2px #fff;
  transform: rotate(45deg);
}

13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?