실전퍼블리싱(네비게이션 호버이펙트-content attr)

Dev_Go·2022년 7월 19일
0
post-thumbnail

네비게이션 호버이펙트-content attr


요소의 앞뒤를 디자인 하는 가상클래스 before, after을 이용하여 SNS 아이콘 애니메이션 네이게이션 만들기

예제보기

HTML

  <div class="gnb">
    <a href="javascript:viod(0)" data-text="CodingWorks Online Class"></a>
  </div>

CSS

/* Google Web Font */
@import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');

/* Fontawesome 4.7 */
@import url('https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');

body {
  font-family: 'Raleway', sans-serif;
  line-height: 1.5em;
  margin: 0;
  font-weight: 300;
  color: #222;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
a {
  text-decoration: none;
  color: #222;
}

.gnb a {
  width: 300px;
  display: block;
  height: 40px;
  position: relative;
  overflow: hidden;
}
.gnb a::before,
.gnb a::after {
  content: attr(data-text);
  position: absolute;
  width: inherit;
  height: inherit;
  text-align: center;
  line-height: 40px;
  color: #fff;
  text-transform: uppercase;
  transition: 0.3s;
}
.gnb a::before {
  background-color: crimson;
  top: 0;
}
.gnb a::after {
  background-color: royalblue;
  top: 40px;
}
.gnb a:hover::before {
  top: -40px;
}
.gnb a:hover::after {
  top: 0;
}
profile
프론트엔드 4년차

0개의 댓글