icon 圖示css實現

與自己賽跑的青年發表於2018-12-19

icon 圖示css實現

.icon {
  position: relative;

  font-style: normal;
  //   padding: 10px;
  box-sizing: border-box;
}
//--------------------------plus--------------------//
.icon-plus::before,
.icon-plus::after {
  content: "";
  width: 16px;
  height: 2px;
  background-color: currentColor;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate3d(-50%, -50%, 0);
}
.icon-plus::after {
  width: 2px;
  height: 16px;
}
//--------------------------right--------------------//
.icon-right::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 8px;
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  transform: translate(-50%, -50%) rotate(-52deg);
  box-sizing: border-box;
  margin-top: -1px;
}
//--------------------------cross--------------------//
.icon-cross::before,
.icon-cross::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 14px;
  transform: translate(-50%, -50%) rotate(45deg);
  background-color: currentColor;
}
.icon-cross::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
//--------------------------arrow-left--------------------//
.icon-arrow-left::after {
  content: "";
  display: inline-block;
  vertical-align: middle;
  width: 10px;
  height: 10px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: 2px;
  -webkit-transform: translate(-50%, -50%) rotate(45deg);
  -ms-transform: translate(-50%, -50%) rotate(45deg);
  transform: translate(-50%, -50%) rotate(45deg);
  box-sizing: border-box;
}
//--------------------------arrow-right--------------------//
.icon-arrow-right::after {
  content: "";
  display: inline-block;
  vertical-align: middle;
  width: 10px;
  height: 10px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -2px;
  -webkit-transform: translate(-50%, -50%) rotate(45deg);
  -ms-transform: translate(-50%, -50%) rotate(45deg);
  transform: translate(-50%, -50%) rotate(45deg);
  box-sizing: border-box;
}
//--------------------------search--------------------//
.icon-search::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  border: 2px solid currentColor;
  height: 12px;
  width: 12px;
  box-sizing: border-box;
  border-radius: 50%;
  margin-left: -2px;
  margin-top: -2px;
}
.icon-search::after {
  content: "";
  background: currentColor;
  height: 6px;
  width: 2px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: 4px;
  margin-top: 4px;
  -webkit-transform: translate(-50%, -50%) rotate(-45deg);
  -ms-transform: translate(-50%, -50%) rotate(-45deg);
  transform: translate(-50%, -50%) rotate(-45deg);
}
//--------------------------warning ,info,question,ok--------------------//
.icon-warning,
.icon-info,
.icon-question,
.icon-ok {
  display: inline-block;
  vertical-align: middle;
  position: relative;
  width: 18px;
  height: 18px;
  border: 1px solid currentColor;
  border-radius: 50%;
  line-height: 16px;
  text-align: center;
}
.icon-warning {
  color: red;
}
.icon-warning::after {
  content: "!";
}
.icon-info {
  color: red;
}
.icon-info::after {
  content: "i";
}
.icon-question {
  color: red;
}
.icon-question::after {
  content: "?";
}
.icon-ok {
  color: red;
}
.icon-ok::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 2px;
  border-bottom: 1px solid currentColor;
  border-left: 1px solid currentColor;
  -webkit-transform: translate(-50%, -50%) rotate(-52deg) scale(1.5);
  -ms-transform: translate(-50%, -50%) rotate(-52deg) scale(1.5);
  transform: translate(-50%, -50%) rotate(-52deg) scale(1.5);
  margin-top: -1px;
}
//--------------------------checkbox,radio-------------------//
.icon-checkbox,
.icon-radio {
  display: inline-block;
  vertical-align: middle;
  width: 16px;
  height: 16px;
  color: #999;
  border: 1px solid currentColor;
  background-color: #fff;
  position: relative;
  top: -1px;
  margin-right: 5px;
  box-sizing: border-box;
}
//--------------------------checkbox--------------------//
.icon-checkbox::before {
  content: "";
  width: 5px;
  height: 6px;
  background-color: #fff;
  position: absolute;
  right: -1px;
  top: -1px;
}
.icon-checkbox::after {
  content: "";
  height: 4px;
  width: 10px;
  border: 1px solid currentColor;
  border-width: 0 0 2px 2px;
  position: absolute;
  top: 1px;
  left: 3px;
  -webkit-transform: rotate(-52deg);
  -ms-transform: rotate(-52deg);
  transform: rotate(-52deg);
}
//--------------------------radio--------------------//
.icon-radio {
  border-radius: 10px;
}
.icon-radio::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  position: absolute;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
//--------------------------switch--------------------//
.icon-switch {
  height: 30px;
  width: 50px;
  position: relative;
  display: inline-block;
  vertical-align: middle;
  background-color: #ccc;
  border-radius: 15px;
  overflow: hidden;
  z-index: 1;
}
.icon-switch::before {
  content: "";
  height: 30px;
  width: 50px;
  position: absolute;
  left: -50px;
  background-color: #099fde;
  border-radius: 15px;
  -webkit-transition: left 0.2s ease 0s;
  transition: left 0.2s ease 0s;
  z-index: 2;
}
.icon-switch::after {
  content: "";
  height: 26px;
  width: 26px;
  background-color: #fff;
  border-radius: 15px;
  position: absolute;
  left: 2px;
  top: 2px;
  -webkit-transition: left 0.2s ease 0s;
  transition: left 0.2s ease 0s;
  z-index: 3;
}
.icon-switch.active::before {
  left: 0;
}
.icon-switch.active::after {
  left: 22px;
}
複製程式碼

相關文章