I have a problem with transform property. There is a box with position: absolute
. To put this in the center of parent div I use transform: translate(-50%, -50%)
because in real project I have adaptive page. So, I can't use px and negative margin.
In addition I want to apply zoomIn animation and see that with animation line transform: translate(-50%, -50%)
doesn't work. I suppose, it's because of double transform property.
How can I fix it?
This is example on Codepen https://codepen.io/pndparade/pen/VKGXPj
html,
body{
height: 100%;
margin: 0;
padding: 0;
}
.box{
height: 100%;
width: 100%;
background: red;
position: relative;
}
.box-in{
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
animation-duration: 1.5s;
animation-delay: 0.8s;
animation-fill-mode: both;
animation-name: zoomIn;
animation-iteration-count: infinite;
}
@keyframes zoomIn {
from {
opacity: 0;
-webkit-transform: scale3d(.3, .3, .3);
transform: scale3d(.3, .3, .3);
}
50% {
opacity: 1;
}
to {
-webkit-transform: scale3d(1, 1, .1);
transform: scale3d(1, 1, 1);
}
}