10
6

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.

display:none; だと、transitionが効かない時の解決

Posted at

問題

ツールチップを作る際、hover時に
ふわっと表示されるようにしたいが、
今回都合上displayプロパティを使用することになった。

.tooltip {
 display:none;/*いつもはopacity:0;と書いていた*/
 transform: translateY(5px);
 transition: 0.3s;
}
.tooltip:hover {
 display:block;/*いつもはopacity:1;と書いていた*/
 transform: translateY(0px);
}

すると、transitionが効かない。

解決

@keyframes tooltipShow {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0px);
  }
}
.tooltip {
  display: none;
}
.tooltip:hover {
  animation: tooltipShow 0.3s linear 0s;
  display: block;
}
10
6
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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?