【问题标题】:Transform scale on card flip在卡片翻转上变换比例
【发布时间】:2021-02-15 18:47:22
【问题描述】:

如何在 CSS 中的卡片翻转动画上使用 transform:scale()?当我将transform:scale(0.75); 放在.container 上并悬停以翻转卡片时,transform 消失了吗?

请使用 Chrome 或 Safari 查看问题。

@import url('https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i');

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i');

html, body { 
  height: 100%;
  width: 100%; 
  margin: 0; 
  padding: 0; 
  background-color:#eaeaea;}

.container {
  width:900px;
  height:550px;
  background-color:white;
  position: absolute;
  top:0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;}

.right-div {
  width:540px;
  height:550px;
  background-image:url();
  transform:scale(1);
  background-position: -170px 0px; 
  background-size:cover;
  position: absolute;
  top:0;
  bottom: 0;
  right: 0;
  margin: auto;}

.left-div {
  width:323px;
  height:550px;
  background-color:white;
  position: absolute;
  top:0;
  bottom: 0;
  left: 0;
  margin: auto;}

.content-name {
    font-family: 'Open Sans', sans-serif;
    letter-spacing: 3px;
    font-size: 10px;
    text-transform: uppercase;
    color: #7E7E7E;    
    font-weight: 700;
    margin-top:160px;
    margin-left:40px;}

.content-title {
    font-family: 'Playfair Display', serif;
    font-size: 44px;
    letter-spacing: 3px;
    font-weight: 700;
    color: #2C2C2C;
    margin-top:10px;
    margin-left:40px;}

.content-description {
    margin-top: -20px;
    font-family: 'Open Sans', sans-serif;
    font-size: 13px;
    color: #7e7e7e;
    line-height: 22px;
    margin-left:40px;}

.content-link {
    position:absolute;
    margin-top:20px;
    color: #2C2C2C;
    font-family: 'Open Sans', sans-serif;
    letter-spacing: 3px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    text-decoration: none;
    margin-left:40px;}





/*Flip*/

.flip-container {
  -webkit-perspective: 1000;
  position: fixed;
  top: 50%;
  left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, -50%);}

.flip-container:hover .flipper, .flip-container.hover .flipper {
  -webkit-transform: rotateY(180deg);}

.flip-container, .front, .back {
    width: 900px;
    height: 550px;}

.flipper {
    -webkit-transition: 0.6s;
    -webkit-transform-style: preserve-3d;
    position: relative;}

.front, .back {
    -webkit-backface-visibility: hidden;
  position: absolute;
  top:0;
  bottom: 0;}

.front {
  z-index: 2;}

.back {
  -webkit-transform: rotateY(180deg);
  background: white;}
<div class="flip-container">
    <div class="flipper">
        <div class="front">
<div class="container">
  <div class="left-div">
      <p class="content-name">title</p>
      <p class="content-title">name</p>
    <p class="content-description">Sed ut perspiciatis unde omnis iste natus <br/> error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
    <a href="#" class="content-link">Link</a>
  </div>
  <div class="right-div">
  </div>
  </div>
    </div>
    <div class="back">
      :p
        </div>
    </div>
</div>

【问题讨论】:

    标签: html css css-transforms


    【解决方案1】:

    我不知道这对您来说是否是一个好的解决方法,但您可以尝试将 transform: scale(0.75) 设置为 .front.back 类而不是 .container

    .front {
      transform: scale(0.75);
    }
    
    .back {
      transform: rotateY(180deg) scale(0.75);
    }
    

    【讨论】:

    • 你确定吗?我在 jsfiddle 上试过,效果很好,两边都缩放(在 Chrome 上)
    【解决方案2】:

    卡片的背面应该有自己的 180 度变换。既然是背面,就已经翻转了180度。对于 Firefox 60 中的我来说,即使 scale(0.75) 应用于 .container,它仍然可以正常工作。换句话说,我无法重现您所说的问题,但我确实注意到您的卡的行为不像一张卡。

    @import url('https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i');
    @import url('https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i');
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
      background-color: #eaeaea;
    }
    
    .container {
      width: 900px;
      height: 550px;
      background-color: white;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
      transform: scale(0.75);
    }
    
    .right-div {
      width: 540px;
      height: 550px;
      background-image: url();
      transform: scale(1);
      background-position: -170px 0px;
      background-size: cover;
      position: absolute;
      top: 0;
      bottom: 0;
      right: 0;
      margin: auto;
    }
    
    .left-div {
      width: 323px;
      height: 550px;
      background-color: white;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      margin: auto;
    }
    
    .content-name {
      font-family: 'Open Sans', sans-serif;
      letter-spacing: 3px;
      font-size: 10px;
      text-transform: uppercase;
      color: #7E7E7E;
      font-weight: 700;
      margin-top: 160px;
      margin-left: 40px;
    }
    
    .content-title {
      font-family: 'Playfair Display', serif;
      font-size: 44px;
      letter-spacing: 3px;
      font-weight: 700;
      color: #2C2C2C;
      margin-top: 10px;
      margin-left: 40px;
    }
    
    .content-description {
      margin-top: -20px;
      font-family: 'Open Sans', sans-serif;
      font-size: 13px;
      color: #7e7e7e;
      line-height: 22px;
      margin-left: 40px;
    }
    
    .content-link {
      position: absolute;
      margin-top: 20px;
      color: #2C2C2C;
      font-family: 'Open Sans', sans-serif;
      letter-spacing: 3px;
      font-size: 11px;
      text-transform: uppercase;
      font-weight: 700;
      text-decoration: none;
      margin-left: 40px;
    }
    
    
    /*Flip*/
    
    .flip-container {
      perspective: 1000;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      backface-visibility: visible;
    }
    
    .flip-container:hover .flipper {
      transform: rotateY(180deg);
    }
    
    .flip-container,
    .front,
    .back {
      width: 900px;
      height: 550px;
    }
    
    .flipper {
      transition: 0.6s;
      transform-style: preserve-3d;
      position: relative;
    }
    
    .front,
    .back {
      position: absolute;
      top: 0;
      bottom: 0;
    }
    
    .front {
      backface-visibility: hidden;
      background: white;
    }
    
    .back {
      backface-visibility: hidden;
      background: red;
    
      /* this is the line you were missing */
      transform: rotateY(180deg);
    }
    <div class="flip-container">
      <div class="flipper">
        <div class="front">
          <div class="container">
            <div class="left-div">
              <p class="content-name">title</p>
              <p class="content-title">name</p>
              <p class="content-description">Sed ut perspiciatis unde omnis iste natus <br/> error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
              <a href="#" class="content-link">Link</a>
            </div>
            <div class="right-div">
            </div>
          </div>
        </div>
        <div class="back">
          :p
          <h1> you have to put the snippet in fullscreen mode because this card is really big </h1>
        </div>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 2018-08-08
      • 2014-02-25
      • 2013-11-22
      • 2015-06-05
      • 2012-04-04
      相关资源
      最近更新 更多