I'm following a tutorial on youtube on how to create a Glowing Border Animation with CSS
I tried to implement it myself and was pretty successful, however, I encountered a problem which I'm unable to solve. When I view my animation there is an uneven transition. It looks like as if two images are stuck together where the colours transition is cut off.
How can I solve the issue there with my transition looks smooth?
I created a JSFiddle to display what I mean:
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #151320;
}
.box {
position: relative;
width: 300px;
height: 300px;
color: #fff;
font: 300 2rem 'Montserrat';
text-align: center;
text-transform: uppercase;
display: flex;
align-items: center;
}
.box::before,
.box::after {
content: '';
z-index: -1;
position: absolute;
width: calc(100% + 30px);
height: calc(100% + 30px);
top: -15px;
left: -15px;
background: linear-gradient(45deg, #0096FF, #0047AB, #000000, #6082B6, #87CEEB, #00008B, #145DA0, #00008B, #145DA0, #0096FF, #0047AB, #000000, #6082B6, #87CEEB);
background-repeat: repeat;
border-radius: 5px;
background-size: 600%;
animation: border 12s linear infinite;
}
.box::after {
filter: blur(25px);
}
#keyframes border {
0% {
background-position: 0% 0%;
}
100% {
background-position: 250% 250%;
}
}
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<div class="box">
Greetings fellow developer!
</div>
Note: The animation looks smooth at first but after about 7ish seconds you encounter the "cut off" where the transition doesn't line up.
Your gradient need to have a kind of repetition to achieve such effect. Make its size 200% 200% then use a repeating gradient where the first color start at 0% and the last one at 50%. Notice how the list of color is repeated twice but in the opposite order.
body {
background: #151320;
}
.box {
position: relative;
width: 300px;
height: 300px;
}
.box::before,
.box::after {
content: '';
z-index: -1;
position: absolute;
inset: -15px;
background:
repeating-linear-gradient(45deg,
#0096FF 0%, #0047AB, #6082B6, #87CEEB, #00008B,
#00008B, #87CEEB, #6082B6,#0047AB,#0096FF 50%);
border-radius: 5px;
background-size: 200% 200%;
animation: border 2s linear infinite;
}
.box::after {
filter: blur(25px);
}
#keyframes border {
0% {
background-position: bottom left;
}
100% {
background-position: top right;
}
}
<div class="box">
</div>
Related
I got this shape and trying to achieve this in css3, what I tried so far is:
.door {
width: 150px;
height: 160px;
background-image: linear-gradient(180deg, #234dbc, #b84295);
position: absolute;
top: 100px;
border-radius: 5px;
transform: rotate(17deg) skew(17deg);
background-size: 200% 200%;
animation: Animation 5s ease infinite;
}
#keyframes Animation {
0%{background-position:10% 0%}
50%{background-position:90% 100%}
100%{background-position:10% 0%}
}
<div class="door"></div>
But I couldn't handle this with skew any idea or solution?
You are almost there. Consider a pseudo element to be able to hide the bottom part using overflow:hidden
.door {
width: 100px;
height: 160px;
display: grid;
border-radius: 10px;
overflow:hidden;
transform-origin: bottom;
transform: skewX(-4deg);
}
.door:before {
content:"";
background-image: linear-gradient(180deg, #234dbc, #b84295);
border-radius: inherit;
transform: skewY(17deg);
transform-origin: bottom left;
background-size: 200% 200%;
animation: Animation 5s ease infinite;
}
#keyframes Animation {
50% {
background-position: 90% 100%
}
}
<div class="door"></div>
Always :before solve the problem
.door {
width: 100px;
height: 160px;
background-image: linear-gradient(180deg, #234dbc, #b84295);
position: absolute;
top: 100px;
border-radius: 5px;
background-size: 200% 200%;
animation: Animation 5s ease infinite;
overflow: hidden;
transform: skewX(-2deg)
}
.door::before {
content: "";
position: absolute;
width: 150px;
height: 52px;
background: rgb(248, 248, 248);
top: -30px;
left: 0px;
transform: skewY(18deg);
}
<div class="door"></div>
You should make the :before background like the background of the area to seem like it's transparent
For that i make the background color of the :before rgb(248, 248, 248)
I want to create a gradient border animation starting from the top left to the bottom right. The animation will be used for images within this div.
I tried every degree of angle, but didn't get this to work in the direction I want, it always starts at the right top or at the bottom right.
Also tried it with negative degree values.
.block {
position: relative;
margin: 30px auto 0;
width: 250px;
height: 250px;
background: #272727;
}
.block:before, .block:after {
content: '';
position: absolute;
left: -1px;
top: -1px;
background: linear-gradient(45deg, rgba(0,0,0,0)35%, rgba(0,204,255,1)50%, rgba(0,0,0,0)65%);
background-size: 400%;
width: calc(100% + 2px);
height: calc(100% + 2px);
z-index: -1;
animation: shine 8s linear infinite;
}
#keyframes shine {
to {
background-position: 400% center;
}
}
.block:after {
filter: blur(8px);
}
<div class="block"></div>
Update your code like below:
.block {
position: relative;
margin: 30px auto 0;
width: 250px;
height: 250px;
background: #272727;
}
.block:after {
content: '';
position: absolute;
inset: -1px;
background: linear-gradient(-45deg, rgba(0, 0, 0, 0)35%, rgba(0, 204, 255, 1)50%, rgba(0, 0, 0, 0)65%);
background-size: 400% 400%;
z-index: -1;
animation: shine 3s linear infinite;
filter: blur(8px);
}
#keyframes shine {
from {
background-position: 100% 100%
}
to {
background-position: 0 0
}
}
<div class="block"></div>
This question already has answers here:
Is it possible based on CSS to create a circle with gradient border and transparent inner?
(3 answers)
Closed 4 years ago.
First of all, sorry for the very specific question. I'm not that good at CSS yet and I'd need a code help.
I'd like to make the inside circle transparent, without loosing the gradient effect of the border. How can I do it?
I have this spin loader (see the code snippet)
.spin-loader {
border-radius: 50%;
display: inline-block;
height: 20px;
width: 20px;
position: relative;
animation: spin .675s linear 0s infinite normal;
background: #5090bd;
margin-top: 18px;
margin-left: 205px;
}
.spin-loader:before {
content: "";
display: block;
position: absolute;
border-radius: 0 90px 90px 0;
height: 20px;
width: 50%;
top: 0; right: 0;
z-index: 1;
background: #405060;
background-image: -webkit-gradient(linear, left top, left bottom, from(#5090bd), to(#405060));
background-image: -webkit-linear-gradient(top, #5090bd, #405060);
background-image: -moz-linear-gradient(top, #5090bd, #405060);
background-image: -ms-linear-gradient(top, #5090bd, #405060);
background-image: -o-linear-gradient(top, #5090bd, #405060);
background-image: linear-gradient(to bottom, #5090bd, #405060);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#5090bd, endColorstr=#405060);
}
.spin-loader:after {
content: "";
display: block;
position: absolute;
border-radius: 80%;
height: 16px;
width: 16px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
background: #405060;
}
/* Safari */
#-webkit-keyframes spin {
to {
transform: rotate(360deg);
}
}
#keyframes spin {
to {
transform: rotate(360deg);
}
}
<!DOCTYPE html>
<html>
<body>
<div class="spin-loader"></div>
</body>
</html>
Thanks!
You cannot make this spin loader transparent, because there is some trick to get effect of decreasing opacity of rotating stripe, which cannot be done without full cover this loader with background. You can try and see what will happen when you delete or change background for .spin-loader:after.
This question already has an answer here:
Background-image in keyframe does not display in Firefox or Internet Explorer
(1 answer)
Closed 5 years ago.
I need help to make animation like linear gradient using CSS that ends with transparent color on image..
This is an example (if Possible):
Current effect achieved by creating linear gradient transparent-white-transparent and moving background forward/back on :hover.
here's solution for placing image under this animation. but please keep in mind endless animation might be very distractive and annoying for your users
.wrapper {
position: relative;
width: 350px;
height: 150px;
/*border: 2px solid #444;*/
border-radius: 10px;
overflow: hidden;
}
img {
position: relative;
z-index: 0;
width: 100%;
}
.gradient {
transition: background-position .5s;
background-size: 200% auto;
box-shadow: 0 0 20px #eee;
font: 0;
position: absolute;
z-index: 1;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.gradient {
background-image: linear-gradient(to top, transparent 0%, white 51%, transparent 100%);
background-position: center bottom;
}
.gradient:hover {
background-position: center top;
}
.gradient.animated {
animation: gradient 2s infinite;
}
#keyframes gradient {
0% {
background-position: center bottom;
}
50% {
background-position: center top;
}
100% {
background-position: center bottom;
}
}
<div class='wrapper'>
<div href='#' class='gradient'></div>
<img src='http://lorempixel.com/350/150/sports/' />
</div>
<div class='wrapper'>
<div href='#' class='gradient animated'></div>
<img src='http://lorempixel.com/350/150/sports/' />
</div>
and simplier example for better understanding
you can find more in article below
w3schools about CSS3 Gradients
.gradiented {
transition: background-position .5s;
background-size: 200% auto;
box-shadow: 0 0 20px #eee;
border-radius: 10px;
width: 200px;
height: 200px;
}
.gradiented {
background-image: linear-gradient(to top, #283048 0%, #859398 51%, #283048 100%);
background-position: center bottom;
}
.gradiented:hover {
background-position: center top;
}
<div href='#' class='gradiented'></div>
i am trying to get the background color to change on hover. Something like this.
I have tried various approaches but cannot get it to work, presumably it is the way my CSS and HTML is set up. I cannot figure out why it is not working, as it should be easy to implement
Please see code below.
CSS
.image-container {
position: relative;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 100%;
height: 100%;
display: none;
color: #FFF;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, red 50%, black 50%);
-webkit-transition: background-position 1s;
-moz-transition: background-position 1s;
transition: background-position 1s;
}
.image-container .after p {
position: relative;
text-align: center;
font-size: 26px;
text-transform: uppercase;
font-weight: 300;
line-height: 300px;
height: 300px;
}
.image-container:hover .after {
display: block;
background: rgba(0,0,0,0.3);
background-position: 0 -100%;
}
[class*='col-'] {
float: left;
}
.col-1-3 {
width: 33.33%;
}
HTML
<div class="col-1-3 image-container">
<img class="portrait-image geysir" src="images/geysir.jpg">
<div class="after">GEYSIR</div>
</div>
Remove the background declaration on the hover. It's overriding all the other backgrounds you declared previously.
.image-container:hover .after {
display: block;
background-position: 0 -100%;
}
It should then work.
Based on the given fiddle, I would use a transparent .png image as a second overlapping element like that. Not sure if that's your intention...
.container{
position:relative;
}
.box {
width: 400px; height: 200px;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, red 50%, black 50%);
-webkit-transition: background-position 1s;
-moz-transition: background-position 1s;
transition: background-position 1s;
}
.box:hover {
background-position: 0 -100%;
}
.geysir{
position:absolute;
top:0px;
}
<div class="container">
<div class="box"></div>
<img class="portrait-image geysir" src="http://cdn.mysitemyway.com/etc-mysitemyway/icons/legacy-previews/icons-256/high-resolution-dark-blue-denim-jeans-icons-arrows/008776-high-resolution-dark-blue-denim-jeans-icon-arrows-hand-pointer1-right.png">
</div>
Do you want to have the background, including the text slide in from the top on hover? In which case you would be better transitioning a bottom move like this:
.image-container {
position: relative;
overflow: hidden;
}
.image-container .after {
position: absolute;
bottom: 100%;
margin: auto;
width: 100%;
height: 100%;
color: #fff;
background-color: black;
-webkit-transition: bottom 1s;
-moz-transition: bottom 1s;
transition: bottom 1s;
}
.image-container:hover .after {
bottom: 0;
}
Fiddle
If you're looking to have your text appear on a red background that shifts to black, try using a combination of the above with what you were using. Avoid using display: none/block as this stops the transistion from functioning.
.image-container {
position: relative;
overflow: hidden;
}
.image-container .after {
position: absolute;
bottom: 100%;
margin: auto;
width: 100%;
height: 100%;
color: #fff;
background-size: 100% 200%;
background-image: linear-gradient(to bottom, red 50%, black 50%);
-webkit-transition: background-position 2s;
-moz-transition: background-position 2s;
transition: background-position: 2s;
}
.image-container:hover .after {
bottom: 0;
background-position: 0 -100%;
}
Fiddle