【问题标题】:CSS transitions in different directions不同方向的 CSS 过渡
【发布时间】:2016-04-16 18:05:39
【问题描述】:

当我将鼠标悬停在里面的小盒子上时,我试图填充一个包装器 (600x600px)。对于左上角的框,使用常规的过渡定时功能很容易完成,但是当尝试在其他方向放大时,我就卡住了。

所以我有以下内容:

#allbox {
  background: #bbb;
  width: 600px;
  height: 600px;
  margin: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0
}

带盒子:

div.box1 {
  position: absolute;
  top: 0%;
  left: 0%;
}

div.box2 {
  position: absolute;
  top: 0%;
  left: 37.5%;
}

我使用的过渡:

#div1 {-webkit-transition-timing-function: linear;}
#div1 {transition-timing-function: linear;}
div.box1:hover {
  width: 600px;
  height: 600px;
}

但我无法为下面的方框找到一个好的方法。

【问题讨论】:

  • 需要您的 HTML 部分才能正确理解它。请编辑问题并添加 HTML 部分。

标签: css css-transitions transition


【解决方案1】:

这是一个使用z-index 保持悬停在顶部的示例。

#allbox {
  background: #bbb;
  width: 600px;
  height: 300px;
  margin: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0
}
#allbox div {
  position: absolute;
  z-index: 1;
  top: 0%;
  width: 33.33%;
  height: 50%;
  transition: left 0.5s linear, width 0.5s linear, height 0.5s linear, z-index 1s linear;
}
div.box1 {
  left: 0;
  background: blue;
}
div.box2 {
  left: 33.33%;
  background: red;
}
div.box3 {
  left: 66.66%;
  background: green;
}
#allbox div:hover {
  z-index: 2;
  left: 0;
  width: 100%;
  height: 100%;
  transition: left 0.5s linear, width 0.5s linear, height 0.5s linear, z-index 0s linear;
}
<div id="allbox">
  <div class="box1">  
  </div>
  <div class="box2">  
  </div>
  <div class="box3">  
  </div>
</div>

【讨论】:

    【解决方案2】:

    我认为我们只是将“left: 0;”添加到悬停状态。

    div.box2:hover {
      left: 0;
      width: 600px;
      height: 600px;
    }
    

    希望对您有所帮助。

    【讨论】:

    • 不,box1 工作正常。我正在努力解决以下问题。 imgur.com/i99wKT8
    • 对不起,我的朋友,我的错误。我只是更新它。希望这对你有用。
    猜你喜欢
    • 2014-05-05
    • 2019-04-10
    • 2015-01-26
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2012-08-16
    • 2017-03-06
    相关资源
    最近更新 更多