Flip a 3D card with CSS

前端 未结 2 1749
星月不相逢
星月不相逢 2020-11-27 23:02

I\'m trying to make a 3D card flipping effect with CSS like this.

The difference is that I want to use only CSS to implem

2条回答
  •  萌比男神i
    2020-11-27 23:47

    yes it can be done using CSS only and you can do by using CSS3 animation property. Here is example of flipping card animation.

    User

    The CSS

    .card-container {
        display: inline-block;
        margin: 0 auto;
        padding: 0 12px;
        perspective: 900px;
        text-align: center;
    }
    
    .card {
      position: relative;
      width: 100px;
      height: 100px;
      transition: all 0.6s ease;
      transform-style: preserve-3d;
    }
    
    .front, .back {
      position: absolute;
      background: #FEC606;
      top: 0;
      left: 0;
      width: 100px;
      height: 100px;
      border-radius: 5px;
      color: white;
      box-shadow: 0 27px 55px 0 rgba(0, 0, 0, 0.3), 0 17px 17px 0 rgba(0, 0, 0, 0.15);
      backface-visibility: hidden;
    }
    
    .front {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30px;
    }
    
    .back {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 18px;
    }
    
    .card-container:hover .card {
      transform: rotateY(180deg);
    }
    
    .back {
      transform: rotateY(180deg);
    }
    

    You can also read this article about CSS Flip Animation on Hover

    You can also find demo and download source from the article.

提交回复
热议问题