Related
I'm trying to create a shine animation on an element that already has a gradient.
But my animation remove the gradient background...
This is what I have done:
body {
background: blue;
}
.mytoast {
-webkit-animation-name: ShineAnimation;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(.12, .89, .98, .47);
box-sizing: border-box;
/*background-color:rgba(0, 0, 0, 0.8);*/
background-image: linear-gradient(-225deg, #FF3CAC 0%, #562B7C 52%, #2B86C5 100%);
border-radius: 100px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
clear: both;
color: #fff;
cursor: grab;
/* display: -webkit-flex;
display: -ms-flexbox;*/
/* display: flex;*/
display: inline-block;
font-size: 16px;
font-weight: 300;
height: auto;
line-height: 1.5;
margin-top: 8px;
max-width: 100%;
min-height: 48px;
padding: 16px 24px;
position: relative;
top: 0px;
width: 90%;
margin: 0;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
#-webkit-keyframes ShineAnimation {
from {
background-repeat: no-repeat;
background-image: -webkit-linear-gradient( top left, rgba(255, 255, 255, 0.0) 0%, rgba(255, 255, 255, 0.0) 45%, rgba(255, 255, 255, 0.5) 48%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0.0) 57%, rgba(255, 255, 255, 0.0) 100%);
background-position: -250px -250px;
background-size: 600px 600px
}
to {
background-repeat: no-repeat;
background-position: 250px 250px;
}
}
<div class="mytoast">
</div>
If you run the code above, you will see the shine animation but the issue is that it will also animate the gradient and removes it which is not what I am trying to do.
could someone please advice on this?
You can set multiple backgrounds (including gradients) in CSS. Since you only animate the background position of the shiny gradient, you can move all definitions to .mytoast, and set the definitions for each of the backgrounds.
In the animations set the background position for both backgrounds. The one for the non animated background would be the identical to the definition in .mytoast.
Note: unless you're going to support really old browsers, you don't need the -webkit prefix.
body {
background: blue;
}
.mytoast {
background:
linear-gradient(
to top left,
rgba(255, 255, 255, 0.0) 0%,
rgba(255, 255, 255, 0.0) 45%,
rgba(255, 255, 255, 0.5) 48%,
rgba(255, 255, 255, 0.8) 50%,
rgba(255, 255, 255, 0.5) 52%,
rgba(255, 255, 255, 0.0) 57%,
rgba(255, 255, 255, 0.0) 100%
),
linear-gradient(-225deg, #FF3CAC 0%, #562B7C 52%, #2B86C5 100%);
background-size: 600px 600px, 100% 100%;
background-position: -250px -250px, center;
background-repeat: no-repeat;
animation: ShineAnimation 5s infinite cubic-bezier(.12, .89, .98, .47);
box-sizing: border-box;
border-radius: 100px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
clear: both;
color: #fff;
cursor: grab;
display: inline-block;
font-size: 16px;
font-weight: 300;
height: auto;
line-height: 1.5;
margin-top: 8px;
max-width: 100%;
min-height: 48px;
padding: 16px 24px;
position: relative;
top: 0px;
width: 90%;
margin: 0;
}
#keyframes ShineAnimation {
to {
background-position: 250px 250px, center;
}
}
<div class="mytoast">
</div>
I prefer creating a block overlaying before .mytoast and animate the shining block from left to right.
Hope this helps.
body {
width: 100%;
background: blue;
}
.mytoast {
box-sizing: border-box;
background-image: linear-gradient(-225deg, #ff3cac 0%, #562b7c 52%, #2b86c5 100%);
border-radius: 100px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
clear: both;
color: #fff;
cursor: -webkit-grab;
cursor: grab;
display: block;
font-size: 16px;
font-weight: 300;
height: auto;
line-height: 1.5;
width: 100%;
height: 48px;
padding: 16px 24px;
position: relative;
top: 0px;
width: 90%;
margin: 8px 0 0;
overflow: hidden;
}
.mytoast:before {
width: 100%;
height: 48px;
content: "";
background-image: -webkit-linear-gradient(top left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0) 45%, rgba(255, 255, 255, 0.5) 48%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0) 57%, rgba(255, 255, 255, 0) 100%);
-webkit-animation-name: ShineAnimation;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(0.12, 0.89, 0.98, 0.47);
display: block;
position: absolute;
top: 0;
left: -100%;
z-index: 2;
-webkit-transform: skew(-20deg);
transform: skew(-20deg);
}
#-webkit-keyframes ShineAnimation {
from {
left: -100%;
}
to {
left: 100%;
}
}
<div class="mytoast"></div>
Im trying to acomplish two things.
1) Gradient from left to right on hover
2) Gradient from right to left when there's no hover
3) Also Im trying to get rid of some kind of right grey border right at firefox
Here's my code:
HTML:
<a class="btn-main" href="#">Przejdź do sklepu </a>
CSS:
.btn-main {
color: #000000;
border-left: solid 1px #000000;
padding: 8px 12px;
font-weight: 700;
text-decoration: none;
}
.btn-main {
background-size: 200% 100%;
background-image: linear-gradient(to right, black 50%, white 50%),
linear-gradient(to right, white 50%, black 50%);
background-image: -moz-linear-gradient(to right, white 50%, black 50%),
linear-gradient(to right, black 50%, white 50%);
background-image: -webkit-linear-gradient(to right, black 50%, white 50%),
linear-gradient(to right, white 50%, black 50%);
transition: background-position left 0.5s linear;
-webkit-transition: background-position left 0.5s linear;
-moz-transition: background-position left 0.5s linear;
-o-transition: background-position left 0.5s linear;
-webkit-background-clip: text, border-box;
-moz-background-clip: text, border-box;
background-clip: text, border-box;
color: transparent;
-webkit-text-fill-color: black;
}
.btn-main:hover {
background-position: -100% 0;
color: #ececec;
text-decoration: none;
transition: all 0.5s cubic-bezier(0.000, 0.000, 0.230, 1);
-webkit-text-fill-color: #ececec;
}
Right now it's working fine when I make it hover (1), but I cant find solution to gradient when there's no hover (2) and how to get rid of this grey border right on Firefox (3).
Please help.
My fiddle:
https://jsfiddle.net/6fx64L8j/3/
You can simplify your code like this:
.btn-main {
color: #000;
border-left: solid 1px #000;
padding: 8px 12px;
font-weight: 700;
text-decoration: none;
background-size: 0% 100%;
background-image: linear-gradient(black, black);
background-repeat: no-repeat;
transition: all 0.5s linear;
color: #000;
}
.btn-main:hover {
background-size: 100% 100%;
color: #ececec;
transition: all 0.5s cubic-bezier(0.000, 0.000, 0.230, 1);
}
<a class="btn-main" href="#">Przejdź do sklepu </a>
Try this.
.btn-grad {
background: transparent;
width: 200px;
margin: 0 auto;
text-align: center;
padding: 50px;
text-transformation: uppercase;
font-family: 'arial', sans-serif;
font-weight: bold;
margin-top: 45px;
color: #000;
padding: 20px;
display: block;
background-image: linear-gradient(to left, transparent, transparent 50%, #ff0000 50%, #00c6ff);
background-position: 100% 0;
background-size: 200% 100%;
transition: all .25s ease-in;
text-decoration:none;
}
.btn-grad:hover {
background-position: 0 0;
color: #333;
}
Button
I have an input for text with a placeholder. As soon as you click the input the placeholder moves up and stays as a title. The problem is that when I start typing that title goes away.
.material-input-login {
margin: 8px 10px;
width: 200px;
/* display: block; */
border: none;
padding: 10px 0;
border-bottom: solid 1px #fff;
-webkit-transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 96%, #fff 4%);
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 96%, #fff 4%);
background-position: -200px 0;
background-size: 200px 100%;
background-repeat: no-repeat;
color: #fff;
}
.material-input-login:focus, .material-input-login:valid {
box-shadow: none;
outline: none;
background-position: 0 0;
}
.material-input-login:focus::-webkit-input-placeholder, .material-input-login:valid::-webkit-input-placeholder {
color: #fff;
font-size: 11px;
-webkit-transform: translateY(-20px);
transform: translateY(-20px);
visibility: visible !important;
}
.material-input-login::-webkit-input-placeholder, .material-button {
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
<input id="searchBox" type="search" placeholder="Search" class="material-input-login" required="">
The problem is that placeholders disappear when you begin typing - I'm not aware of any CSS tricks that will allow you to avoid this behaviour.
I've had a go at making an alternative that uses the input label instead:
https://jsfiddle.net/zug5j8m5/
CSS:
body {
background: #333;
}
.material-input-login {
margin: 0 10px 8px;
width: 200px;
border: none;
padding: 10px 0;
border-bottom: solid 1px #fff;
-webkit-transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 96%, #fff 4%);
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 96%, #fff 4%);
background-position: -200px 0;
background-size: 200px 100%;
background-repeat: no-repeat;
color: #fff;
}
.material-input-login:focus, .material-input-login:valid {
box-shadow: none;
outline: none;
background-position: 0 0;
}
.label {
color: #fff;
display: block;
font-family: sans-serif;
font-size: 13px;
margin: 0 10px;
position: absolute;
-webkit-transform: translateY(-35px);
transform: translateY(-35px);
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.material-input-login:focus+.label {
color: #fff;
font-size: 11px;
-webkit-transform: translateY(-50px);
transform: translateY(-50px);
display:block !important;
}
HTML:
<input id="searchBox" type="search" title="Search" class="material-input-login" required="">
<label for="searchBox" class="label">Search</label>
Here is what makes it moves up:
-webkit-transform: translateY(-20px);
transform: translateY(-20px);
translateY allows you to move the placeholder -20px above. Just remove it or change the number if you want.
This transition works in Safari & Chrome (= Webkit browsers), but not in Firefox (= Mozilla). Why?
a.lorem {
width: 100px;
padding: 20px;
display: block;
color: white;
text-align: center;
background: rgb(191,210,85);
background: -moz-linear-gradient(top, rgb(191,210,85) 0%, rgb(142,185,42) 50%, rgb(114,170,0) 51%, rgb(158,203,45) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(191,210,85)), color-stop(50%,rgb(142,185,42)), color-stop(51%,rgb(114,170,0)), color-stop(100%,rgb(158,203,45)));
background: -webkit-linear-gradient(top, rgb(191,210,85) 0%,rgb(142,185,42) 50%,rgb(114,170,0) 51%,rgb(158,203,45) 100%);
background: -o-linear-gradient(top, rgb(191,210,85) 0%,rgb(142,185,42) 50%,rgb(114,170,0) 51%,rgb(158,203,45) 100%);
background: -ms-linear-gradient(top, rgb(191,210,85) 0%,rgb(142,185,42) 50%,rgb(114,170,0) 51%,rgb(158,203,45) 100%);
background: linear-gradient(to bottom, rgb(191,210,85) 0%,rgb(142,185,42) 50%,rgb(114,170,0) 51%,rgb(158,203,45) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bfd255', endColorstr='#9ecb2d',GradientType=0 );
box-shadow: inset 0 -3px 0 #A9A9A9,
0 3px 0 #EFEFED;
-webkit-transition: box-shadow .5s linear;
-moz-transition: box-shadow .5s linear;
-o-transition: box-shadow .5s linear;
-ms-transition: box-shadow .5s linear;
transition: box-shadow .5s linear;
}
a:hover.lorem {
box-shadow: 0 3px 0 rgba(0, 0, 0, .1),
inset 0 -3px 0 rgba(0, 0, 0, .1),
inset 0 0 100px rgba(255, 255,255 , .3);
}
Fiddle
first, you need to write a.lorem:hover and not a:hover.lorem
after, border-shadow multi values need to be corresponding to their ":hover" pair.
"inset" border-shadow can't transit to "outset" border-shadow.
exemple :
a.lorem{
box-shadow:
inset 0 -3px 0 #A9A9A9,
0 3px 0 #EFEFED,
inset 0 0 0 rgba(0,0,0,0); /* for third ":hover" value */
transition:box-shadow .5s linear; /* add prefixed verison (-moz-, -webkit-, ...*/
}
a.lorem:hover{
box-shadow:
inset 0 -3px 0 rgba(0, 0, 0, .1),
0 3px 0 rgba(0, 0, 0, .1),
inset 0 0 100px rgba(255, 255,255 , .3);
}
I am trying to change the background and text color with the css3 transition effects when hovering over a button, but only the text color is changing and not the background color. Here is my jsfiddle code and here is my css :
.input-submit
{
margin: 12px 0 2px
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(255, 255, 255)), to(rgb(224, 224, 224)));
background-image: -webkit-linear-gradient(top, rgb(255, 255, 255), rgb(224, 224, 224));
background-image: -moz-linear-gradient(top, rgb(255, 255, 255), rgb(224, 224, 224));
background-image: -o-linear-gradient(top, rgb(255, 255, 255), rgb(224, 224, 224));
background-image: linear-gradient(top, rgb(255, 255, 255), rgb(224, 224, 224));
-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
-moz-box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
border: 0;
font-weight: normal;
color: #333;
text-shadow: 0 1px 0 white;
border-radius: 5px;
-moz-border-radius: 5px;
padding: 5px;
width: 60px;
border-image: initial;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
.input-submit:hover
{
cursor:pointer;
margin: 12px 0 2px;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(145, 191, 1)), to(rgb(111, 149, 1)));
background-image: -webkit-linear-gradient(top, rgb(145, 191, 1), rgb(111, 149, 1));
background-image: -moz-linear-gradient(top, rgb(145, 191, 1), rgb(111, 149, 1));
background-image: -o-linear-gradient(top, rgb(145, 191, 1), rgb(111, 149, 1));
background-image: linear-gradient(top, rgb(145, 191, 1), rgb(111, 149, 1));
-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
-moz-box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
box-shadow: inset 0 1px 0 #fff, 0 1px 3px rgba(0,0,0,.5);
border: 0;
font-weight: normal;
color: #fff;
text-shadow: 0 1px 0 white;
border-radius: 5px;
-moz-border-radius: 5px;
padding: 5px;
width: 60px;
border-image: initial;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
That's quite a block of CSS you've got there! As far as I'm aware, no browsers allow transitions of css gradients yet. Since your backgrounds aren't solid colors, you can't transition them.