css - 我怎样才能水平居中这个动画?

标签 css animation alignment

我有 3 张图像叠加在链接悬停上的 css 动画。我正在使用 position:absolute 来叠加 2 个动画图像。但是后来我不知道如何将动画放在页面的中心。

这是CodePen http://codepen.io/beng_beng/pen/IHAFD

<div id="avatar">
  <img src="http://placehold.it/174x174" alt="rotator">
    <a id="rotator" href="#"><img src="http://s28.postimg.org/gfrse4h7d/small.png" alt="rotator"><span><img src="http://s27.postimg.org/j6qdwtowf/small.png" alt="rotator"></span></a>
</div>


body {
  margin:0;
  padding:0;
}
#avatar img {
  position: relative;
  height: 174px;
  width: 174px;
  border-radius: 100%;
}
a#rotator img {
position: absolute;
top: 0;
left: 0;
-webkit-transition: all 1s ease-in-out; 
-moz-transition: all 1s ease-in-out;  
-o-transition: all 1s ease-in-out; 
-ms-transition: all 1s ease-in-out;
}

a#rotator:hover img { 
-webkit-transform: rotate(-360deg); 
-moz-transform: rotate(-360deg); 
-o-transform: rotate(-360deg);
-ms-transform: rotate(-360deg); 
}

a#rotator span img {
position: absolute;
width: 147px;
height: 147px;
top: 14px;
left: 14px;
-webkit-transition: all 1s ease-in-out; 
-moz-transition: all 1s ease-in-out;  
-o-transition: all 1s ease-in-out; 
-ms-transition: all 1s ease-in-out;
}

a#rotator:hover span img { 
-webkit-transform: rotate(360deg); 
-moz-transform: rotate(360deg); 
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg); 
}

最佳答案

将此添加到您的 CSS:

#avatar {
  text-align:center;
  position:relative;
  width:147px;
  margin:0 auto;
}

关于css - 我怎样才能水平居中这个动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23974473/

相关文章:

html - 创建 slider 但无法将图像置于绝对 div 的中心

html - 使用 overflow-x :auto (so it hides content). Chrome 时,Internet Explorer 不会针对表格单元格高度进行调整。我怎样才能解决这个问题?

javascript - 如何使 javascript 形状看起来与图像中的形状相同以及如何在动画结束后清除 javascript Canvas 形状?

ios - SwiftUI 中的自定义 segue 动画(导航动画)

C 对齐特定用例的字符串文字

html - 如何对齐一行中的框

html - 'background-color' 上的“背景位置”与 CSS

javascript - 根据页面宽度 javascript 更改 CSS?

css - HTML5。我无法将菜单标题与 ul 背景匹配

iphone - UITableView 中的错误(deleteSections :withRowAnimation: )?