Other code that might be blocking the animation:
.projectLinks a{
background-color: var(--secondary-color);
color: var(--main-color);
padding: 2px 4px 4px 4px;
border-radius: 15px;
margin-right: 25px;
text-decoration: none;
Animation
transition-property: transform;
transition-duration: .3s;
}
.projectLinks a:hover{
background-color: var(--secondary-hover);
transform: translateY(-3px);
}
The hover color is applied but there is no transition. Why is that?
Here is a link to a codepen recreation of what I have:
https://codepen.io/Ancross/pen/yLKabeM
You will want to change the display property of the links. By default they are display inline.
To keep a similar look, I used display:inline
.projectLinks a{
background-color: rgb(0, 153, 255);
color: white;
padding: 2px 4px 4px 4px;
border-radius: 15px;
margin-right: 25px;
text-decoration: none;
transition-property: transform;
transition-duration: .3s;
display:inline-block;
}
.projectLinks a:hover{
background-color: rgb(1, 137, 228);
transform: translateY(-3px);
}
<div class='projectLinks'>
<a>Text</a>
</div>
You are using translateY on an inline-level element which can not be transformed due to some limitation. To use it correctly you can make it an inline-block
write this line in CSS like
.projectLinks a {
...
display: inline-block;
}
this will cause this to display inline but as a block for more info about inline element and block level element please refer below MDN docs:
inline elements: https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
block level element: https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
I have the following button.
The CSS for the button above is this:
.cta-btn {
display: inline-block;
margin: 20px 0 0 20px;
color: #fff;
background-color: #FF8F1B;
background-image: linear-gradient(to right, #2ab3ff, #ff2d00);
box-shadow: 4px 5px 27px 4px rgba(220, 120, 184, 0.85);
font-size: 21px;
border-radius: 30px;
padding: 12px 21px;
font-family: Montserrat;
}
click me
I want the button to change gradient color smoothly when I hover over it. I do not want the gradient color to just snap onto the button when I hover it. This is my attempt at a smooth gradient color transition:
a.cta-btn:hover {
background-image: linear-gradient(to right,#FF2A67,#FF5D3A);
color: #fff;
box-shadow: 4px 5px 27px 4px rgba(255,45,45,0.85);
transition: background-image .3s linear;
transition: box-shadow .3s linear;
}
Any help is much appreciated.
Short answer, you can't using just background. However, you can achieve a similar effect using other elements (or pseudo elements) inside and fading them in on hover.
The following example uses two pseudo-elements as the two background states. On hover, we simply fade-in the new background giving a similar transition effect that would happen if gradients were transition-able.
NOTE: Not all browsers support transitions on pseudo elements, so you may need to add empty elements to achieve the same effect on older/unsupported browsers.
.cta-btn {
position: relative;
display: inline-block;
margin: 20px 0 0 20px;
color: #fff;
box-shadow: 4px 5px 27px 4px rgba(220, 120, 184, 0.85);
font-size: 21px;
border-radius: 30px;
overflow: hidden;
padding: 12px 21px;
font-family: Montserrat;
transition: box-shadow.3s ease-in-out;
text-decoration: none;
}
/* These are the two backgrounds, absolutely positioned to cover. */
.cta-btn::before,
.cta-btn::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
background-image: linear-gradient(to right, #2ab3ff, #ff2d00);
border-radius: 30px;
z-index: -1;
}
.cta-btn::after {
opacity: 0;
background-image: linear-gradient(to right,#FF2A67,#FF5D3A);
transition: opacity.3s ease-in-out;
}
/* On hover, transtiion the shadow of the anchor, and fade in the after element to show the new background. */
.cta-btn:hover {
box-shadow: 4px 5px 27px 4px rgba(255,45,45,0.85);
}
.cta-btn:hover::after {
opacity: 1;
}
click me
I have try all your answers, and i prefer this :
It's lightly and working perfect with only background-size property for the hover
and Work with Chrome IE and ff
Enjoy
.ex-button-0 {
transition: all ease 0.5s;
cursor: pointer;
padding: 10.5px 25px;
border: none;
border-radius: 35px;
background-image: linear-gradient(to left, black, blue, yellow, orange);
background-size:300%;
background-position: 0 0;
-webkit-appearance: none !important;
color: #000;
text-decoration:none
}
.ex-button-0:hover {
background-position: 100% 0;
color:#fff;
}
<a class="ex-button-0" href="">Exemple</a>
Though still able to see background decreasing and increasing in dimensions, this is partially possible using multiple background properties at same element, toggling background-size property.
.cta-btn {
color: #fff;
background: linear-gradient(to right, #2ab3ff, #ff2d00)
, linear-gradient(to right,#FF2A67,#FF5D3A);
background-size:100% 100%, 0% 0%;
background-origin: border-box, border-box;
box-shadow: 4px 5px 27px 4px rgba(220, 120, 184, 0.85);
font-size: 21px;
border-radius: 30px;
padding: 12px 21px;
font-family: Montserrat;
transition: background .3s linear;
}
.cta-btn:hover {
background-size:0% 0%, 100% 100%;
box-shadow: 4px 5px 27px 4px rgba(255,45,45,0.85);
}
click me
Probably a little late to the party, but I did manage to get a gradient transition into a solid color, which is what I needed for my project.
Here is the codepen for proof of concept.
https://codepen.io/etc-umbrella/pen/pXremq
<button class="ui-button">This is a button</button>
<h2>Creating an aninmated gradient background button using only SCSS. Worked pretty good. Didn't have to use any crazy javascript</h2>
.ui-button {
position: relative;
overflow: hidden;
border-radius: 6px;
cursor: pointer;
padding: 12px 18px;
border: 1px solid aqua;
background-color: white;
color: #ffffff;
font-family: raleway;
font-weight: bold;
font-size: 16px;
z-index: 1;
transition: all 800ms ease-in;
&:after{
content: '';
position: absolute;
left: -200%;
top: 0px;
width: 400%;
height: 100%;
background: rgb(33,209,159);
background: linear-gradient(45deg, rgba(33,209,159,1) 0%, rgba(34,44,64,1) 50%, rgba(21,65,153,1) 100%);
z-index: -1;
transition: all 800ms ease-in;
}
&:hover{
color: #ffffff;
background-color: #21d19f;
}
&:hover:after{
left: 0%;
opacity: 0;
}
}
#import url('https://fonts.googleapis.com/css?family=Montserrat:500');
html,body {
font-family: 'Montserrat', sans-serif;
margin:0;
padding:0;
background: linear-gradient(to right, #c9d6ff, #e2e2e2);
}
div {
height: 100vh;
display: flex;
align-items:center;
justify-content:center;
}
h1 {
font-size: 42px;
background-size:200%;
padding:15px;
border-radius:5px;
background-image: linear-gradient(to top left, #fe87c3 0%, #D38312 50%, #A83279 100%);
transition: .3s ease;
cursor: pointer;
}
h1:hover {
background-position: 90%;
color: #202020;
}
.home {
background-size: 200%
}**strong text**
Here is a demo
https://codepen.io/Mikeytown19/pen/aLpNZa
In every other browser the :active selector works even if there are elements nested inside the anchor tag, but IE11 seems special. (Microsoft Edge is apparently fine).
I'd expect when I click on the anchor tag, even if I click on the span, that the active selector will be applied.
http://jsfiddle.net/91ejuvjm/4/
HTML
<span>Click here</span>
CSS
a
{
display: block;
background-color: red;
}
a:active
{
background-color: blue;
}
It's an anchor tag and according to the spec it can be active, but it's like the span tag captures the click. I tried adding pointer-events:none; to the span tag and it ignores it which is against the spec and obviously a bug. I also thought maybe it was being selected since it's text, but -ms-user-select: none; doesn't help. Am I missing something obvious? How do I make clicks ignore the span tag in IE11?
#FighterJet had the solution for me pointer-events: none; on the nested element allows for the parent to take the event (for ie)
.squishy span {
position: absolute;
/*######################
# THE IMPORTANT PART #
######################*/
/*pointer-events: none;*/
display: inline-block;
white-space: nowrap;
top: 0;
left: 0;
vertical-align: middle;
line-height: 75px; /*change to btn height*/
width: 100%;
height: 100%;
-webkit-transition: transfrom .15s;
-moz-transition: transfrom .15s;
-ms-transition: transfrom .15s;
transition: transfrom .15s;
}
/* The solution! */
.solution {
pointer-events: none;
}
.btn-1 {
width: 75px;
height: 75px;
border-radius: 50%;
}
.squishy {
position: relative;
display: inline-block;
vertical-align: middle;
margin: 10px;
color: #fff;
text-align: center;
background: #333;
box-shadow: inset 5px 5px 15px rgba(150, 150, 150, .5), inset -5px -5px 15px rgba(0, 0, 0, .5), 3px 3px 5px rgba(0, 0, 0, .7);
-webkit-transition: box-shadow .15s;
-moz-transition: box-shadow .15s;
-ms-transition: box-shadow .15s;
transition: box-shadow .15s;
}
.squishy:active {
box-shadow: inset 1px 1px 1px rgba(150, 150, 150, .5), inset -1px -1px 1px rgba(0, 0, 0, .5), 1px 1px 1px rgba(0, 0, 0, .7);
}
.squishy:active span {
-webkit-transform: scale(.95);
transform: scale(.95);
}
<h1>Broken in IE</h1>
<a class="squishy btn-1" type="button">
<span>O</span>
</a>
<h1>Works in IE</h1>
<a class="squishy btn-1" type="button">
<span class="solution">O</span>
</a>
I ran into this problem while making buttons. Now they work properly in IE http://codepen.io/FluidOfInsanity/pen/XjpEag
IE11 doesn't allow block elements I guess to function that way.
http://jsfiddle.net/91ejuvjm/7/
span
{
display: inline-block;
}
Another example that's probably more complete: http://jsfiddle.net/91ejuvjm/8/
Was playing around and changed the span to inline-block and it's fine.
I have a tab that when I hover over it, I open a dropdown-menu. What I would like is that when I hover over the tab, the dropdown menu will show with an transition of 0.5s to give that animation look.
To be open from top to bottom. Something similar you can see in dropdown on linkedIn page.
This is what I have so far.
.dropdown:hover .dropdown-menu {
display: block;
}
.dropdown-menu {
width: 211px;
border-color: #efefef;
border-width: 3px;
background-clip: padding-box;
background-color: #ffffff;
border-radius: 0 0 7px 7px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.176);
display: none;
float: left;
font-size: 12px;
left: 0;
list-style: outside none none;
margin: 0px 0 0;
min-width: 160px;
padding: 5px 0;
position: absolute;
top: 100%;
z-index: 1000;
}
I try add this into the dropdown:hover and dropdown-menu without success.
-o-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-webkit-transition: opacity 0.5s;
transition: opacity 0.5s;
Add opacity: 0; to .dropdown and opacity: 1; to .dropdown-menu
Here is a demo
I'd like to have a nice hover effect where I scale the width of list items slightly.
I also want to do this with an animation delay of 250ms. The problem is that the text gets stretched and shimmers.
How can one offset that effect?
I have a jsFiddle that shows the problem. It is the most noticeable in Chrome.
http://jsfiddle.net/LxywP/
Example CSS:
span {
display: inline-block;
background: #eee;
border: solid 1px #ddd;
padding: 8px 10px;
font-size: 1.2em;
font-weight: bold;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
-moz-transition: all 250ms;
-webkit-transition: all 250ms;
-o-transition: all 250ms;
transition: all 250ms;
}
span:hover {
background: darken(#E2F3E2, 8%);
text-decoration: none;
-ms-transform: scale(1.05, 1);
-mozilla-transform: scale(1.05, 1);
-webkit-transform: scale(1.05, 1);
transform: scale(1.05, 1);
}
As #Spudley mentioned in the comment, you shouldn't use scale since that stretches the element by definition. Instead you can add more left/right paddings to make the element wider. A problem with that is the element will be pushed to the right, you can solve that by adding "text-align: center" to its wrapper.
HTML:
<div>
<span>This text gets stretched</span>
</div>
CSS:
div {
text-align: center;
}
span {
display: inline-block;
background: #eee;
border: solid 1px #ddd;
padding: 8px 10px;
font-size: 1.2em;
font-weight: bold;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
-moz-transition: padding 250ms;
-webkit-transition: padding 250ms;
-o-transition: padding 250ms;
transition: padding 250ms;
}
span:hover {
background: darken(#E2F3E2, 8%);
text-decoration: none;
padding: 8px 20px;
}
Paste those into your jsfiddle and see the effect.
Another pro tip is to restrain from using "transition: all", specifying specific attributes to apply transition improves performance a lot. In this case you would use "transition: padding".