I am using a gradient to set the background color on one element. The thing is, I am also having an "hover" background but not using the gradient. At the minute, when I hover on an element having the class .tinted it flashes as it first display no background and then apply the rgba(0,0,0,0.65)
Is there any way that the transition could directly go from background: gradient(left, rgba(0,0,0,0.65), rgba(0,0,0,0.30)) to rgba(0,0,0,0.65) ?
.tinted {
transition: background-color 500ms linear;
background: -webkit-linear-gradient(left, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: -o-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: -moz-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background: linear-gradient(to right, rgba(0,0,0,.65), rgba(0,0,0,.30));
}
.tinted:hover {
background: rgba(0, 0, 0, 0.65);
}
You need to define the gradients with background-image and the plain color with background-color:
.tinted {
transition: background-color 500ms linear;
background-image: -webkit-linear-gradient(left, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: -o-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: -moz-linear-gradient(right, rgba(0,0,0,.65), rgba(0,0,0,.30));
background-image: linear-gradient(to right, rgba(0,0,0,.65), rgba(0,0,0,.30));
}
.tinted:hover {
background-color: rgba(0, 0, 0, 0.65);
}
DEMO
This Is What you Can Use For This Approach:
#box{
width: 200px;
height: 300px;
background-color: orange;
background-image: -webkit-linear-gradient(top, crimson 0%, transparent 100%);
transition: all 1s ease-in-out;
}
#box:hover{
background-color: crimson;
}
<div id="box"></div>
A posibility is to set a gradient that has 2 parts, one with the color changing, and the other with a constant color.
And change the part of the gradient that you are showing with background-image.position
.test {
width: 300px;
height: 100px;
background-image: linear-gradient(to right, rgba(0,0,0,0.65) 50%, rgba(0,0,0,0.3));
background-size: 200% 100%;
background-position: 100% 0%;
transition: background-position 1s;
margin: 10px;
}
.test:hover {
background-position: 0% 0%;
}
#test2 {
background-image: linear-gradient(to right, blue 50%, red 100%);
}
<div class="test"></div>
<div class="test" id="test2"></div>
Related
In my code, on hover the direction of linear-gradient animation is like counterclockwise, how can do it stright linear from top right to bottom left?
.boxstyle
{
background-color:rgba(0,69,255,1);
background-size: 0% 100%;
transition: background-color .5s;
width: 150px;
height: 150px;
}
.boxstyle:hover
{
background-image:linear-gradient(to left bottom, rgba(189,41,242,0) 0%, rgba(189,41,242,0) 40%, rgba(189,41,242, 0.9) 100%);
background-repeat:no-repeat;
background-size: 200% 100%;
transition:background-size 1s, background-color 1s;
}
<div class="boxstyle">hover it</div>
If you really want the pink to start at the top right and move to the bottom left you could use before and after pseudo elements, the before with just the color, the after also with the linear-gradient.
The after pseudo element moves diagonally across to the bottom left on hover of the main element.
.boxstyle {
width: 150px;
height: 150px;
position: relative;
overflow: hidden;
}
.boxstyle::before,
.boxstyle::after {
content: '';
position: absolute;
z-index: -1;
}
.boxstyle::before {
background-color: rgba(0, 69, 255, 1);
width: 100%;
height: 100%;
}
.boxstyle::after {
background-image: linear-gradient(to left bottom, rgba(189, 41, 242, 0) 0%, rgba(189, 41, 242, 0) 40%, rgba(189, 41, 242, 0.9) 100%);
bottom: 100%;
left: 100%;
transition: all 1s linear;
width: 200%;
height: 200%;
}
.boxstyle:hover::after {
bottom: -10%;
left: -10%;
}
<div class="boxstyle">hover it</div>
Old comment: This fits your verbal description of the effect desired, but I suspect it isn't exactly what you intended - did you want it more 'blendy' and subtle, becoming the final picture only at the very end?
UPDATE: Since seeing your images this snippet uses an after that has twice the dimensions of the main element so spreading out the colors more. It 'settles' on a hover a bit beyond the bottom left.
You can try like below. Invert the positions to get the opposite direction. More details: Using percentage values with background-position on a linear-gradient
.boxstyle {
background: linear-gradient(to top right, #0000 40%, rgb(189 41 242/0.9) 100%);
background-size: 200% 200%;
background-position: 0% 100%;
background-color: rgba(0, 69, 255, 1);
transition: .5s;
width: 150px;
height: 150px;
}
.boxstyle:hover {
background-position: 100% 0;
}
<div class="boxstyle">hover it</div>
If you prefer the pink color area to travel through the box (from top right corner to bottom left corner), it can be implemented by setting the linear-gradient so that has the pink area in the middle.
Example:
.boxstyle {
background: linear-gradient(to top right, #0000 10%, rgb(189 41 242/0.9) 40%, rgb(189 41 242/0.9) 60%, #0000 90%);
background-size: 500% 500%;
background-position: 0% 100%;
background-color: rgba(0, 69, 255, 1);
transition: .5s ease-in-out;
width: 150px;
height: 150px;
color: #fff;
}
.boxstyle:hover {
background-position: 100% 0;
}
<div class="boxstyle">hover it</div>
I have an issue on safari with my heading.
I use video as background.
On chrome, it has nice smooth animation, but on safari I can't even see the heading.
Can anyone find the solution? Or just the reason why it is happening?
Thanks!
Heading CSS:
h1#index-title {
font-family: 'GothamMedium', sans-serif;
font-size: 160px;
line-height: 0.99;
margin-bottom: 56px;
position: relative;
/* background: linear-gradient(to right, transparent, #fff); */
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #fff)
)
right;
background: -o-linear-gradient(right, transparent 50%, #fff 50%) right;
background: linear-gradient(to left, transparent 50%, #fff 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
-webkit-animation: shownow 0.8s linear forwards;
animation: shownow 0.8s linear forwards;
-webkit-animation-delay: calc(var(--load-time) + 0.4s);
animation-delay: calc(var(--load-time) + 0.4s);
}
Shownow animation:
#-webkit-keyframes shownow {
0% {
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #fff)
)
right;
background: linear-gradient(to left, transparent 50%, #fff 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
}
100% {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background-position: left;
}
}
working codepen example: https://codepen.io/tabitfree/pen/oNeOZPe
I have changed the color from #fff to #f0f:
h1#index-title {
font-family: 'GothamMedium', sans-serif;
font-size: 160px;
line-height: 0.99;
margin-bottom: 56px;
position: relative;
/* background: linear-gradient(to right, transparent, #fff); */
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #fff)
)
right;
background: -o-linear-gradient(right, transparent 50%, #f0f 50%) right;
background: linear-gradient(to left, transparent 50%, #f0f 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
-webkit-animation: shownow 0.8s linear forwards;
animation: shownow 0.8s linear forwards;
-webkit-animation-delay: calc(var(--load-time) + 0.4s);
animation-delay: calc(var(--load-time) + 0.4s);
}
#-webkit-keyframes shownow {
0% {
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #f0f)
)
right;
background: linear-gradient(to left, transparent 50%, #f0f 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
}
100% {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background-position: left;
}
}
<h1 id="index-title">Heading</h1>
I cannot understand why the video isnt showing on your codepen but it is true, I don't see it on my Safari (IOS14 iPad).
However, using the Stackoverflow snippet system and copying the HTML and CSS from your codepen I can see the video on Safari.
Here is the snippet for you to try.
<style>
* {
margin: 0;
padding: 0;
}
body {
position: relative;
--load-time: 0;
width: 100vw;
height: 100vh;
color: #fff;
}
.bg-video {
position: absolute;
min-width: 100%;
min-height: 100%;
max-width: 100%;
max-height: 100%;
z-index: -1;
-o-object-fit: cover;
object-fit: cover;
right: 0;
bottom: 0;
z-index: -2;
}
h1#index-title {
font-family: "GothamMedium", sans-serif;
font-size: 160px;
margin: 0 !important;
line-height: 0.99;
margin-bottom: 56px;
position: relative;
background: linear-gradient(to right, transparent, #fff);
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #fff)
)
right;
background: -o-linear-gradient(right, transparent 50%, #fff 50%) right;
background: linear-gradient(to left, transparent 50%, #fff 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
-webkit-animation: shownow 0.8s linear forwards;
animation: shownow 0.8s linear forwards;
-webkit-animation-delay: calc(var(--load-time) + 0.4s);
animation-delay: calc(var(--load-time) + 0.4s);
margin: 0 !important;
}
#-webkit-keyframes shownow {
0% {
background: transparent;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background: -webkit-gradient(
linear,
right top,
left top,
color-stop(50%, transparent),
color-stop(50%, #fff)
)
right;
background: linear-gradient(to left, transparent 50%, #fff 50%) right;
-webkit-background-clip: text;
background-size: 200% 100%;
}
100% {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-blend-mode: difference;
background-position: left;
}
}
</style>
<section>
<div class="main-container">
<h1 id='index-title'>Long heading</h1>
</div>
<video class='bg-video' autoplay muted>
<source src="http://learn.shayhowe.com/assets/misc/courses/html-css/adding-media/earth.mp4" type="video/mp4">
</video>
</section>
So.. I figured out my problem.
DOUBLE CHECK YOUR FONT FILE.
After approximately 6 hours of debugging and crying I've figured out that I have a corrupted font file.
Since I was desperate af I just tried to download a new font file and it worked out.
Thanks everyone for trying to help me!
I have a menu that has one gradient type for default state, and one for the hover/active state. The current page is just like the hover/active state, but with an arrow under it. I can't figure out the best way to get that arrow to show up. I tried a border image, but that didn't look right since the button size is different depending on the length of the menu item. Here is the current CSS I am using to create the two different styles:
.main-nav li a {
float: left;
font-size: 15px;
color: #333;
padding: 10px 15px;
text-shadow: 1px 1px #DDD;
border-right: 1px solid rgba(0, 0, 0, .3);
border-left: 1px solid rgba(255, 255, 255, .5);
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0.0, #B3D09E),
color-stop(0.75, #A0B88E)
);
background-image: -o-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -moz-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -webkit-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: -ms-linear-gradient(bottom, #B3D09E 0%, #A0B88E 75%);
background-image: linear-gradient(to bottom, #B3D09E 0%, #A0B88E 75%);
transition: all 300ms;
-moz-transition: all 300ms;
-o-transition: all 300ms;
-webkit-transition: all 300ms;
}
.main-nav .current-menu-item a, .main-nav .current-page-ancestor a, .main-nav li a:hover {
color: #FFF;
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #043420),
color-stop(1, #075A36)
);
text-shadow: none;
background-image: -o-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -moz-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -webkit-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: -ms-linear-gradient(bottom, #043420 0%, #075A36 100%);
background-image: linear-gradient(to bottom, #043420 0%, #075A36 100%);
}
I would like to avoid using jquery if I can. I feel like there should be some way to do this using just CSS instead of placing an image in the center of the button with jquery. Do I place an invisible div under each button with the arrow image centered and display it on the current page?
This is what I was given to follow for my menu. They didn't use quite the correct terminology. The 'Active' part of the image is the Current Page style:
You can use pseudo elements in CSS to add content, like ::after. By using the border property with different widths and colors you get a triangle shape. The only thing that can be a bit tricky is if you need the gradient to continue on to the arrow.
I put together a small demo. Hover the links in the menu to see the arrow.
DEMO
li:hover::after {
content: ' ';
position: absolute;
border: solid 10px transparent;
border-top: solid 0px transparent;
border-width: 10px;
left: 50%;
margin-left: -10px;
border-color: #222 transparent transparent transparent;
}
So i'm creating a navbar (with Twitter Bootstrap) and pick a color for it, and set it to slightly different color when certain element are hovered. but the problem is, the transition doesn't seem to work on chrome, it's working on IE and Firefox so far. any ideas? here's the css transition code (i put it in the normal state, not on :hover):
-webkit-transition: All .50s ease-out;
-moz-transition: All .50s ease-out;
-o-transition: All .50s ease-out;
-ms-transition: All .50s ease-out;
transition: All .50s ease-out;
the color css is like this, if somehow needed:
background-color: hsl(0, 86%, 24%) !important;
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#ed1b1b", endColorstr="#710808");
background-image: -khtml-gradient(linear, left top, left bottom, from(#ed1b1b), to(#710808));
background-image: -moz-linear-gradient(top, #ed1b1b, #710808);
background-image: -ms-linear-gradient(top, #ed1b1b, #710808);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ed1b1b), color-stop(100%, #710808));
background-image: -webkit-linear-gradient(top, #ed1b1b, #710808);
background-image: -o-linear-gradient(top, #ed1b1b, #710808);
background-image: linear-gradient(#ed1b1b, #710808);
border-color: #710808 #710808 hsl(0, 86%, 17%);
color: #fff !important;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.46);
I have some menu items that are styled using a background gradient on hover using the following styling:
#sidebar ul li a:hover {
background-image: linear-gradient(bottom, rgb(68,68,68) 5%, rgb(51,51,51) 100%);
background-image: -o-linear-gradient(bottom, rgb(68,68,68) 5%, rgb(51,51,51) 100%);
background-image: -moz-linear-gradient(bottom, rgb(68,68,68) 5%, rgb(51,51,51) 100%);
background-image: -webkit-linear-gradient(bottom, rgb(68,68,68) 5%, rgb(51,51,51) 100%);
background-image: -ms-linear-gradient(bottom, rgb(68,68,68) 5%, rgb(51,51,51) 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.05, rgb(68,68,68)),
color-stop(1, rgb(51,51,51))
);
color: #f0f0f0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
My question is, is it possible to make the new background (defined by gradients) slide in from the right using CSS3 transitions or animations? Or will I have to resort to using a sprite image or Javascript?
Animation on gradients aren't supported yet. However this site provides a pleasing approach for a animated kind of feel on hover-
http://sapphion.com/2011/10/css3-gradient-transition-with-background-position/
Sample css:-
#DemoGradient{
background: -webkit-linear-gradient(#C7D3DC,#5B798E);
background: -moz-linear-gradient(#C7D3DC,#5B798E);
background: -o-linear-gradient(#C7D3DC,#5B798E);
background: linear-gradient(#C7D3DC,#5B798E);
-webkit-transition: background 1s ease-out;
-moz-transition: background 1s ease-out;
-o-transition: background 1s ease-out;
transition: background 1s ease-out;
background-size:1px 200px;
border-radius: 10px;
border: 1px solid #839DB0;
cursor:pointer;
width: 150px;
height: 100px;
}
#DemoGradient:Hover{
background-position:100px;
}
It seems gradients don't support transitions yet (still):
Use CSS3 transitions with gradient backgrounds
If you use a background image rather than a css3 gradient, then you can use css transition to animate it in and out.
Try this as a hack:
<div class="background-animate">
<div class="content">Hi im content</div>
</div>
And style it
.background-animate {
position: relative;
z-index: 10;
display: block;
background: transparent;
}
.background-animate:before {
content: "";
position: absolute;
transition: opacity .35s ease-in-out;
-moz-transition: opacity .35s ease-in-out;
-webkit-transition: opacity .35s ease-in-out;
top:0; left: 0; right: 0; bottom: 0; z-index:-1;
background: -moz-radial-gradient(center, ellipse cover, #ffffff 40%, #e9eae9 100%); /* FF3.6-15 */
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 40%,#e9eae9 100%); /* Chrome10-25,Safari5.1-6 */
background: radial-gradient(ellipse at center, #ffffff 40%,#e9eae9 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
.background-animate:hover:before {
opacity: 0;
}
.background-animate:after {
content: ""; opacity: 0;
transition: opacity .35s ease-in-out;
-moz-transition: opacity .35s ease-in-out;
-webkit-transition: opacity .35s ease-in-out;
position: absolute;
top:0; left: 0; right: 0; bottom: 0; z-index:-1;
background: -moz-radial-gradient(center, ellipse cover, #ffffff 80%, #e9eae9 100%); /* FF3.6-15 */
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 80%,#e9eae9 100%); /* Chrome10-25,Safari5.1-6 */
background: radial-gradient(ellipse at center, #ffffff 80%,#e9eae9 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
.background-animate:hover:after {
opacity: 1;
}
It basically does an opacity switch between to gradients. Demo found here https://codepen.io/anon/pen/eWOEoR