I'm trying to use the solution to this question:
css3 transition animation on load?
And I have the following as my HTML and CSS:
@keyframes slideInFromRight {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(0);
}
}
.announcements-container {
position: fixed;
top: 80px;
right: 20px;
z-index: 1001;
display: flex;
flex-direction: column;
width: 300px;
/* animation: 1s ease-out 0s 1 slideInFromRight; */
}
.announcments-1 {
animation: 1s ease-out 0s 1 slideInFromRight;
}
.announcements-2 {
margin-top: 15px;
}
.annoucements-header {
background-color: #1481C3;
color: #ffffff;
font-family: "Proxima Nova Bold";
padding: 7px 10px;
}
.annoucements-close {
position: absolute;
right: 5px;
width: 24px;
height: 36px;
cursor: pointer;
opacity: .85;
}
.annoucements-close:hover {
opacity: 1;
}
.annoucements-close::before,
.annoucements-close::after {
content: '';
width: 24px;
height: 2px;
background: white;
position: absolute;
top: 7px;
left: 0;
}
.annoucements-close::before {
transform: rotate(-45deg);
}
.annoucements-close::after {
transform: rotate(45deg);
}
<body>
<div class="announcements-container">
<div class="announcements-1">
<div class="annoucements-header">
<span class="annoucement-type-quantity">2 School Announcements</span>
<i class="annoucements-close"></i>
</div>
</div>
<div class="announcements-2">
<div class="annoucements-header">
<span class="annoucement-type-quantity">1 Admin Annoucement</span>
<i class="annoucements-close"></i>
</div>
</div>
</div>
</body>
As you can see, it doesn't do anything when animation: 1s ease-out 0s 1 slideInFromRight;
gets applied to an inner-div. It does, however, work when applied to the container div:
@keyframes slideInFromRight {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(0);
}
}
.announcements-container {
position: fixed;
top: 80px;
right: 20px;
z-index: 1001;
display: flex;
flex-direction: column;
width: 300px;
animation: 1s ease-out 0s 1 slideInFromRight;
}
.announcments-1 {
/*animation: 1s ease-out 0s 1 slideInFromRight;*/
}
.announcements-2 {
margin-top: 15px;
}
.annoucements-header {
background-color: #1481C3;
color: #ffffff;
font-family: "Proxima Nova Bold";
padding: 7px 10px;
}
.annoucements-close {
position: absolute;
right: 5px;
width: 24px;
height: 36px;
cursor: pointer;
opacity: .85;
}
.annoucements-close:hover {
opacity: 1;
}
.annoucements-close::before,
.annoucements-close::after {
content: '';
width: 24px;
height: 2px;
background: white;
position: absolute;
top: 7px;
left: 0;
}
.annoucements-close::before {
transform: rotate(-45deg);
}
.annoucements-close::after {
transform: rotate(45deg);
}
<body>
<div class="announcements-container">
<div class="announcements-1">
<div class="annoucements-header">
<span class="annoucement-type-quantity">2 School Announcements</span>
<i class="annoucements-close"></i>
</div>
</div>
<div class="announcements-2">
<div class="annoucements-header">
<span class="annoucement-type-quantity">1 Admin Annoucement</span>
<i class="annoucements-close"></i>
</div>
</div>
</div>
</body>
But the issue with that, is that I want for the divs to slide in one after another, sequentially. And if I 'X' out of the top div, I'll want for the second div to slide up and take its place, which is why I'm assuming a container div is necessary.
Is there anything else I can do to make the animation apply to the child divs, one at a time? Is there something about keyframes that prevents animation on inner-divs? Is it better to do this with JavaScript?