1

我正在尝试使用翻译百分比垂直定位元素,以便我可以轻松地为它们设置动画。在以下示例中,无论 y 值如何,百分比都不会移动我的元素。

http://jsfiddle.net/DUdzC/3/

<div id="experiment-slide-display">

    <div id="slide">

            <div class="experiment"><div class="experiment-title">abstraction layer</div></div>
    </div>

</div>

CSS:

html{width:100%;height:100%; margin: 0;}
body{overflow:hidden; margin:0; width:100%; height:100%;}


#experiment-slide-display{top: 50%; left:50%; position:absolute;border:1px solid #000000;}
#slide{height:2000px; top:-1000px; position: absolute; left:0; width:20px;}

.experiment{position: relative; -webkit-transform: translate(0%,50%); -moz-transform: translate(0%,50%); transform: translate(0%,50%); }
.experiment-title{position: absolute;}
4

1 回答 1

0

只需对您的代码进行一些调整并使其发生...

演示:- http://jsfiddle.net/DUdzC/4/

CSS:-

#experiment-slide-display { width: 100%; height:100%; top:0; left:0; position:absolute; }
#slide { height:20px; top:50%; position: absolute; left:50%; width:200px; margin-left:-100px; margin-top:-10px; text-align:center; }

.experiment { position: relative; -webkit-transform: translate(0%,50%); -moz-transform: translate(0%,50%); transform: translate(0%,50%);  width:100%; }
.experiment-title { position: absolute; top:0; left:0; width:100%; }

谢谢希望这对你有用...

于 2013-07-09T05:24:02.423 回答