CSS: Background fills on hover from bottom to top: - html

please take a look at this example:
https://www.outsideonline.com/2317131/wilma-rudolph-worlds-fastest-woman
Note that when you hover over link, the background animated to fill the anchor text from bottom to top, and clears is from top to bottom when you hover away from it.
I've done something similar with my own website. The relevant CSS for it:
a {
box-shadow: inset 0 -3px 0 -1px #FFF986;
-webkit-transition: box-shadow .15s ease-in-out;
transition: box-shadow .15s ease-in-out;
color: black;
}
a:hover {
box-shadow: inset 0 -3px 0 40px #FFF986;
-webkit-transition: box-shadow .15s ease-in-out;
transition: box-shadow .15s ease-in-out;
}
This gives me a similar effect, but instead of filling from top to bottom like in the example link: The background starts to fill from all sides of the rectangle toward to center.
How do I force it to fill from top to bottom, like in the example link I shared? what am I missing?

You're changing wrong parameter:
a:hover {
box-shadow: inset 0 -40px 0 -1px #FFF986;
a {
box-shadow: inset 0 -3px 0 -1px #FFF986;
transition: box-shadow .15s ease-in-out;
color: black;
line-height: 40px;
}
a:hover {
box-shadow: inset 0 -40px 0 -1px #FFF986;
}
Hey Mickey!

Another solution that uses a 50%/50% linear gradient resized to 200%. To animate the background change the background position:
a {
background-image: linear-gradient(to top, yellow 50%, transparent 50%);
background-size: 100% 200%;
background-position: top;
transition: background-position 0.5s ease-in-out; /** I've changed the time for demo purposes **/
color: black;
}
a:hover {
background-position: bottom;
}
I'm a link
I'm another link

a {
box-shadow: inset 0 -3px 0 -1px #FFF986;
transition: box-shadow .15s ease-in-out;
color: black;
line-height: 40px;
}
a:hover {
box-shadow: inset 0 -40px 0 -1px #FFF986;
}
Hey Mickey!

Related

Background, hover and transition - Why it doesn't work? [duplicate]

This question already has answers here:
Use CSS3 transitions with gradient backgrounds
(19 answers)
Closed 1 year ago.
I'm trying to add a transition to a button I have that's background is made with css linear-gradient but it's not working.
This is the css for my button.
a.button
{
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#green), color-stop(100%,#a5c956));
-webkit-transition: background 5s linear;
}
a.button:hover
{
-webkit-gradient(linear, left top, left bottom, color-stop(0%,#greenhover), color-stop(100%,#89af37))
}
If you're wondering about #green and #greenhover, I'm using .less to make my css.
Anything wrong with this? Any ideas?
Sadly, you really can't transition gradients for now.
So, the only workable workaround is using an extra element with needed gradient and transition it's opacity:
a.button {
position: relative;
z-index: 9;
display: inline-block;
padding: 0 10px;
background: -webkit-gradient(linear, 0 0, 0 100%, from(green), to(#a5c956));
background: -webkit-linear-gradient(top, green, #a5c956);
background: -moz-linear-gradient(top, green, #a5c956);
background: -o-linear-gradient(top, green, #a5c956);
background: linear-gradient(top, green, #a5c956);
}
.button-helper {
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
background: -webkit-gradient(linear, 0 0, 0 100%, from(lime), to(#89af37));
background: -webkit-linear-gradient(top, lime, #89af37);
background: -moz-linear-gradient(top, lime, #89af37);
background: -o-linear-gradient(top, lime, #89af37);
background: linear-gradient(top, lime, #89af37);
-webkit-transition: opacity 1s linear;
-moz-transition: opacity 1s linear;
-o-transition: opacity 1s linear;
transition: opacity 1s linear;
}
a.button:hover .button-helper {
opacity: 1;
}
<span class="button-helper"></span>button
it's tricky.. and of course tricky is cool ;)
okay.. i got a solution. and it's basically done via amazing :before selector
#cool-hover{
width: 120px;
height: 120px;
display: block;
cursor: pointer;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0,0,0,0.3);
margin: 0px auto 24px auto;
transition: all 0.5s;
position: relative;
overflow: hidden;
}
#cool-hover:before{
border-radius: inherit;
display: block;
width: 200%;
height: 200%;
content: '';
position: absolute;
top: 0;
left: 0;
background: linear-gradient(135deg, #21d4fd 25%, #b721ff 75%);
transition: all 0.5s;
transform: translate(-25%, -25%);
z-index: 0;
}
#cool-hover:after{
border-radius: 9px;
display: block;
width: 108px;
height: 108px;
margin: 6px;
background: url('https://i.imgur.com/w0BjFgr.png');
background-size: cover;
content: '';
position: absolute;
top: 0; left: 0;
z-index: 1;
}
#cool-hover:hover:before{
transform: translate(-25%, -25%) rotate(-180deg);
}
#cool-hover:hover{
box-shadow: 0 0 35px rgba(0,0,0,0.3);
}
<div id="cool-hover"></div>
NOTE : i just added the :after sudo class just for the small on top image placeholder purpose..
have a nice awesome styling ;)
I know this pretty old but I could not find any good solution yet. So here is my solution
First Make gradient on ":before and hide it with opacity then transition opacity 1 on hover.
https://jsfiddle.net/sumon380/osqLpboc/3/
.button {
text-decoration: none;
padding: 10px 25px;
font-size: 20px;
color: #333;
display: inline-block;
background: #d6e9eb;
position: relative;
z-index: 1;
transition: color 0.3s ease-out;
}
.button:before {
background: #91a5f4;
background: linear-gradient(135deg, #91a5f4 0%, #b08cf9 86%);
content: "";
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
z-index: -1;
opacity: 0;
transition: opacity 0.3s ease-out;
}
.button:hover:before {
opacity: 1;
}
.button:hover {
color: #fff;
}
<a class="button" href="#">Button</a>
You can fake gradient transitions using drop shadows!
For instance, from one of my pages:
c {
color: #FFF;
background: #000;
border-style:solid;
border-color:#CCC;
border-width: 0 0 0 1px;
box-shadow: 2px 2px 2px #555, inset 0 25px 20px -10px rgba(255, 255, 255, 0.3),
inset 0 -15px 20px -10px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 2px 2px 2px #555, inset 0 25px 20px -10px rgba(255, 255, 255, 0.3),
inset 0 -15px 20px -10px rgba(0, 0, 0, 0.15);
-o-box-shadow: 2px 2px 2px #555, inset 0 25px 20px -10px rgba(255, 255, 255, 0.3),
inset 0 -15px 20px -10px rgba(0, 0, 0, 0.15);
-webkit-box-shadow: 2px 2px 2px #555,
inset 0 25px 20px -10px rgba(255, 255, 255, 0.3),
inset 0 -15px 20px -10px rgba(0, 0, 0, 0.15);
-moz-transition: background-color .5s ease;
-o-transition: background-color .5s ease;
-webkit-transition: background-color .5s ease-in-out;
transition: background-color .5s ease;
}
Followed by:
c:hover {
color:#FFF;
background: #505;
position:relative;
top:1px;
box-shadow: -1px -1px -1px #555,inset 0 20px 20px -10px rgba(0, 0, 0, 0.15),
inset 0 -15px 20px -10px rgba(255, 255, 255, 0.3);
-moz-box-shadow: -1px -1px -1px #555,inset 0 20px 20px -10px rgba(0, 0, 0, 0.15),
inset 0 -15px 20px -10px rgba(255, 255, 255, 0.3);
-o-box-shadow: -1px -1px -1px #555, inset 0 20px 20px -10px rgba(0, 0, 0, 0.15),
inset 0 -15px 20px -10px rgba(255, 255, 255, 0.3);
-webkit-box-shadow: 1px -1px -1px #555, inset 0 20px 20px -10px rgba(0, 0, 0, 0.15),
inset 0 -15px 20px -10px rgba(255, 255, 255, 0.3);
}
Here, you are essentially using an inset shadow as a Photoshop-like mask, causing a gradient effect on the underlying element. On hover, you invert the effect.
If you're doing the slight highlight when hovering the button there is a much simpler solution. You can just nudge the gradient down a bit and have the background-color be the same as the top color of your gradient: http://cdpn.io/oaByI
It's pretty limited I know, but if works well for that use case.
I know this question is pretty old, but I found a good way to animate basic gradients that will work in some cases.
This method will let you animate a change in color of the gradient but not a change in the position of the color stops.
https://jsfiddle.net/62vzydeh/
HTML:
<div class="button">
Click Me!
</div>
CSS:
.button {
width: 200px;
height: 30px;
margin: 50px;
padding-top: 10px;
color: #C0C0C0;
background: linear-gradient(to left, #F8F8F8, transparent 30%);
background-color: #808080;
text-align: center;
font-family: sans-serif;
cursor: pointer;
transition: background-color 500ms;
}
.button:hover {
background-color: #A0A0A0;
}
a hacky way i tried was putting lots of <spans> to replicate "position", CSS only hack here: https://codepen.io/philipphilip/pen/OvXEaV
9 years, but this time, hope my styled-components can help someone:
import React, { ReactNode } from 'react'
import { Button as ButtonUI } from "#your-library-ui"
import styled from 'styled-components'
type Props = {
onClick?: () => void;
children?: ReactNode;
};
const Button = ({onClick, children}: Props) => (
<StyledButton onClick={onClick} >
{children}
<ButtonHelper />
</StyledButton>
)
export default Button
const ButtonHelper = styled.span`
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
border-radius: 5px;
background: linear-gradient(to right, #5ab0f4, #1273ea)!important;
transition: opacity 0.2s linear;
`;
const StyledButton = styled(ButtonUI)`
position: relative;
z-index: 1;
background: linear-gradient(to right, #1273ea, #1c94f4)!important;
color: #fff;
&:hover ${ButtonHelper} {
opacity: 1;
}
`;
And start using your new designed component with extra effect! Thanks to #kizu for the suggestion.
you must have same style in source and changed style in target.
like
a {
background: transparent;
background: linear-gradient(transparent,transparent);
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
a:hover
{
background: #abc07c;
background: linear-gradient(#c5db95,#88a743);
}

Box-Shadow not carrying out Transition

I know this may be a dupe, but I'm willing to take the hit as I feel confident I have researched multiple solutions.
I have tried many methods to get This box-shadow transition to work, including:
Switching between hex, rgb, and rgba colors in the box-shadow declaration.
Using selectors with more specificity.
Changing the the transition property to include ease-in-out at the end of the declaration.
I cleansed the CSS file of any transition properties that could possibly effect the element.
All the while, triple checking my spelling mistakes.
The inspector says my styles are not being overridden. Here is my code:
.site-header .genesis-nav-menu .menu-item a {
-webkit-box-shadow: 3px 3px 14px rgb(0,0,0) inset;
-moz-box-shadow: 3px 3px 14px rgb(0,0,0) inset;
-o-box-shadow: 3px 3px 14px rgb(0,0,0) inset;
box-shadow: 3px 3px 14px rgb(0,0,0) inset;
-webkit-transition: box-shadow 3s;
-moz-transition: box-shadow 3s;
-o-transition: box-shadow 3s;
transition: box-shadow 3s;
}
.site-header .genesis-nav-menu .menu-item a:hover{
-webkit-box-shadow: 3px 3px 14px rgb(0,0,0);
-moz-box-shadow: 3px 3px 14px rgb(0,0,0);
-o-box-shadow: 3px 3px 14px rgb(0,0,0);
box-shadow: 3px 3px 14px rgb(0,0,0);
}
What could be happening here to cause this to do nothing?
Here is a link to my site for an in context experience. It's the header menu in the top right corner of the page.
Try:
.site-header .genesis-nav-menu .menu-item a {
-webkit-box-shadow: 0 0 0 rgba(0,0,0,0), 3px 3px 14px rgb(0,0,0) inset;
transition: box-shadow 3s;
}
.site-header .genesis-nav-menu .menu-item a:hover {
box-shadow: 3px 3px 14px rgb(0,0,0), 0 0 0 rgba(0,0,0, 0) inset;
}
Use transition: all; instead of box-shadow, should fix your issue

CSS transition doesn't work

section#lBox{
background-color: rgb(168, 0, 0);
border: 1px solid rgba(0,0,0,.15);
border-radius: 0px;
box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 0 4px rgba(0,0,0,0.2);
margin: 100px auto; /*aligns center*/
padding: 24px;
width: 500px;
opacity: 0.5;
-webkit-transition: all 5s linear;
transition: background-color 5s;
-moz-transition: all 5s linear;
}
section#lbox:hover {
/*background-color: rgba(168, 0, 0, 0.8);
box-shadow: 0px 0px 500px; */
opacity: 0.8;
}
I have been trying to fix it for half an hour and can't seem to find why the transition isn't working. It is supposed to make the translucent box more opaque when the mouse cursor is over it.
Look at this:
section#lBox {
That has a capital letter B in lBox.
Then look at this:
section#lbox:hover {
This has a lowercase b in lbox.
Assuming your box has an id="lBox", the hover opacity: 0.8 part will not work, as CSS is case-sensitive, and lbox and lBox are two different things.
So what you should do is just change this:
section#lbox:hover {
To this:
section#lBox:hover {
And it should work.

How to configure opacity based CSS overlay to not effect spacing of surrounding elements?

Ok, I have the following code: https://jsfiddle.net/7u1aLxaw/
So the issue is that when you hover over an image, it shows an overlay with a name specific to that image. But if the name is longer than the image width, the image immediately to the right is pushed away and the overlay isn't centered on the image. It expands just to the right, not on both sides.
I can't work out how to center the overlay and avoid it effecting divs on either side of it.
*I tried using display: none, but I want to preserve the CSS3 transitions. Using display: none to completely remove the element removes the CSS3 transition.
Any ideas?
Change your .item_overlay style to:
.item_overlay {
height: auto;
width: auto;
margin: 0 auto;
margin-top: -95px;
position: absolute;
z-index: 1;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
transition: all 0.3s linear;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
Making the position absolute ignores the other elements position, then setting a negative top margin moves it back to the top. http://jsfiddle.net/q8SER/2/
Working jsFiddle: http://jsfiddle.net/q8SER/3/
I had to change a whole bunch of stuff to make it work.
First of all, I changed the HTML structure and placed the overlay div before the icon div.
Here is the new overlay CSS:
.item_overlay {
position: absolute;
z-index: 1;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-transition: all 0.3s linear;
-moz-transition: all 0.3s linear;
-o-transition: all 0.3s linear;
transition: all 0.3s linear;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
Now, because the inner div (overlay) overflows the parent div, I couldn't center it conventionally with auto margins, so I implemented a jQuery solution.
JS code:
$(".item_overlay").each( function() {
var offset = ($(this).parent().width() - $(this).width()) / 2;
$(this).css("left", offset + "px");
});
Hope that helps.

Transition doesn't work on FF

I have the below simple HTML and CSS. It works in Chrome fine. but not FF. I mean the transition doesn't work on FF. I'm using FF 18. I searched the issue on Google and SO and find some hacks. But none of them works for my issue. Any idea please?
HTML:
<div class="image-list cf">
<figure>
<a href="javascript:return false;">
<img src="image-src-1"/>
</a>
<span>
File Name 1
</span>
<span>
10 Images
</span>
</figure>
<figure>
<a href="javascript:return false;">
<img src="image-src-1"/>
</a>
<span>
File Name 1
</span>
<span>
10 Images
</span>
</figure>
<-- and more -->
</div>
CSS:
/* images list
**********************************************************/
.image-list {}
.image-list figure {
float: right;
width: 180px;
border: 1px solid;
border-color: #aaa;
border-radius: 0;
box-shadow:
1px 0 0 #fff,
0 1px 0 #fff,
-1px 0 0 #fff,
0 -1px 0 #fff,
0 0 2px #000;
margin-right: 29px;
text-align: center;
padding: 10px 0;
background-color: #fff;
-webkit-transition: all .3s ease 0s;
-moz-transition: all .3s ease 0s;
-o-transition: all .3s ease 0s;
transition: all .3s ease 0s;
}
.image-list figure:hover{
border-color: #666;
box-shadow:
1px 0 0 #fff,
0 1px 0 #fff,
-1px 0 0 #fff,
0 -1px 0 #fff,
0 0 10px #000;
}
[class="image-list"] figure:hover {
border-color: #666;
box-shadow:
1px 0 0 #fff,
0 1px 0 #fff,
-1px 0 0 #fff,
0 -1px 0 #fff,
0 0 10px #000;
}
.image-list figure a {}
.image-list figure a img {}
.image-list figure span {
display: block;
padding: 5px 0;
width: 160px;
margin: 0 auto;
overflow: hidden;
height: 1em;
}
.image-list figure span a {}
may be you are using older version of browser that dones not support transition functinality. see below link for transition support chart at end of page
https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_transitions
here is some code wih support comments
-webkit-transition: all .3s linear; // webkit browsers like chrome, safari support code
-moz-transition: all .3s linear; // mozilla support code
-o-transition: all .3s linear; // opera support code
transition: all .3s linear; // css3 code