使用CSS转换时文本摆动

时间:2013-04-08 18:34:47

标签: css hover css-transitions transition shake

在Chrome和Safari中,此代码中的文字(http://codepen.io/igdaloff/pen/cgCFt)在悬停时会微妙地摆动。我希望文本在整个过渡过程中保持稳定。

我已经尝试了几种替代方法来实现同样的效果(在this post中解释),但是摆动仍然存在。

我需要文本保持垂直居中,内容完全流畅(仅限百分比)。只要这些要求属实,我就会对任何解决方案持开放态度。我正在使用最新的浏览器版本。

提前致谢。

1 个答案:

答案 0 :(得分:1)

HTML

<div class="work-home">         
  <ul>
      <li>
        <a href="">
          <img src="..." />
          <h4>Goats</h4>
        </a>
      </li>
  </ul>
</div>

CSS

.work-home {
  text-align: center;
}
.work-home li {
  display: inline-block;
  position: relative;
  margin: 0 0 2em;
  width: 100%;
}

.work-home li:hover a:before {
  opacity: 1;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom:5%;
}

.work-home li:hover h4 {
  opacity:1;
}

.work-home img {
  width: 100%;
  -webkit-transition: all 0.1s ease;
  -moz-transition: all 0.1s ease;
  -o-transition: all 0.1s ease;
  transition: all 0.1s ease;
}

.work-home a:before {
  content:"";
  display:block;
  opacity: 0;
  position: absolute;
  margin: 0;
  top:0;
  right:0;
  left:0;
  bottom:0;
  background-color: rgba(0, 160, 227, 0.88);
  -webkit-transition: all linear .3s;
  -moz-transition: all linear .3s;
  -ms-transition: all linear .3s;
  transition: all linear .3s;
}


.work-home h4 {
  display: block;
  padding: 0;
  margin:0;
  font-family: helvetica, sans-serif;
  font-size: 4em;
  color: #ffffff;
  position:absolute;
  top:50%;
  margin-top:-.8em;
  text-align:center;
  width:100%;
  z-index:1;
  opacity:0;
  -webkit-transition: all linear .3s;
  -moz-transition: all linear .3s;
  -ms-transition: all linear .3s;
  transition: all linear .3s;
}
相关问题