On hover, how to override an existing animation style? - html

See the snippet below. Notice when you hover over an item, the item's background color changes but the transform: translateY(-5px) is being ignored. The hover's transform style only works if the .list-item animation is not set.
How can I get the translateY(-5px) on hover to work in the code?
.list {
display: flex;
flex-direction: column;
align-items: center;
margin: 24px 0;
}
.list-item {
cursor: pointer;
margin-bottom: 14px;
padding: 12px 16px;
border-radius: 50px;
background: #EFEFEF;
animation-name: popin;
animation-fill-mode: both;
animation-duration: .6s;
animation-iteration-count: 1;
animation-timing-function: ease;
animation-delay: 0.1s;
}
.list-item:hover {
background-color: yellow;
transform: translateY(-5px);
}
#keyframes popin {
0%{
transform:scale(0);
}
50%{
transform:scale(1.1);
}
100%{
transform:scale(1);
}
}
<div class="list">
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
</div>
UPDATE
I also need to have a transition when the translation is done.

Remove the last state from the animation since it's the default one and you will be able to override the transform. Basically the animation will consider the state of the element as the 100% and when you change it on hover it will also change in the animation.
If a 100% or to keyframe is not specified, then the user agent constructs a 100% keyframe using the computed values of the properties being animated.ref
.list {
display: flex;
flex-direction: column;
align-items: center;
margin: 24px 0;
}
.list-item {
cursor: pointer;
margin-bottom: 14px;
padding: 12px 16px;
border-radius: 50px;
background: #EFEFEF;
animation-name: popin;
animation-fill-mode:both;
animation-duration: .6s;
/*animation-iteration-count: 1; also not needed */
animation-timing-function: ease;
animation-delay: 0.1s;
}
.list-item:hover {
background-color: yellow;
transform: translateY(-5px);
}
#keyframes popin {
0%{
transform:scale(0);
}
50%{
transform:scale(1.1);
}
}
<div class="list">
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
</div>
UPDATE
if you want the transition you can adjust the code slightly to be able to have two elements where it would be easy to apply transform independently:
.list {
display: flex;
flex-direction: column;
align-items: center;
margin: 24px 0;
}
.list-item {
cursor: pointer;
margin-bottom: 14px;
animation-name: popin;
animation-fill-mode:both;
animation-duration: .6s;
animation-timing-function: ease;
animation-delay: 0.1s;
}
.list-item:before {
content:attr(data-text);
display:block;
padding: 12px 16px;
border-radius: 50px;
background: #EFEFEF;
transition:1s all;
}
.list-item:hover:before {
background-color: yellow;
transform: translateY(-5px);
}
#keyframes popin {
0%{
transform:scale(0);
}
50%{
transform:scale(1.1);
}
}
<div class="list">
<div class="list-item" data-text="item"></div>
<div class="list-item" data-text="item"></div>
<div class="list-item" data-text="item"></div>
<div class="list-item" data-text="item"></div>
<div class="list-item" data-text="item"></div>
<div class="list-item" data-text="item"></div>
</div>
You can also consider an extra wrapper like below:
.list {
display: flex;
flex-direction: column;
align-items: center;
margin: 24px 0;
}
.list-item {
cursor: pointer;
margin-bottom: 14px;
animation-name: popin;
animation-fill-mode:both;
animation-duration: .6s;
animation-timing-function: ease;
animation-delay: 0.1s;
}
.list-item > div {
padding: 12px 16px;
border-radius: 50px;
background: #EFEFEF;
transition:1s all;
}
.list-item:hover > div {
background-color: yellow;
transform: translateY(-5px);
}
#keyframes popin {
0%{
transform:scale(0);
}
50%{
transform:scale(1.1);
}
}
<div class="list">
<div class="list-item"><div>item</div></div>
<div class="list-item"><div>item</div></div>
<div class="list-item"><div>item</div></div>
<div class="list-item"><div>item</div></div>
<div class="list-item"><div>item</div></div>
<div class="list-item"><div>item</div></div>
</div>

I was actually facing a similar problem the other day. I can't tell you why it behaves like this but I can tell you how I solved it. I created another animation and activated it on hover. I used animation-fill-mode: forwards so the animation would only go back to its initial state after you hover somewhere else.
Give it a try and let me know what you think.
.list {
display: flex;
flex-direction: column;
align-items: center;
margin: 24px 0;
}
.list-item {
cursor: pointer;
margin-bottom: 14px;
padding: 12px 16px;
border-radius: 50px;
border-color: black;
border: 1px solid black;
background: #EFEFEF;
animation-name: popin;
animation-fill-mode: both;
animation-duration: .6s;
animation-iteration-count: 1;
animation-timing-function: ease;
animation-delay: 0.1s;
}
.list-item:hover {
animation: pull-up 0.3s ease-in-out forwards;
background-color: yellow;
}
#keyframes popin {
0%{
transform:scale(0);
}
50%{
transform:scale(1.1);
}
100%{
transform:scale(1);
}
}
#keyframes pull-up {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-5px);
}
}
<div class="list">
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
<div class="list-item">item</div>
</div>

Related

Three Circle Object is not rotate 360degree

Please see the code below.
.nk-loader-c {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.nk-loader-circle {
transform-origin: bottom center;
animation: obj-rotate 3s linear infinite;
height: 36px;
}
.obj-circle {
display: inline-block;
background-color: #6540eb;
height: 20px;
width: 20px;
border-radius: 50%;
transform: scale(0);
animation: obj-grow 1.5s linear infinite;
margin: -5px;
}
.obj-circle:nth-child(1) {
background-color: #3766f3;
animation-delay: 1.5s;
}
.obj-circle:nth-child(2) {
background-color: #603aef;
animation-delay: .75s;
}
.obj-circle:nth-child(3) {
background-color: #2998f6;
animation-delay: .37s;
}
#keyframes obj-rotate {
to{
transform: rotate(360deg);
}
}
#keyframes obj-grow {
50% {
transform: scale(1);
}
}
<div class="nk-loader-c">
<div class="nk-loader-circle">
<div class="obj-circle"></div>
<div class="obj-circle"></div>
<div class="obj-circle"></div>
</div>
</div>
Can anyone help me with this? the rotation of the object circle is not
really 360degrees. Can anyone help me how can I make the rotation
360deg?
But when I tried using two circles the rotation if working on 360degress.
What about this?
.nk-loader-c {
padding-top: 50px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.nk-loader-circle {
position:absolute;
transform-origin: bottom center;
animation: obj-rotate 3s linear infinite;
height: 36px;
}
.obj-circle {
display: inline-block;
background-color: #6540eb;
height: 20px;
width: 20px;
border-radius: 50%;
transform: scale(0);
animation: obj-grow 1.5s linear infinite;
margin: -5px;
}
.nk-loader-circle:nth-child(1){
animation-delay: -0.5s;
}
.nk-loader-circle:nth-child(1) .obj-circle{
background-color: #3766f3;
animation-delay: 1.5s;
}
.nk-loader-circle:nth-child(2){
animation-delay: -.25s;
}
.nk-loader-circle:nth-child(2) .obj-circle{
background-color: #603aef;
animation-delay: .75s;
}
.nk-loader-circle:nth-child(3) {
animation-delay: 0s;
}
.nk-loader-circle:nth-child(3) .obj-circle{
background-color: #2998f6;
animation-delay: .37s;
}
#keyframes obj-rotate {
to {
transform: rotate(360deg);
}
}
#keyframes obj-grow {
50% {
transform: scale(1);
}
}
<div class="nk-loader-c">
<div class="nk-loader-circle">
<div class="obj-circle"></div>
</div>
<div class="nk-loader-circle">
<div class="obj-circle"></div>
</div>
<div class="nk-loader-circle">
<div class="obj-circle"></div>
</div>
</div>
</div>

Triggering a transition mid-animation CSS

Been trying to trigger a transition using :hover in a running animation using CSS, in the example below, only the background-color changes on :hover but the transform property is triggered only after an animation stops. How can I trigger the transform: rotate during the animation?
Also, my initial background-color: red seems to fade-in when I reload the page without me explicitly triggering it by :hover. I assume it's caused by the transition-duration, can this be avoided using only CSS?
.container {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.red {
width: 100px;
height: 100px;
background-color: red;
animation-name: animation;
animation-duration: 5s;
animation-delay: 0;
animation-timing-function: ease-in-out;
animation-direction: alternate;
transition-duration: 5s;
transition-property: all;
}
.red:hover {
transform: rotate(180deg);
background-color: teal;
}
#keyframes animation {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="container">
<div class="red"></div>
</div>
</body>
Transforms do not stack in this way. One way to work around this limitation could be to use a parent element for the rotation transform.
.container {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.red {
width: 100px;
height: 100px;
background-color: red;
animation-name: animation;
animation-duration: 5s;
animation-delay: 0;
animation-timing-function: ease-in-out;
animation-direction: alternate;
transition-duration: 5s;
transition-property: all;
}
.red:hover {
background-color: teal;
}
.wrap {
transition: all 5s;
}
.wrap:hover {
transform: rotate(180deg);
}
#keyframes animation {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="container">
<div class="wrap">
<div class="red"></div>
</div>
</div>
</body>

css animation help needed

So I am Pretty new to programming and I just started with html, css, JavaScript and a bit of php. I've tried to make a dropdown menu with animations. It works prety god but now i want to add "reverse" animations for the menu Options but i can't get it to work without playing the "fade out" Animation when the Options are loaded. I hope my Problem is clear enought and I'm Looking Forward to find someone who can help me out with my problem. ps: I'm german so sorry for grammar mistakes ;)
index.html:
<html>
<link rel="stylesheet" href="/templates/simplyblu_j1.5/css/template.css"/>
<head>
<title>Stephen's Site</title>
</head>
<body>
<div id="menu1"><font color="c079da">Instagram</font></div>
<div id="menu2"><font color="da5148">Youtube</font></div>
<div id="menu3"><font color="68b9e1">Twitter</font></div>
<div id="menu4"><font color="000">Menutest V2</font></div>
<div id="bild1"></div>
<div id="link1"><font color=000">Menutest V1</font></div>
<!-- <div class="dropdown">
<div class="dropdown-button">
Menu
</div>
<ul>
<li>Spalte 1</li>
<li>Spalte 2</li>
<li>Spalte 3</li>
<li>Spalte 4</li>
</ul>
</div>
-->
<div id="credit1"><font color="d97757--">Made by Stephen Scholz</font></div>
</body>
</html>
"menutest.html"(where the Dropdown items are in):
<html>
<link rel="stylesheet" href="/templates/simplyblu_j1.5/css/template3.css"/>
<head>
<title>Stephen's Site</title>
</head>
<body>
<div class="dropdown">
<div class="dropdown-button">
Menu</div>
<ul class="opt">
<li><font color="000"<div id="opt1">Hauptseite</font></li>
<li><font color="000"<div id="opt2">Hauptseite2</font></li>
<li><font color="000"<div id="opt3">Hauptseite3</font></li>
<li><font color="000"<div id="opt4">Hauptseite4</font></li>
</ul>
</div>
<div id="credit1"><font color="d97757--">Made by Stephen Scholz</font></div>
</body>
</html>
template3.css (css file for Dropdown menu) :
background-image: url(../images/background.png);
margin: 0px;
padding: 0px;
font-size: 14px;
background-color: #F9EBAE;
background-repeat: repeat-x;
}
#credit1 {
font-size: 25px;
width: 100px;
height: 100px;
margin-left: 5px;
margin-top: 3400px;
border: 3px solid #cfcecf;
}
.dropdown{
margin: 0 auto;
margin-top: 50px;
width: 150px;
}
.dropdown-button {
padding: 10px;
background: white;
}
.dropdown-button a{
color: #333;
text-decoration: none;
*border: 3px solid #cfcecf;
}
.dropdown ul{
list-style-type: none;
background: white;
*border: 3px solid #cfcecf;
animation: load 1s forwards;
}
.dropdown ul li{
margin-top: 0px;
padding: 10px 5px;
*background: white;
display: none;
opacity: 0;
animation: load 1s forwards
}
.dropdown:hover li{
animation: load 0.3s forwards;
display: block;
}
#keyframes load {
0%{
transform: scale(0) translateX(100px) rotate(-45deg);
}
100%{
opacity: 1;
transform: scale(1) translateX(0px) rotate(0);
/*box-shadow: 0px 0px 10px black;*/
}
0%{
transform: scale(0) translateX(100px) rotate(-45deg);
}
}
#opt1:hover {
animation: opt 0.5s forwards;
display: block;
}
#opt2:hover {
animation: opt 0.5s forwards;
display: block;
}
#opt3:hover {
animation: opt 0.5s forwards;
display: block;
}
#opt4:hover {
animation: opt 0.5s forwards;
display: block;
}
#keyframes opt{
0%{
transform: scale(1);
}
100%{
transform: scale(1.4);
}
}
#opt1 {
animation: optout 1s forwards;
display: block;
}
#opt2 {
animation: optout 1s forwards;
display: block;
}
#opt3 {
animation: optout 1s forwards;
display: block;
}
#opt4 {
animation: optout 1s forwards;
display: block;
}
#keyframes optout {
0%{
transform: scale(1.4);
}
100%{
transform: scale(1);
}
}```

Div transform and rotate animations in React.js/html/css

I want to animate the divs in HTML and CSS as shown in the videoPlease find Video here. I had tried something but it is not working as my divs have 2 types of animation at a time. Please help with it. Thanks in advance.
My code snippet is -
<div className="container">
<div className="content">R</div>
<div className="content">E</div>
<div className="content">D</div>
<div className="content">B</div>
<div className="content">O</div>
<div className="content">O</div>
<div className="content">K</div>
</div>
And CSS file is -
div.container {
height: 200px;
border: 2px solid #ddd;
padding: 5px;
display: inline-block;
}
div.stone {
height: 20px;
width: 20px;
border: 1px solid #bbb;
border-radius: 4px;
display: inline-block;
float: left;
margin-left: 5px;
color: white;
padding: 10px;
text-align: center;
font-size: 18px;
background-color: #fa7878;
-webkit-animation: spin 1s linear;
-moz-animation: spin 1s linear;
animation: spin 1s linear;
}
#-moz-keyframes spin {
0% {
-moz-transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
10% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
div.stone:first-child {
// sepatrate animation code
}

How to fix a Div position from moving when another changes height dynamically

I have a 'bouncing loader' div, in which moves up and down on an infinite loop (see this jsfiddle
However, if I place a button below it, (or anything else for that matter), it will also move in time to the animation effect.
Is there anyway of stopping this button from moving?
I have tried adding margins/padding on both, but they didn't work so I removed them.
the loader html:
<div class="loader" style="float:initial;">
<span></span>
<span></span>
<span></span>
</div>
<br />
<div>
<button id="popupArea">Click here to invoke a popup window</button>
</div>
with the css being:
.loader {
text-align: center;
}
.loader span {
display: inline-block;
vertical-align: middle;
width: 10px;
height: 10px;
margin: 50px auto;
background: black;
border-radius: 50px;
-webkit-animation: loader 0.9s infinite alternate;
-moz-animation: loader 0.9s infinite alternate;
}
.loader span:nth-of-type(2) {
-webkit-animation-delay: 0.3s;
-moz-animation-delay: 0.3s;
}
.loader span:nth-of-type(3) {
-webkit-animation-delay: 0.6s;
-moz-animation-delay: 0.6s;
}
#-webkit-keyframes loader {
0% {
width: 10px;
height: 10px;
opacity: 0.9;
-webkit-transform: translateY(0);
}
100% {
width: 24px;
height: 24px;
opacity: 0.1;
-webkit-transform: translateY(-21px);
}
}
#-moz-keyframes loader {
0% {
width: 10px;
height: 10px;
opacity: 0.9;
-moz-transform: translateY(0);
}
100% {
width: 24px;
height: 24px;
opacity: 0.1;
-moz-transform: translateY(-21px);
}
}
As always, any help/advice is welcomed.
Please note, I'm don't know jquery, so would like to avoid it as much as possible (hence i'm using asp MVC)
Just add the following css attribute:
#popupArea {
position:fixed;
top:100px;//you can change the value as you wish
}
Example here.
try like this
.loader {
text-align: center;
}
.loader span {
display: inline-block;
vertical-align: middle;
width: 10px;
height: 10px;
margin: 50px auto;
background: black;
border-radius: 50px;
-webkit-animation: loader 0.9s infinite alternate;
-moz-animation: loader 0.9s infinite alternate;
}
.loader span:nth-of-type(2) {
-webkit-animation-delay: 0.3s;
-moz-animation-delay: 0.3s;
}
.loader span:nth-of-type(3) {
-webkit-animation-delay: 0.6s;
-moz-animation-delay: 0.6s;
}
#-webkit-keyframes loader {
0% {
width: 10px;
height: 10px;
opacity: 0.9;
-webkit-transform: translateY(0);
}
100% {
width: 24px;
height: 24px;
opacity: 0.1;
-webkit-transform: translateY(-21px);
}
}
#-moz-keyframes loader {
0% {
width: 10px;
height: 10px;
opacity: 0.9;
-moz-transform: translateY(0);
}
100% {
width: 24px;
height: 24px;
opacity: 0.1;
-moz-transform: translateY(-21px);
}
}
<div class="loader" style="height:100px;">
<span></span>
<span></span>
<span></span>
</div>
<br />
<div>
<button id="popupArea">Click here to invoke a popup window</button>
</div>
Try to put height at loader's div .
.loader {
text-align: center;
height:85px;
}
http://jsfiddle.net/csdtesting/9emc9so9/4/
Simple, just set the height for the span
Set height: 100px; in the loader
.loader {
text-align: center;
height:100px;
}
Here is a DEMO