CSS hover, transition effect in the same direction
up vote
-1
down vote
favorite
I am doing some basic CSS fill transitions on hover. I have used this codepen as an example: https://codepen.io/brandon4117/pen/ihIgE. Now on hover the background position raises to fill the div, and on hover off, the background goes back down. I wanted to know how can I modify this pen, to work such as when hover off the transition should go upwards, rather than down.
Most hover transitions: Hover on new fill top->bottom. Hover off new fill removes bottom->top. I would like to do on hover fill top->bottom, on hover off fill removes top->bottom again.
A look at the CSS being used:
div {border-style: solid;
border-color: black;
color: black;
padding: 50px;
background-size: 200% 200%;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position:0 100%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
div:hover {color: white;
border-color: #A72424;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position: 0 0%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
a {color: black; text-decoration: none;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;}
a:hover {color: white;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;
}
a:active {color: white;}
Thanks
html css html5 css-transitions
add a comment |
up vote
-1
down vote
favorite
I am doing some basic CSS fill transitions on hover. I have used this codepen as an example: https://codepen.io/brandon4117/pen/ihIgE. Now on hover the background position raises to fill the div, and on hover off, the background goes back down. I wanted to know how can I modify this pen, to work such as when hover off the transition should go upwards, rather than down.
Most hover transitions: Hover on new fill top->bottom. Hover off new fill removes bottom->top. I would like to do on hover fill top->bottom, on hover off fill removes top->bottom again.
A look at the CSS being used:
div {border-style: solid;
border-color: black;
color: black;
padding: 50px;
background-size: 200% 200%;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position:0 100%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
div:hover {color: white;
border-color: #A72424;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position: 0 0%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
a {color: black; text-decoration: none;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;}
a:hover {color: white;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;
}
a:active {color: white;}
Thanks
html css html5 css-transitions
Play withlinear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck
– tera_789
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
transition
doesn't have a reverse value, likeanimation
has, so to accomplish such transition effect you either need to combine it with a script, or useanimation
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am doing some basic CSS fill transitions on hover. I have used this codepen as an example: https://codepen.io/brandon4117/pen/ihIgE. Now on hover the background position raises to fill the div, and on hover off, the background goes back down. I wanted to know how can I modify this pen, to work such as when hover off the transition should go upwards, rather than down.
Most hover transitions: Hover on new fill top->bottom. Hover off new fill removes bottom->top. I would like to do on hover fill top->bottom, on hover off fill removes top->bottom again.
A look at the CSS being used:
div {border-style: solid;
border-color: black;
color: black;
padding: 50px;
background-size: 200% 200%;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position:0 100%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
div:hover {color: white;
border-color: #A72424;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position: 0 0%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
a {color: black; text-decoration: none;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;}
a:hover {color: white;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;
}
a:active {color: white;}
Thanks
html css html5 css-transitions
I am doing some basic CSS fill transitions on hover. I have used this codepen as an example: https://codepen.io/brandon4117/pen/ihIgE. Now on hover the background position raises to fill the div, and on hover off, the background goes back down. I wanted to know how can I modify this pen, to work such as when hover off the transition should go upwards, rather than down.
Most hover transitions: Hover on new fill top->bottom. Hover off new fill removes bottom->top. I would like to do on hover fill top->bottom, on hover off fill removes top->bottom again.
A look at the CSS being used:
div {border-style: solid;
border-color: black;
color: black;
padding: 50px;
background-size: 200% 200%;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position:0 100%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
div:hover {color: white;
border-color: #A72424;
background-image:
linear-gradient(to top, #A72424 50%, transparent 50%);
background-position: 0 0%;
-webkit-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-moz-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-ms-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
-o-transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
transition: background-position 300ms, color 300ms ease, border-color 300ms ease;
}
a {color: black; text-decoration: none;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;}
a:hover {color: white;
transition: all 100ms linear;
-webkit-transition: all 100ms linear;
-moz-transition: all 100ms linear;
-ms-transition: all 100ms linear;
-o-transition: all 100ms linear;
}
a:active {color: white;}
Thanks
html css html5 css-transitions
html css html5 css-transitions
edited 2 days ago
asked 2 days ago
balaji sreenivas
12
12
Play withlinear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck
– tera_789
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
transition
doesn't have a reverse value, likeanimation
has, so to accomplish such transition effect you either need to combine it with a script, or useanimation
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago
add a comment |
Play withlinear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck
– tera_789
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
transition
doesn't have a reverse value, likeanimation
has, so to accomplish such transition effect you either need to combine it with a script, or useanimation
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago
Play with
linear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck– tera_789
2 days ago
Play with
linear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck– tera_789
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
transition
doesn't have a reverse value, like animation
has, so to accomplish such transition effect you either need to combine it with a script, or use animation
– LGSon
2 days ago
transition
doesn't have a reverse value, like animation
has, so to accomplish such transition effect you either need to combine it with a script, or use animation
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
i think it's easier to make this effect with a :before or a :after pseudo element instead of using the background if you're not using self closing tags.
div { padding: 50px; border: 2px solid #000; color: #000; position: relative; transition: 0.3s ease; }
div:after { content: ""; height: 0; width: 100%; background-color: #A72424; position: absolute; top: 0; left: 0; transition: 0.3s ease; }
div:hover { color: #fff; border-color: #A72424; }
div:hover:after { height: 100%; }
in case you need to use the linear gradient you just need to change the linear-gradient direction into "to bottom" instead of "to top"
div { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
div:hover { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
New contributor
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
add a comment |
up vote
-1
down vote
Ok I got the answer: For top down do this:
.divclass::after {
position: absolute;
transition: 0.3s;
content: '';
height: 0;
top: 50%;
right: 0;
width: 3px;
background: #fff;
bottom: 0;
top: auto;
z-index: -1;
width: 120%;
}
.divclass:hover::after {
height: 100%;
top: 0;
}
Thanks for pointing me in the direction of pseudos Frderico
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
i think it's easier to make this effect with a :before or a :after pseudo element instead of using the background if you're not using self closing tags.
div { padding: 50px; border: 2px solid #000; color: #000; position: relative; transition: 0.3s ease; }
div:after { content: ""; height: 0; width: 100%; background-color: #A72424; position: absolute; top: 0; left: 0; transition: 0.3s ease; }
div:hover { color: #fff; border-color: #A72424; }
div:hover:after { height: 100%; }
in case you need to use the linear gradient you just need to change the linear-gradient direction into "to bottom" instead of "to top"
div { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
div:hover { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
New contributor
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
add a comment |
up vote
0
down vote
i think it's easier to make this effect with a :before or a :after pseudo element instead of using the background if you're not using self closing tags.
div { padding: 50px; border: 2px solid #000; color: #000; position: relative; transition: 0.3s ease; }
div:after { content: ""; height: 0; width: 100%; background-color: #A72424; position: absolute; top: 0; left: 0; transition: 0.3s ease; }
div:hover { color: #fff; border-color: #A72424; }
div:hover:after { height: 100%; }
in case you need to use the linear gradient you just need to change the linear-gradient direction into "to bottom" instead of "to top"
div { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
div:hover { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
New contributor
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
i think it's easier to make this effect with a :before or a :after pseudo element instead of using the background if you're not using self closing tags.
div { padding: 50px; border: 2px solid #000; color: #000; position: relative; transition: 0.3s ease; }
div:after { content: ""; height: 0; width: 100%; background-color: #A72424; position: absolute; top: 0; left: 0; transition: 0.3s ease; }
div:hover { color: #fff; border-color: #A72424; }
div:hover:after { height: 100%; }
in case you need to use the linear gradient you just need to change the linear-gradient direction into "to bottom" instead of "to top"
div { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
div:hover { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
New contributor
i think it's easier to make this effect with a :before or a :after pseudo element instead of using the background if you're not using self closing tags.
div { padding: 50px; border: 2px solid #000; color: #000; position: relative; transition: 0.3s ease; }
div:after { content: ""; height: 0; width: 100%; background-color: #A72424; position: absolute; top: 0; left: 0; transition: 0.3s ease; }
div:hover { color: #fff; border-color: #A72424; }
div:hover:after { height: 100%; }
in case you need to use the linear gradient you just need to change the linear-gradient direction into "to bottom" instead of "to top"
div { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
div:hover { background-image: linear-gradient(to bottom, #A72424 50%, transparent 50%); }
New contributor
New contributor
answered 2 days ago
Federico Pasquarelli
1
1
New contributor
New contributor
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
add a comment |
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
Thank you for responding to my query, Your code reverses the direction of the transition which is good, but what I am looking for is: Let's say my div has a background color white, on hover we are filling the div with a color black, direction of transition is top->bottom. Now when I remove the mouse from the element the white color will transition from bottom->top. I want this transition to be from top -> bottom. Hope I am clear.
– balaji sreenivas
2 days ago
add a comment |
up vote
-1
down vote
Ok I got the answer: For top down do this:
.divclass::after {
position: absolute;
transition: 0.3s;
content: '';
height: 0;
top: 50%;
right: 0;
width: 3px;
background: #fff;
bottom: 0;
top: auto;
z-index: -1;
width: 120%;
}
.divclass:hover::after {
height: 100%;
top: 0;
}
Thanks for pointing me in the direction of pseudos Frderico
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
add a comment |
up vote
-1
down vote
Ok I got the answer: For top down do this:
.divclass::after {
position: absolute;
transition: 0.3s;
content: '';
height: 0;
top: 50%;
right: 0;
width: 3px;
background: #fff;
bottom: 0;
top: auto;
z-index: -1;
width: 120%;
}
.divclass:hover::after {
height: 100%;
top: 0;
}
Thanks for pointing me in the direction of pseudos Frderico
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
add a comment |
up vote
-1
down vote
up vote
-1
down vote
Ok I got the answer: For top down do this:
.divclass::after {
position: absolute;
transition: 0.3s;
content: '';
height: 0;
top: 50%;
right: 0;
width: 3px;
background: #fff;
bottom: 0;
top: auto;
z-index: -1;
width: 120%;
}
.divclass:hover::after {
height: 100%;
top: 0;
}
Thanks for pointing me in the direction of pseudos Frderico
Ok I got the answer: For top down do this:
.divclass::after {
position: absolute;
transition: 0.3s;
content: '';
height: 0;
top: 50%;
right: 0;
width: 3px;
background: #fff;
bottom: 0;
top: auto;
z-index: -1;
width: 120%;
}
.divclass:hover::after {
height: 100%;
top: 0;
}
Thanks for pointing me in the direction of pseudos Frderico
answered 2 days ago
balaji sreenivas
12
12
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
add a comment |
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
Provide a proper code sample both at the question and the answer, that explains and shows, with a working code snippet, it all works, as with the existing, it is difficult to see how it can.
– LGSon
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184037%2fcss-hover-transition-effect-in-the-same-direction%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Play with
linear-gradient
first of all...You should try something yourself first - this is how SO works. You show what you did, and people help you improve your work. Good luck– tera_789
2 days ago
Thanks for your response, my question is that there are two states: 1) On hover where I have some background-position and the original background-position which is what our control will default to on hover off. How can I get the transition in the same direction as the fill on hover?
– balaji sreenivas
2 days ago
transition
doesn't have a reverse value, likeanimation
has, so to accomplish such transition effect you either need to combine it with a script, or useanimation
– LGSon
2 days ago
There might be some options using a couple of extra child elements, or the pseudo elements.
– LGSon
2 days ago
Also take a look at this: w3schools.com/w3css/w3css_animate.asp They have some pretty cool stuff, which is very easy to implement. It might not be exactly what you are looking for, but still...
– tera_789
2 days ago