So I'm using three different texts and the first class .item-1 seems to be positioned properly but the second one goes slightly lower and the third one is way off at the bottom. I used the "margin-top" to get it centered but I feel like this isn't the best practice.
What are some ways to get them centered no matter what?
.divider3 {
background-image: url("images/people.png");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #b6b6b6;
height: 300px;
margin: 0 auto;
}
.divider3 p {
color: #FFFFFF;
font-size: 20px;
text-align: center;
line-height: 25px;
letter-spacing: 1px;
padding-top: 8%;
}
.item-1, .item-2, .item-3 {
position: relative;
display: inline-block;
width: 50%;
font-size: 6em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
margin-top: -1%;
}
.item-2 {
animation-name: anim-2;
margin-top: -12%;
}
.item-3 {
animation-name: anim-3;
margin-top: -13%;
}
#keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 33.33% { left: -100%; opacity: 0; }
41.63%, 58.29% { left: 25%; opacity: 1; }
66.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 66.66% { left: -100%; opacity: 0; }
74.96%, 91.62% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<div class="divider3">
<p class="item-1">"Super fast service and clean environment!" <br /> - John Anderson, GA</p>
<p class="item-2">"Plans have changed and I had to have a conference room within an hour and ThanksOffice was perfect for it!" <br /> - Ashley Green, CA</p>
<p class="item-3">"Very professional and satisfies every need." <br /> - Sam Smith, NJ</p>
</div>
You can use position:absolute on the p elements and use a vertical centering solution which involves using top:50% and transform:translateY(-50%). This means you don't have to add a unique margin-top to every p element.
I also added position:relative to the .divider3 element so the p tags are positioned relative to that container.
NOTE: I noticed in another answer you said you don't want to use position:absolute. You will have to use position:absolute to take the element out of the natural document flow. Otherwise using position:relative the p tags will stack on top of each other and you will be constantly battling with CSS to adjust their vertical positioning. The more p tags you add it will get progressively harder to compensate for their vertical positioning, because they will get pushed further and further down the page.
.divider3 {
background-image: url("images/people.png");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #b6b6b6;
height: 300px;
margin: 0 auto;
position:relative;
overflow:hidden;
}
.divider3 p {
color: #FFFFFF;
font-size: 20px;
text-align: center;
line-height: 25px;
letter-spacing: 1px;
top:50%;
transform:translateY(-50%);
margin:0;
}
.item-1, .item-2, .item-3 {
position: absolute;
display: inline-block;
width: 50%;
font-size: 6em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
}
.item-2 {
animation-name: anim-2;
}
.item-3 {
animation-name: anim-3;
}
#keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 33.33% { left: -100%; opacity: 0; }
41.63%, 58.29% { left: 25%; opacity: 1; }
66.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 66.66% { left: -100%; opacity: 0; }
74.96%, 91.62% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<div class="divider3">
<p class="item-1">"Super fast service and clean environment!" <br /> - John Anderson, GA</p>
<p class="item-2">"Plans have changed and I had to have a conference room within an hour and ThanksOffice was perfect for it!" <br /> - Ashley Green, CA</p>
<p class="item-3">"Very professional and satisfies every need." <br /> - Sam Smith, NJ</p>
</div>
These all are paragraphs, so they're appearing just below the preceding one.
You can change their position to be absolute.
I don't know why margin-top isn't working, so I removed them.
The code in action is this:
.divider3 {
background-image: url("images/people.png");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #b6b6b6;
height: 300px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
.divider3 p {
color: #FFFFFF;
font-size: 20px;
text-align: center;
line-height: 25px;
letter-spacing: 1px;
padding-top: 8%;
}
.item-1, .item-2, .item-3 {
position: absolute;
display: inline-block;
width: 50%;
font-size: 6em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
}
.item-2 {
animation-name: anim-2;
}
.item-3 {
animation-name: anim-3;
}
#keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 33.33% { left: -100%; opacity: 0; }
41.63%, 58.29% { left: 25%; opacity: 1; }
66.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 66.66% { left: -100%; opacity: 0; }
74.96%, 91.62% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<div class="divider3">
<p class="item-1">"Super fast service and clean environment!" <br /> - John Anderson, GA</p>
<p class="item-2">"Plans have changed and I had to have a conference room within an hour and ThanksOffice was perfect for it!" <br /> - Ashley Green, CA</p>
<p class="item-3">"Very professional and satisfies every need." <br /> - Sam Smith, NJ</p>
</div>
.divider3 {
background-image: url("images/people.png");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #b6b6b6;
height: 300px;
margin: 0 auto;
}
.divider3 p {
color: #FFFFFF;
font-size: 20px;
text-align: center;
line-height: 25px;
letter-spacing: 1px;
padding-top: 8%;
position: absolute;
top: 5em;
}
.item-1, .item-2, .item-3 {
position: relative;
display: inline-block;
width: 50%;
font-size: 6em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
}
.item-2 {
animation-name: anim-2;
}
.item-3 {
animation-name: anim-3;
}
#keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 33.33% { left: -100%; opacity: 0; }
41.63%, 58.29% { left: 25%; opacity: 1; }
66.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 66.66% { left: -100%; opacity: 0; }
74.96%, 91.62% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
Related
I have loader designed and I positioned it to center with top:0 left:0 z:10 and text-align:center. Its not positioning to center of the page. I also added a text called Loading But its's not showing up.
#container-sleftpinner {
background: #ffffff;
color: #666666;
position: fixed;
height: 100%;
width: 100%;
z-index: 10;
top: 0;
left: 0;
text-align: center;
opacity: .80;
}
.loader,
.loader:before,
.loader:after {
background: grey;
-webkit-animation: load1 1s infinite ease-in-out;
animation: load1 1s infinite ease-in-out;
width: 1em;
height: 4em;
}
.loader {
color: grey;
background-repeat: no-repeat;
background-position: center;
position: fixed;
display: block;
left: 0;
right: 0;
top: 0;
bottom: 0;
text-indent: -9999em;
margin: 88px auto;
position: relative;
font-size: 11px;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
.loader:before,
.loader:after {
position: absolute;
top: 0;
content: '';
}
.loader:before {
left: -1.5em;
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.loader:after {
left: 1.5em;
}
.loader p {
position: absolute;
left: 0;
right: 0;
bottom: 50%;
display: inline-block;
text-align: center;
margin-bottom: -5em;
}
#-webkit-keyframes load1 {
0%,
80%,
100% {
box-shadow: 0 0;
height: 4em;
}
40% {
box-shadow: 0 -2em;
height: 5em;
}
}
#keyframes load1 {
0%,
80%,
100% {
box-shadow: 0 0;
height: 4em;
}
40% {
box-shadow: 0 -2em;
height: 5em;
}
}
<div id="container-spinner" style="display:block;">
<div class="loader">
<p>Loading...</p>
</div>
</div>
Based upon your code.
give the .container-spinner class the following and the content will center.
I changed the display to be flex and made sure to give it hight:100vh to fill the page and all that left is to center it vertically and horizontally using justify-content and align-items ( don't forget to remove the inline style to get this to work)
.container-spinner {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
Edit
based upon your request. Here is the working code with the text showing up and all the changes to the HTML and CSS.
.container-spinner {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
height: 100vh;
}
#container-sleftpinner {
background: #ffffff;
color: #666666;
position: fixed;
height: 100%;
width: 100%;
z-index: 10;
top: 0;
left: 0;
text-align: center;
opacity: 0.8;
}
.loader,
.loader:before,
.loader:after {
background: grey;
-webkit-animation: load1 1s infinite ease-in-out;
animation: load1 1s infinite ease-in-out;
width: 1em;
height: 4em;
}
.loader {
color: grey;
background-repeat: no-repeat;
background-position: center;
text-indent: -9999em;
margin: 10px auto;
font-size: 11px;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
.loader:before,
.loader:after {
position: absolute;
top: 0;
content: "";
}
.loader:before {
left: -1.5em;
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.loader:after {
left: 1.5em;
}
.container-spinner p {
text-align: center;
}
#-webkit-keyframes load1 {
0%,
80%,
100% {
box-shadow: 0 0;
height: 4em;
}
40% {
box-shadow: 0 -2em;
height: 5em;
}
}
#keyframes load1 {
0%,
80%,
100% {
box-shadow: 0 0;
height: 4em;
}
40% {
box-shadow: 0 -2em;
height: 5em;
}
}
<div class="container-spinner">
<div class="loader">
</div>
<p>Loading...</p>
</div>
If that doesn't work please let me know.
I have a simple 3 text I want to add slide down effect of these text here is what I have so far jsfiddle demo
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
}
.item-2 {
animation-name: anim-2;
}
.item-3 {
animation-name: anim-3;
}
#keyframes anim-1 {
0%,
8.3% {
left: -100%;
opacity: 0;
}
8.3%,
25% {
left: 25%;
opacity: 1;
}
33.33%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-2 {
0%,
33.33% {
left: -100%;
opacity: 0;
}
41.63%,
58.29% {
left: 25%;
opacity: 1;
}
66.66%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-3 {
0%,
66.66% {
left: -100%;
opacity: 0;
}
74.96%,
91.62% {
left: 25%;
opacity: 1;
}
100% {
left: 110%;
opacity: 0;
}
}
<p class="item-1">Fast.</p>
<p class="item-2">Slow</p>
<p class="item-3">Much slow</p>
I have a simple 3 text I want to add slide down effect of these text here is what I have so far jsfiddle
The result I want can be seen in this page if you look at the title named video made sample
For now it just slides right, I want a slide down effect
Just replace left with top?
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1 {
animation-name: anim-1;
}
.item-2 {
animation-name: anim-2;
}
.item-3 {
animation-name: anim-3;
}
#keyframes anim-1 {
0%,
8.3% {
top: -100%;
opacity: 0;
}
8.3%,
25% {
top: 25%;
opacity: 1;
}
33.33%,
100% {
top: 110%;
opacity: 0;
}
}
#keyframes anim-2 {
0%,
33.33% {
top: -100%;
opacity: 0;
}
41.63%,
58.29% {
top: 25%;
opacity: 1;
}
66.66%,
100% {
top: 110%;
opacity: 0;
}
}
#keyframes anim-3 {
0%,
66.66% {
top: -100%;
opacity: 0;
}
74.96%,
91.62% {
top: 25%;
opacity: 1;
}
100% {
top: 110%;
opacity: 0;
}
}
<p class="item-1">Fast.</p>
<p class="item-2">Slow</p>
<p class="item-3">Much slow</p>
I'm trying to animate my logo using css, what I want is each logo fade in from top then stop in a certain point, then fade out to bottom, but couldn't make this, is this possible?
.logo {
width: 50px;
height: 50px;
background: whitesmoke;
transform: rotate(45deg);
position: absolute;
border-radius: 5px;
border: 2px solid white;
}
#logo {
width: 500px;
height: 500px;
margin: auto;
margin-top: 100px;
position: relative;
}
#logo-1 {
top: 0px;
animation: loading3 4s linear infinite normal;
}
#logo-2 {
top: -10px;
animation: loading2 3s linear infinite normal;
}
#logo-3 {
top: -20px;
animation: loading1 2s linear infinite normal;
}
#keyframes loading1 {
0% {background: white;opacity: 0;top: -120px;}
50% {background:#f44;opacity: 1;top: -50px;}
65% {background:#f44;opacity: 1;top: -20px;}
75% {background:#f44;opacity: 1;top: -20px;}
100% {background: white;opacity: 0;top: 50px;}
}
#keyframes loading2 {
0% {background: white;opacity: 0;top: -120px;}
50% {background:#f44;opacity: 1;top: -50px;}
65% {background:#f44;opacity: 1;top: -10px;}
75% {background:#f44;opacity: 1;top: -10px;}
100% {background: white;opacity: 0;top: 50px;}
}
#keyframes loading3 {
0% {background: white;opacity: 0;top: -120px;}
50% {background:#f44;opacity: 1;top: -50px;}
65% {background:#f44;opacity: 1;top: 0px;}
75% {background:#f44;opacity: 1;top: 0px;}
100% {background: white;opacity: 0;top: 50px;}
}
<div id="logo">
<div class="logo" id="logo-1"></div>
<div class="logo" id="logo-2"></div>
<div class="logo" id="logo-3"></div>
</div>
Note: logo-3 should come first and stop, then logo-2 come and stop,
then logo-1 come and stop then logo-3 should go first, then logo-2
then logo-1, one by one.
Original logo is:
There is no way to stop a CSS animation in-between and then continue, hence i have used little JavaScript.
What we do is, we divide all three animations into two portions, the first one for all three runs and then the second one. I have divided animations and then activate those animations using classes with JavaScript. This solution is not complex, it's just lengthy.
function animateLogo() {
logo1 = document.getElementById('logo-1');
logo2 = document.getElementById('logo-2');
logo3 = document.getElementById('logo-3');
if(logo1.classList.contains('anim31')) {
logo1.classList.remove('anim31');
logo1.classList.add('anim32');
} else {
logo1.classList.add('anim31');
logo1.classList.remove('anim32');
}
if(logo2.classList.contains('anim21')) {
logo2.classList.remove('anim21');
logo2.classList.add('anim22');
} else {
logo2.classList.add('anim21');
logo2.classList.remove('anim22');
}
if(logo3.classList.contains('anim11')) {
logo3.classList.remove('anim11');
logo3.classList.add('anim12');
} else {
logo3.classList.add('anim11');
logo3.classList.remove('anim12');
}
}
setInterval(animateLogo, 3000); // The time is the amount of milliseconds our longest animation will take i.e 3s
.logo {
width: 50px;
height: 50px;
background: whitesmoke;
transform: rotate(45deg);
position: absolute;
border-radius: 5px;
border: 2px solid white;
}
#logo {
width: 500px;
height: 500px;
margin: auto;
margin-top: 100px;
position: relative;
}
#logo-1 {
top: 0px;
}
#logo-1.anim31 {
animation: loading31 3s linear forwards normal;
}
#logo-1.anim32 {
animation: loading32 1s linear forwards normal;
}
#keyframes loading31 {
0% {
background: white;
opacity: 0;
top: -120px;
}
65% {
background: #f44;
opacity: 1;
top: -50px;
}
75% {
top: -50px;
}
100% {
background: #f44;
opacity: 1;
top: 0px;
}
}
#keyframes loading32 {
0% {
background: #f44;
opacity: 1;
top: 0px;
}
65% {
background: #f44;
opacity: 1;
top: 0px;
}
100% {
background: white;
opacity: 0;
top: 50px;
}
}
#logo-2 {
top: -10px;
}
#logo-2.anim21 {
animation: loading21 2s linear forwards normal;
}
#logo-2.anim22 {
animation: loading22 2s linear forwards normal;
}
#keyframes loading21 {
0% {
background: white;
opacity: 0;
top: -120px;
}
65% {
background: #f44;
opacity: 1;
top: -50px;
}
75% {
top: -50px;
}
100% {
background: #f44;
opacity: 1;
top: -10px;
}
}
#keyframes loading22 {
0% {
background: #f44;
opacity: 1;
top: -10px;
}
65% {
background: #f44;
opacity: 1;
top: -10px;
}
100% {
background: white;
opacity: 0;
top: 50px;
}
}
#logo-3 {
top: -20px;
}
#logo-3.anim11 {
animation: loading11 1s linear forwards normal;
}
#logo-3.anim12 {
animation: loading12 3s linear forwards normal;
}
#keyframes loading11 {
0% {
background: white;
opacity: 0;
top: -120px;
}
65% {
background: #f44;
opacity: 1;
top: -50px;
}
75% {
top: -50px;
}
100% {
background: #f44;
opacity: 1;
top: -20px;
}
}
#keyframes loading12 {
0% {
background: #f44;
opacity: 1;
top: -20px;
}
65% {
background: #f44;
opacity: 1;
top: -20px;
}
100% {
background: white;
opacity: 0;
top: 50px;
}
}
<body>
<div id="logo">
<div class="logo anim31" id="logo-1"></div>
<div class="logo anim21" id="logo-2"></div>
<div class="logo anim11" id="logo-3"></div>
</div>
</body>
I hope this is the expected result. If not, please comment below and i will edit the answer.
P.S: Play around with the timing of animations to make it faster/slower.
I am trying to adapt a pen from codepen that i found but it doesn't seem to work. The pen is a text slider with 3 slides and my goal is to make it work with 6 slides.
The original codepen is this
My pen is this
The problem that i think it is is that i got the percentage wrong in my code. My code for 6 slides is
#keyframes anim-1 {
0%,
4.15% {
left: -100%;
opacity: 0;
}
4.15%,
12.45% {
left: 25%;
opacity: 1;
}
16.66%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-2 {
0%,
16.66% {
left: -100%;
opacity: 0;
}
20.75%,
29.17% {
left: 25%;
opacity: 1;
}
33.32%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-3 {
0%,
33.32% {
left: -100%;
opacity: 0;
}
37.47%,
45.83% {
left: 25%;
opacity: 1;
}
49.98%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-4 {
0%,
49.98% {
left: -100%;
opacity: 0;
}
54.13%,
62.43% {
left: 25%;
opacity: 1;
}
66.58%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-5 {
0%,
66.58% {
left: -100%;
opacity: 0;
}
70.73%,
79.03% {
left: 25%;
opacity: 1;
}
83.18%,
100% {
left: 110%;
opacity: 0;
}
}
#keyframes anim-6 {
0%,
83.18% {
left: -100%;
opacity: 0;
}
87.33%,
95.85% {
left: 25%;
opacity: 1;
}
100% {
left: 110%;
opacity: 0;
}
}
I messed up the indentation here in this post but everything should be clearer in the codepen.
I don't think that i made any typos and i am still thinkin what could cause this.
In your CSS, you're not separating the different classes with a comma. Add these, and it will work.
Your Code
.item-1,
.item-2,
.item-3
.item-4
.item-5
.item-6 {
...
The Fix
.item-1,
.item-2,
.item-3,
.item-4,
.item-5,
.item-6 {
...
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3,
.item-4,
.item-5,
.item-6{
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
.item-3{
animation-name: anim-3;
}
.item-4{
animation-name: anim-4;
}
.item-5{
animation-name: anim-5;
}
.item-6{
animation-name: anim-6;
}
#keyframes anim-1 {
0%, 4.15% { left: -100%; opacity: 0; }
4.15%, 12.45% { left: 25%; opacity: 1; }
16.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 16.66% { left: -100%; opacity: 0; }
20.75%, 29.17% { left: 25%; opacity: 1; }
33.32%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 33.32% { left: -100%; opacity: 0; }
37.47%, 45.83% { left: 25%; opacity: 1; }
49.98%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-4 {
0%, 49.98% { left: -100%; opacity: 0; }
54.13%, 62.43% { left: 25%; opacity: 1; }
66.58%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-5 {
0%, 66.58% { left: -100%; opacity: 0; }
70.73%, 79.03% { left: 25%; opacity: 1; }
83.18%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-6 {
0%, 83.18% { left: -100%; opacity: 0; }
87.33%, 95.85% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>
<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>
<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-4">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-5">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-6">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
JSFiddle
I found a snippet that I want to use for my website. The Snippet is a Text Slider with 3 Boxes. You can see it here:
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
.item-3{
animation-name: anim-3;
}
#keyframes anim-1 {
0%, 8.3% { left: -100%; opacity: 0; }
8.3%,25% { left: 25%; opacity: 1; }
33.33%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 33.33% { left: -100%; opacity: 0; }
41.63%, 58.29% { left: 25%; opacity: 1; }
66.66%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 66.66% { left: -100%; opacity: 0; }
74.96%, 91.62% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>
<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>
<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
But for my Project i need 4 textboxes. I tryed to adust the script, but I have on error which I don't understand why. If I add another textbox, adjust the class of the textbox, edit the css and adjust the timings of the textboxes, the slide effect is working well until the last (the new added) slide comes up. Then the first line shows up, even if the last slide is not finished. Can anyobody help me to find out what I am doing wrong?
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3,
.item-4 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
.item-3{
animation-name: anim-3;
}
.item-4{
animation-name: anim-4;
}
#keyframes anim-1 {
0%, 6.5% { left: -100%; opacity: 0; }
6.5%,18.5% { left: 25%; opacity: 1; }
25%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 25% { left: -100%; opacity: 0; }
31.5%, 43.5% { left: 25%; opacity: 1; }
50%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75% { left: 110%; opacity: 0; }
}
#keyframes anim-4 {
0%, 75% { left: -100%; opacity: 0; }
81.5%, 93.5% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>
<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>
<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-4">Lorum Ipsum Dolor Sit Amet. Lorum Ipsum Dolor Sit Amet.</p>
Greetings
The problem there is define the animation steps, if You look to the CSS there is one keyframe defined with percentage, how to split the animation. Like:
#keyframes anim {
0%, 6.5% { left: -100%; opacity: 0; }
6.5%,18.5% { left: 25%; opacity: 1; }
25%, 100% { left: 110%; opacity: 0; }
}
The percentage at the start of line is saying:
Go from FIRST VALUE to SECOND VALUE and end there (follow by next line).
If You look at keyframe 3, You haven't defined the latest value in percentage, so if You add it, it will work well. Full code below.
From:
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75% { left: 110%; opacity: 0; }
}
To:
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75%, 100% { left: 110%; opacity: 0; }
}
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3,
.item-4 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
.item-3{
animation-name: anim-3;
}
.item-4{
animation-name: anim-4;
}
#keyframes anim-1 {
0%, 6.5% { left: -100%; opacity: 0; }
6.5%,18.5% { left: 25%; opacity: 1; }
25%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 25% { left: -100%; opacity: 0; }
31.5%, 43.5% { left: 25%; opacity: 1; }
50%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-4 {
0%, 75% { left: -100%; opacity: 0; }
81.5%, 93.5% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>
<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>
<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-4">Lorum Ipsum Dolor Sit Amet. Lorum Ipsum Dolor Sit Amet.</p>
Small change in your code. You missed second params in anim-3 keyframes to remove this text from screen
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75%, 100% { left: 110%; opacity: 0; }
}
#import url(https://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', 'sans-serif';
color: #cecece;
background: #222;
overflow: hidden;
}
.item-1,
.item-2,
.item-3,
.item-4 {
position: absolute;
display: block;
top: 2em;
width: 60%;
font-size: 2em;
animation-duration: 20s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
.item-1{
animation-name: anim-1;
}
.item-2{
animation-name: anim-2;
}
.item-3{
animation-name: anim-3;
}
.item-4{
animation-name: anim-4;
}
#keyframes anim-1 {
0%, 6.5% { left: -100%; opacity: 0; }
6.5%,18.5% { left: 25%; opacity: 1; }
25%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-2 {
0%, 25% { left: -100%; opacity: 0; }
31.5%, 43.5% { left: 25%; opacity: 1; }
50%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-3 {
0%, 50% { left: -100%; opacity: 0; }
56.5%, 68.5% { left: 25%; opacity: 1; }
75%, 100% { left: 110%; opacity: 0; }
}
#keyframes anim-4 {
0%, 75% { left: -100%; opacity: 0; }
81.5%, 93.5% { left: 25%; opacity: 1; }
100% { left: 110%; opacity: 0; }
}
<p class="item-1">This is your last chance. After this, there is no turning back.</p>
<p class="item-2">You take the blue pill - the story ends, you wake up in your bed and believe whatever you want to believe.</p>
<p class="item-3">You take the red pill - you stay in Wonderland and I show you how deep the rabbit-hole goes.</p>
<p class="item-4">Lorum Ipsum Dolor Sit Amet. Lorum Ipsum Dolor Sit Amet.</p>