Files
30-seconds-of-code/snippets/icon-border.md
2018-10-30 19:46:58 +01:00

1.6 KiB

Icon Border Animation

Creates a border animation on hover.

HTML

<a href="#" class="button ion-ios-star-outline"></a>

CSS

@import url(https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css);
.button {
  position: relative;
  overflow: hidden;
  font-size: 40px;
  color: rgba(255, 255, 255, 0.8);
  margin: 40px;
  padding: 3px;
  display: inline-block;
  text-align: center;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.6);
  text-decoration: none;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}
.button::before {
  background-color: #2b2b2b;
  width: 75px;
  height: 75px;
  line-height: 75px;
}
.button:after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #f39c12;
  content: '';
  z-index: -1;
  display: inline-block;
  -webkit-transform: rotate(-45deg) scale(1.5) translate(0%, -100%);
  transform: rotate(-45deg) scale(1.5) translate(0%, -100%);
}
.button:before,
.button:after {
  -webkit-transition: all 0.4s ease-in-out;
  transition: all 0.4s ease-in-out;
}
.button:hover,
.button:active,
.button.hover {
  color: #ffffff;
}
.button:hover:after,
.button:active:after,
.button.hover:after {
  -webkit-transform: rotate(-45deg) scale(1.5) translate(0%, 0%);
  transform: rotate(-45deg) scale(1.5) translate(0%, 0%);
}

Demo

Explanation

This effect is uses before and after selectors to make the border full width on hover.

Browser support

No caveats.