I have a problem with CSS that I am trying to solve and at this point I need your help.
I have a #keyframes animation that changes the width of a class which have overflow hidden.
The animation has 9 frames and it is working perfectly at this point.
//the working code
h1.imgholder { // This is the object that will animate.
overflow: hidden;
height: 90px;
width: 415px;
margin-left: 46%;
-webkit-animation-name: example; // animation name
-webkit-animation-duration: 3.5s; //animation duration
animation-name: example; // animation name
animation-duration: 3.5s; //animation duration
}
.img {
float: left;
}
#-webkit-keyframes example {
0% {
width: 85px;
-webkit-animation-timing-function: linear;
}
24.51% {
width: 85px;
-webkit-animation-timing-function: linear;
}
25% {
width: 195px;
-webkit-animation-timing-function: linear;
}
49.51% {
width: 195px;
-webkit-animation-timing-function: linear;
}
50% {
width: 295px;
-webkit-animation-timing-function: linear;
}
74.51% {
width: 295px;
-webkit-animation-timing-function: linear;
}
75% {
width: 322px;
-webkit-animation-timing-function: linear;
}
99.51% {
width: 322px;
-webkit-animation-timing-function: linear;
}
100% {
width: 415px;
-webkit-animation-timing-function: linear;
}
}
Now what I want is that at some frames to add another animation property like border-right: solid #000;
Like at frame 1, 3, 5, 7, 9 = no border, frame 2, 4, 6, 8 = border-right: solid #000;
//code here for example "tried this, didn't work"
#-webkit-keyframes example {
0% {
width: 85px;
-webkit-animation-timing-function: linear;
}
24.51% {
width: 85px;
border-right: solid #000; //show border
-webkit-animation-timing-function: linear;
}
25% {
width: 195px;
-webkit-animation-timing-function: linear;
}
49.51% {
width: 195px;
border-right: solid #000; //show border
-webkit-animation-timing-function: linear;
}
50% {
width: 295px;
-webkit-animation-timing-function: linear;
}
74.51% {
width: 295px;
border-right: solid #000; //show border
-webkit-animation-timing-function: linear;
}
75% {
width: 322px;
-webkit-animation-timing-function: linear;
}
99.51% {
width: 322px;
border-right: solid #000; //show border
-webkit-animation-timing-function: linear;
}
100% {
width: 415px;
-webkit-animation-timing-function: linear;
}
}
What am I doing wrong? How can I make this class that it will show border on specific frames, and remove or "hide" them on other frames.
Any help is appreciated, thanks for your time and sorry for my bad english :p.
I can't quite figure out why it works this way but the animation seems to work well only when you set the border-right on the parent element. As you can see in the below snippet, once that is done the rest of your code works fine.
Also, based on your statement remove or "hide" them on other frames, you may want to consider adding a border-right: none in the other frames because once a property is added in one frame it doesn't go away unless removed. I have added both versions in the snippet for the difference to be visible.
h1.imgholder {
overflow: hidden;
height: 90px;
width: 415px;
-webkit-animation-name: example;
-webkit-animation-duration: 3.5s;
-webkit-animation-timing-function: linear;
animation-name: example;
animation-duration: 3.5s;
animation-timing-function: linear;
border-right: 1px solid transparent;
}
.img {
float: left;
}
#-webkit-keyframes example {
0% {
width: 85px;
}
24.51% {
width: 85px;
border-right: 1px solid #000;
}
25% {
width: 195px;
}
49.51% {
width: 195px;
border-right: 1px solid #000;
}
50% {
width: 295px;
}
74.51% {
width: 295px;
border-right: 1px solid #000;
}
75% {
width: 322px;
}
99.51% {
width: 322px;
border-right: 1px solid #000;
}
100% {
width: 415px;
}
}
/* Just for demo */
h1.imgholder#two{
-webkit-animation-name: example2;
-webkit-animation-duration: 3.5s;
-webkit-animation-timing-function: linear;
animation-name: example2;
animation-duration: 3.5s;
animation-timing-function: linear;
border-right: 1px solid transparent;
}
#-webkit-keyframes example2 {
0% {
width: 85px;
border-right: none;
}
24.51% {
width: 85px;
border-right: 1px solid #000;
}
25% {
width: 195px;
border-right: none;
}
49.51% {
width: 195px;
border-right: 1px solid #000;
}
50% {
width: 295px;
border-right: none;
}
74.51% {
width: 295px;
border-right: 1px solid #000;
}
75% {
width: 322px;
border-right: none;
}
99.51% {
width: 322px;
border-right: 1px solid #000;
}
100% {
width: 415px;
border-right: none;
}
}
<h1 class="imgholder">
<img src="http://lorempixel.com/100/100" alt="" class='img'>
</h1>
<!-- Just for demo -->
<h1 class="imgholder" id ='two'>
<img src="http://lorempixel.com/100/100" alt="" class='img'>
</h1>
Related
i tried to make this animation so it would pause when i hover on it but every time i do, only the div get paused and the pesudo elements don't so what did i do wrong?
i tried to change the property like making the background color change with hover and it works! so it seems that the problem is something related to the animation but i can't get my hand on it
This is my Css
.task1 {
/* box-sizing: border-box; */
width: 50px;
height: 50px;
margin: 50px auto;
border: #fca900 solid 5px;
border-left: transparent solid 5px;
border-radius: 50%;
position: relative;
-webkit-animation: rotate linear infinite 1s;
animation: rotate linear infinite 1s;
}
.task1::after {
content: "";
width: 70%;
height: 70%;
position: absolute;
top: 2.5px;
left: 2.5px;
border: #2090db solid 5px;
border-top: transparent solid 5px;
border-radius: 50%;
-webkit-animation: rotate linear infinite 1s;
animation: rotate linear infinite 1s;
}
.task1::before {
content: "";
width: 40%;
height: 40%;
position: absolute;
top: 10px;
left: 10px;
border: #e51758 solid 5px;
border-right: transparent solid 5px;
border-radius: 50%;
-webkit-animation: rotate linear infinite 1s;
animation: rotate linear infinite 1s;
}
#-webkit-keyframes rotate {
to {
transform: rotate(1turn);
}
}
#keyframes rotate {
to {
transform: rotate(1turn);
}
}
.task1:hover {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
<div class="task1"></div>
The pseudo elements are styled independently so you need to pause their animations on task1 being hovered as well.
.task1 {
/* box-sizing: border-box; */
width: 50px;
height: 50px;
margin: 50px auto;
border: #fca900 solid 5px;
border-left: transparent solid 5px;
border-radius: 50%;
position: relative;
-webkit-animation: rotate linear infinite 1s;
animation: rotate linear infinite 1s;
}
.task1::after {
content: "";
width: 70%;
height: 70%;
position: absolute;
top: 2.5px;
left: 2.5px;
border: #2090db solid 5px;
border-top: transparent solid 5px;
border-radius: 50%;
animation: rotate linear infinite 1s;
}
.task1::before {
content: "";
width: 40%;
height: 40%;
position: absolute;
top: 10px;
left: 10px;
border: #e51758 solid 5px;
border-right: transparent solid 5px;
border-radius: 50%;
animation: rotate linear infinite 1s;
}
#keyframes rotate {
to {
transform: rotate(1turn);
}
}
.task1:hover,
.task1:hover::after,
.task1:hover::before {
animation-play-state: paused;
}
<div class="task1"></div>
it's happening because you are only pausing task1 not it's pesudos just do this change to your code
.task1::before, .task1::after, .task1:hover {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
This question already has answers here:
How to have css3 animation to loop forever
(3 answers)
Closed 2 years ago.
Having this html/css snippet:
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation-name: example;
animation-duration: 4s;
}
#keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
<div class="triangle-four"></div>
I want to make it run infinitely and tried to do it like this:
animation-duration: 4s infinite;
It doesn't work, the animation is not working anymore even thought this is what is recommended to do on w3schools.
Any ideas?
I remove animation-name: example; animation-duration: 4s; and add this animation: example 5s infinite; it will fix your problem.
another solution it just to add this without removing anything :
animation-iteration-count: infinite;
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation: example 5s infinite;
}
#keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
}
<div class="triangle-four"></div>
On the link provided, it says that the animation property is a shorthand for multiple animation properties.
You have to specify the animation-name and the animation-duration. You may then add the animation-iteration-count.
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation: 4s example infinite;
}
#keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
<div class="triangle-four"></div>
just add
animation-iteration-count: infinite;
it will solve the issue
Adding the following css should fix it:
animation-duration: 4s;
animation-iteration-count: infinite;
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
#keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
<div class="triangle-four"></div>
Of course, the end of the animation "jumps" to red, but that is the effect described by your animation. If that was not intended, you can simply add this css:
animation-direction: alternate;
I'm trying to make this div move smoothly while changing colors, but the problem is that right before it should transition into the #bad455 color, it stops briefly.
So I was wondering are there any ways to make it go smoothly without no stopping?
div {
background-color: black;
width: 300px;
height: 300px;
margin: 0 auto;
}
div:hover {
animation-name: anim1;
animation-duration: 3s;
}
#keyframes anim1 {
0% {
background-color: pink;
margin-top: 10px;
}
50% {
background-color: yellow;
margin-top: 20px;
}
100% {
background-color: #bad455;
margin-top: 30px;
}
}
<div></div>
You set the iteration count to infinite so your animation keeps going and set the margin of your last keyframe back to 0 so it returns to it's default state.
div {
background-color: black;
width: 300px;
height: 300px;
margin: 0 auto;
}
div:hover {
animation-name: anim1;
animation-iteration-count: infinite;
animation-duration: 3s;
}
#keyframes anim1 {
0% {
background-color: pink;
margin-top: 10px;
}
50% {
background-color: yellow;
margin-top: 30px;
}
100% {
background-color: #bad455;
margin-top: 0px;
}
}
<div></div>
Try this in your div tag:
-webkit-transition: width 2s;
transition: width 2s;
This is my code:
html
<div id="back">
<div id="right_text">TEST</div>
<div id="left_text">TEST2</div>
</div>
<div id="mid"></div>
css
#mid {
border: 1px solid black;
height: 100px;
width: 100px;
-webkit-animation: rotate linear 5s;
-webkit-animation-iteration-count: infinite;
margin:auto;
margin-top:-125px;
position: static;
}
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
#back {
width:auto;
height: 150px;
border: 1px solid red;
-webkit-animation: rotateY linear 5s;
-webkit-animation-iteration-count: infinite;
position: static;
}
#-webkit-keyframes rotateY {
from {
-webkit-transform: rotateY(0deg)
}
to {
-webkit-transform: rotateY(360deg)
}
}
#right_text {
border: 1px solid green;
height: 75px;
width: 75px;
float: right;
margin-top: 35px;
text-align: center;
}
#left_text {
border: 1px solid green;
height: 75px;
width: 75px;
float: left;
margin-top: 35px;
text-align: center;
}
http://jsfiddle.net/bXhL8/
As you can see, both text-divs face their back to the screen when they are not on their side of origin. i want both of them to always stay the same and just "hang on" to the rotation of my back-div.
my question would be if that is possible in css alone or if id need js for it.
Add the following to your css
#left_text, #right_text {
-webkit-animation: rotateY linear 5s;
-webkit-animation-iteration-count: infinite;
}
JSFiddle
Update
Updated JSFiddle
here is my new bit of code. its not a perfect circle yet, because i just added 4 frames to my #keyframes. im thinking about making a actual circular rotation and adding a skew() element to the whole circular function / to my whole body, don't know if that will work though.
thanks for your help!
html:
<div id="right_text">
<div id="right_text_text">TEST</div>
</div>
<div id="left_text">
<div id="left_text_text">TEST2</div>
</div>
<div id="mid"></div>
css:
#mid {
border: 1px solid black;
background-color: red;
height: 100px;
width: 100px;
-webkit-animation: rotate linear 5s;
-webkit-animation-iteration-count: infinite;
margin-top: 105px;
margin-left: 210px;
position: static;
}
#-webkit-keyframes rotate {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(-360deg);
}
}
#right_text_text {
border: 1px solid black;
text-align: center;
position: absolute;
width: 50px;
-webkit-animation: downupright linear 8s infinite;
}
#left_text_text {
border: 1px solid black;
text-align: center;
position: absolute;
width: 50px;
-webkit-animation: updownleft linear 8s infinite;
}
#-webkit-keyframes downupright {
0% { left: 490px; top: 150px;}
25% { left: 245px; top: 100px; z-index: -10;}
50% { left: 0px; top: 150px;}
75% { left: 245px; top: 200px; z-index:10;}
100% { left: 490px; top: 150px;}
}
#-webkit-keyframes updownleft {
0% { left: 0px; top: 150px;}
25% { left: 245px; top: 200px; z-index: 9;}
50% { left: 490px; top: 150px;}
75% { left: 245px; top: 100px; z-index: -9;}
100% { left: 0px; top: 150px;}
}
http://jsfiddle.net/bXhL8/4/
I have this HTML:
<div id="container">
<div id="content">
<h2 class="frame1">Loriam Ipisum</h2>
<h2 class="frame2">Loriam Ipisumsad</h2>
</div>
</div>
And this CSS:
body{margin: 0; padding: 0;}
#container{
width: 100%;
top: 200px;
border: 1px solid black;
text-align: center;
position: relative;
overflow: hidden;
}
#content{
width: 300px;
height: 50px;
border: 1px solid blue;
position: relative;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
#content h2{
position: relative;
display: inline-block;
}
#content h2.frame1{
-webkit-animation-delay: 0s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
#content h2.frame2{
-webkit-animation-delay: 3s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
}
#-webkit-keyframes efeito1{
0%{
left: 0;
opacity: 0;
}
50%{
opacity: 0.4;
left: 100px;
opacity: 0.4;
left: 200;
}
100%{
opacity: 0;
left: 300px;
opacity: 0.4;
}
}
What I want to do is: I want both .frames be at the same LINE. SO when I apply the animation, it will happen at the same place, giving a nice effect. I want them to be at the same line, at the same place but without one text be upon the other looking like a mess...
I tried to use the overflow: Hidden: but didn't work, the texts stays one above the other...
I want to apply, this effect: http://codepen.io/anon/pen/LcwKj/
Any suggestion? Thanks !
Is this effect what you are aiming for:
HTML
<div id="container">
<div id="content">
<h2 class="frame1">Loriam Ipisum</h2>
<h2 class="frame2">sad</h2>
</div>
</div>
CSS
body{margin: 0; padding: 0;}
#container{
width: 100%;
top: 200px;
border: 1px solid black;
text-align: center;
position: relative;
overflow: hidden;
}
#content{
width: 100%;
height: 50px;
border: 1px solid blue;
position: relative;
margin-left: auto;
margin-right: auto;
overflow: hidden;
}
#content h2{
position: absolute;
display: inline-block;
}
#content h2.frame1{
-webkit-animation-delay: 0s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 4s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
opacity:0;
}
#content h2.frame2{
-webkit-animation-delay: 3s;
-webkit-animation-name: efeito1;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: linear;
-webkit-animation-direction: alternate;
opacity:0;
position:absolute;
}
#-webkit-keyframes efeito1{
0%{
opacity: 0;
}
100%{
opacity: 100;
}
}