I'm trying to create a text highlight animation in css like the one in this gif. From left to right continuously.
I tried this
<p>
The <span class="test">world</span>
</p>
.test {
background: linear-gradient(to top, red 50%, transparent 50%);
animation-name: highlight;
animation-duration: 1s;
animation-iteration-count: infinite;
}
#keyframes highlight {
0% {
background-size: 0;
background-position: -100%, 0;
}
50% {
background-size: 100%;
background-position: 100%, 100%;
}
}
But it's giving some weird glitch effect instead. What am I doing wrong and how to achieve this?
You will need to use a pseudo element (preferably :after) and play around with the width of that pseudo element.
.test {
position: relative;
}
.test:after {
content: "";
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
z-index: -1; /* Place the pseudo element right under the content */
top: 0;
left: 0;
background: linear-gradient(to top, red 50%, transparent 50%);
animation-name: highlight;
animation-duration: 0.75s;
animation-iteration-count: infinite;
animation-direction: alternate; /* Make the animation run back and forth */
}
#keyframes highlight {
0% {
width: 0;
opacity: 0;
}
50% {
width: 100%;
opacity: 1;
}
}
<p>
The <span class="test">world</span>
</p>
References:
Pseudo elements :after
Related
I'm trying to make an expanding circle animation from top left corner of the screen to the entire screen.
I got it working as expected but from page center:
#keyframes anim {
0% { clip-path: circle(0% at 50% 50%); }
100% { clip-path: circle(150%); }
}
#backdrop {
background-color: #1B1B1B;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
overflow: scroll;
z-index: 10;
animation-name: anim;
animation-duration: 1s;
animation-iteration-count: 1;
}
<div id="backdrop"></div>
Please change your keyframes as below. You are starting your circle from 50% 50% which is center of the page.
0% {
clip-path: circle(0% at 0% 0%);
}
.full {
width: 100vw;
height: 150px;
background: red;
animation-name: anim;
animation-duration: 2s;
animation-iteration-count: infinite;
}
#keyframes anim {
0% {clip-path: circle(0% at 150% 0%);}
100% {clip-path: circle(150%);}
}
<div class="full"></div>
I am working on creating a Facebook content placeholder with the shimmer effect. I just want to animate the background property (or applying the linear gradient from top left to bottom right,) from the top left and end to the bottom right.
.Box {
height: 100px;
width: 100px;
margin: 16px;
background: #f6f7f8;
border-radius: 50%;
}
.Shine {
display: inline-block;
background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
background-repeat: no-repeat;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-name: placeholderShimmer;
animation-timing-function: linear;
}
#keyframes placeholderShimmer {
0% {
background-position: -1000px 0;
}
100% {
background-position: 10px 0;
}
}
<div class="Shine">
<div class="Box"> </div>
</div>
Now it's growing linearly from left to right.
Youn need to adjust the gradient then consider percentage value to have a better effect:
.Box {
height: 100px;
width: 100px;
margin: 16px;
background: #f6f7f8;
border-radius: 50%;
}
.Shine {
display: inline-block;
background:
linear-gradient(to bottom right, #eeeeee 40%, #dddddd 50%, #eeeeee 60%);
background-size:200% 200%;
background-repeat: no-repeat;
animation:placeholderShimmer 2s infinite linear;
}
#keyframes placeholderShimmer {
0% {
background-position:100% 100%; /*OR bottom right*/
}
100% {
background-position:0 0; /*OR top left*/
}
}
<div class="Shine">
<div class="Box"></div>
</div>
The trick is that the background will be twice as big as the container (200%x200%) with a diagonal direction and we make the coloration in the middle (around 50%). Then we simply slide this big background from top left to bottom right.
Related question for more details: Using percentage values with background-position on a linear-gradient
I am experimenting with some keyframe animations in css which seem to work fine in IE, Chrome, Firefox but not in Microsoft Edge for some reason. I get this flicker at the end of the animation where I guess it shows their final position and sets the opacity to 1 before hiding them once again and restarting the animation. My code is as follows (This is minified for one bubble, but the link below is a codepen for the whole animation):
HTML:
<div class="canvas">
<div class="bubble"></div>
</div>
CSS:
.canvas {
min-height: 100%;
width: 100%;
background: green;
position: absolute;
overflow: hidden;
}
.bubble {
display: block;
border-radius: 100%;
opacity: 0.8;
position: absolute;
}
.bubble:nth-child(1) {
background: radial-gradient(ellipse at center, #E6EBF2 0%, #E6EBF2 46%, #EFF0EC 100%);
width: 7px;
height: 7px;
left: 13vw;
bottom: 52vh;
-webkit-animation: move1 infinite 10s;
animation: move1 infinite 10s;
}
#-webkit-keyframes move1 {
0% {
bottom: -100px;
}
100% {
bottom: 44vh;
-webkit-transform: translate(10px, 0);
transform: translate(10px, 0);
opacity: 0;
}
}
#keyframes move1 {
0% {
bottom: -100px;
}
100% {
bottom: 44vh;
-webkit-transform: translate(10px, 0);
transform: translate(10px, 0);
opacity: 0;
}
}
Here is a codepen i created:
https://codepen.io/anon/pen/BqqMKe
Any help would be appreciated as I can't seem to figure it out.
In firefox pseudo elements are behind the div (this is what I wanted to achieve) but in chrome they are on top. Is this a bug in chrome? Anyone knows how to fix this? Adding z-index to the div didn't help me to solve this problem.
I've also tried to apply some styles to div:hover but then when I hover over the div element it falls behind pseudo elements (in Firefox, in Chrome pseudo elements are already on top).
Demo on codepen https://codepen.io/mariuszdaniel/pen/rzdyRV?editors=1100
#keyframes spin {
from {
transform: rotate(0turn)
translateY(-100%) translateY(50%)
rotate(1turn)
}
to {
transform: rotate(1turn)
translateY(-100%) translateY(50%)
rotate(0turn);
}
}
#keyframes spin-rev {
from {
transform: rotate(1turn)
translateY(-100%) translateY(50%)
rotate(0turn)
}
to {
transform: rotate(0turn)
translateY(-100%) translateY(50%)
rotate(1turn);
}
}
#keyframes glow {
from {
filter: blur(100px);
opacity: 0.8
}
to {
filter: blur(200px);
opacity: 0.4;
}
}
.path {
width:300px;
height: 300px;
padding: 20px;
margin: 100px auto;
border-radius: 50%;
background-image: url(https://unsplash.it/300);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
transition: transform 0.5s, box-shadow 0.5s;
}
.path:hover {
transform: scale(1.25);
box-shadow: 0 0 50px 0 #3333;
}
.path::before, .path::after {
content: "";
position:aboslute;
display: block;
width: 75%;
height: 75%;
margin: 25% auto 0;
border-radius: 50%;
/*filter: blur(100px); */
/*opacity: 0.5;*/
}
.path::before {
/*mix-blend-mode: hue;*/
z-index: -200;
background-color: #21D4FD;
background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
animation: spin 9s infinite /*alternate*/ linear, glow 3s infinite alternate linear;
}
.path::after {
margin-top: -100%;
z-index: -100;
background-color: #08AEEA;
background-image: linear-gradient(0deg, #08AEEA 0%, #2AF598 100%);
animation: spin-rev 6s infinite /*alternate-reverse*/ linear, glow 6s infinite alternate linear;
}
<div class="path"></div>
background: #ececec url(images/x/x.jpg) top left repeat-x;
I want to slide it. It's loopy image. I want to slide it from left to right or right to left. It doesen't matter... How can I do this?
You could try using keyframes, here's a good example;
http://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp
If you want to add animation to background then you can use pseudo element and add animation to it
div {
position: relative;
height: 200px;
width: 200px;
border: 1px solid red;
overflow: hidden;
}
div:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
z-index:-1;
background: url(http://placehold.it/200x200) no-repeat;
-webkit-animation: slide 4s linear infinite;
-moz-animation: slide 4s linear infinite;
animation: slide 4s linear infinite;
}
#-webkit-keyframes slide {
0% {
left: 101%;
}
100% {
left: -101%;
}
}
#-moz-keyframes slide {
0% {
left: 101%;
}
100% {
left: -101%;
}
}
#keyframes slide {
0% {
left: 101%;
}
100% {
left: -101%;
}
}
<div class="slide">
<p>The background image is moving</p>
</div>