실전퍼블리싱(hover되면 나타나는 툴팁)

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

hover되면 나타나는 툴팁


예제보기

visibility: hiddenvisible 대신에 .icon spanpointer-events:none;을 사용해도 됨.

HTML

  <div class="container">
    <div class="icon">
      <img src="./images/icon-01.png">
      <span>
        This HTML tutorial contains hundreds of HTML examples.
      </span>
    </div>
    <div class="icon">
      <img src="./images/icon-02.png">
      <span>
        This CSS tutorial contains hundreds of CSS examples.
      </span>
    </div>
    <div class="icon">
      <img src="./images/icon-03.png">
      <span>
        AngularJS extends HTML with new attributes.
      </span>
    </div>
    <div class="icon">
      <img src="./images/icon-04.png">
      <span>
        Node.js is an open source server environment.
      </span>
    </div>
  </div>

CSS

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

body {
  font-family: 'Raleway', 'sans-serif';
  color: #222;
  line-height: 1.5em;
  margin: 0;
  font-weight: 300;
}
a {
  color: #222;
  text-decoration: none;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.icon {
  width: 125px;
  height: 125px;
  margin: 10px;
  position: relative;
}
.icon span {
  position: absolute;
  background-color: #000;
  color: #fff;
  width: 300px;
  top: -80px;
  text-align: center;
  padding: 10px;
  border-radius: 5px;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  transition: .5s;
  visibility: hidden;
}
.icon span::after {
  content: '';
  position: absolute;
  background-color: #000;
  width: 10px;
  height: 10px;
  transform: rotate(45deg) translateX(-50%);
  bottom: -7px;
  left: 50%;
}
.icon:hover span {
  opacity: 1;
  visibility: visible;
}
profile
프론트엔드 4년차

0개의 댓글