How do i place text over crossfading slider? - html

How could I place a text over the image?
When I try it just makes the text stay in one of the images.
I don't want the text to change or disappear, it has to be the same text for all the images.
I have tried to set position as absolute and place it over the image but won't show for all images just the first one.
.slider {
max-width: 1080px;
height: 95%;
margin: 0 auto;
padding-top: 120px;
position: relative;
}
.slide1,.slide2,.slide3 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
background: url(images/child.jpg)no-repeat center;
background-size: cover;
animation:fade 8s infinite;
-webkit-animation:fade 8s infinite;
}
.slide2 {
background: url(images/tech.jpg)no-repeat center;
background-size: cover;
animation:fade2 8s infinite;
-webkit-animation:fade2 8s infinite;
}
.slide3 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
background-size: cover;
animation:fade3 8s infinite;
-webkit-animation:fade3 8s infinite;
}
#keyframes fade
{
0% {opacity:1}
33.333% { opacity: 0}
66.666% { opacity: 0}
100% { opacity: 1}
}
#keyframes fade2
{
0% {opacity:0}
33.333% { opacity: 1}
66.666% { opacity: 0 }
100% { opacity: 0}
}
#keyframes fade3
{
0% {opacity:0}
33.333% { opacity: 0}
66.666% { opacity: 1}
100% { opacity: 0}
}
<div class="slider">
<div class="slide1"></div>
<div class="slide2"></div>
<div class="slide3"></div>
</div>

Add an element, position it absolute also, and give it a bigger z-index than that of the images.
.slider {
position: relative;
max-width: 1080px;
height: 95vh;
margin: 0 auto;
padding-top: 120px;
overflow: hidden;
}
.slider-text {
position: absolute;
left: 0;
top: 0 z-index: 2;
}
<div class="slider">
<div class="slider-text"> My text </div>
<div class="slide1"></div>
<div class="slide2"></div>
<div class="slide3"></div>
</div>
Change the left/top properties to reposition it.

Related

css insert image inside linear-gradient half part

I have a css background animation that separate the screen into 2 color part, div 1 left is black and div 2 right is white. However I want to make the div 2 right white part to become a image background while black part remain.
How do I insert the image cover into the right white part without affect the left black part
this is the example image cover I would like to cover in div 2
below is my code
body,
html {
margin: 0;
padding: 0;
}
.bg {
min-height: 100vh;
animation: BgAnimation;
-webkit-animation: BgAnimation;
-moz-animation: BgAnimation;
background: linear-gradient(106deg, #313131 50%, white 50.1%);
animation-duration: 1.3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-timing-function: ease-in-out;
background-size: 200% 200%;
}
#keyframes BgAnimation {
0% {
background-position: 0% 0%;
}
100% {
background-position: 50% 50%;
}
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#wrapper {
display: flex;
}
#left {
flex: 0 0 65%;
color: white;
margin-left: 10%;
margin-top: 20%;
animation: fadein 3s;
}
#right {
flex: 1;
margin-right: 5%;
margin-top: 20%;
font-size: 21px;
text-align: center;
animation: fadein 6s;
-moz-animation: fadein 6s; /* Firefox */
-webkit-animation: fadein 6s; /* Safari and Chrome */
-o-animation: fadein 6s;
}
<body>
<div class="bg">
<div id="wrapper">
<div id="left">1 div</div>
<div id="right">2 div</div>
</div>
</div>
</body>
make your gradient black/transparent and put the image below it:
body {
margin: 0;
}
.bg {
min-height: 100vh;
background:
linear-gradient(106deg, #313131 50%, transparent 50.1%),
url(https://i.stack.imgur.com/bPLa1m.jpg) right;
animation: BgAnimation 1.3s forwards;
background-size: 200% 200%,80% auto;
}
#keyframes BgAnimation {
0% {
background-position: 0% 0%,right;
}
100% {
background-position: 50% 50%,right;
}
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#wrapper {
display: flex;
}
#left {
flex: 0 0 65%;
color: white;
margin-left: 10%;
margin-top: 20%;
animation: fadein 3s;
}
#right {
flex: 1;
margin-right: 5%;
margin-top: 20%;
font-size: 21px;
text-align: center;
animation: fadein 6s;
}
<div class="bg">
<div id="wrapper">
<div id="left">1 div</div>
<div id="right">2 div</div>
</div>
</div>

Css3 animation doesn't work on firefox (background faded)

I wrote animation of changing background and it work every browser besides firefox. On FF background is changing but without animation effect. I tried out #-webkit-keyframes but it didn't helped.
Thats the code:
https://jsfiddle.net/tkw5pfm8/
background-image fade animation in FF is really disables. You will have to use separate divs with background-image for that
* {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
min-height: 100%;
margin: 0;
padding: 0;
}
.background {
width: 100%;
height: 100%;
position: absolute;
}
.background>div {
width: 100%;
height: 100%;
position: absolute;
background-size: cover;
background-position: center;
}
.slide1 {
background-image: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569__340.jpg);
animation: fade 8s infinite;
}
.slide2 {
background-image: url(https://c4.wallpaperflare.com/wallpaper/246/739/689/digital-digital-art-artwork-illustration-abstract-hd-wallpaper-thumb.jpg);
animation: fade2 8s infinite;
}
.slide3 {
background-image: url(https://wallpaperplay.com/walls/full/c/5/3/34778.jpg);
animation: fade3 8s infinite;
}
#keyframes fade {
0% {
opacity: 1
}
33.333% {
opacity: 0
}
66.666% {
opacity: 0
}
100% {
opacity: 1
}
}
#keyframes fade2 {
0% {
opacity: 0
}
33.333% {
opacity: 1
}
66.666% {
opacity: 0
}
100% {
opacity: 0
}
}
#keyframes fade3 {
0% {
opacity: 0
}
33.333% {
opacity: 0
}
66.666% {
opacity: 1
}
100% {
opacity: 0
}
}
<div class='background'>
<div class='slide1'></div>
<div class='slide2'></div>
<div class='slide3'></div>
</div>
Or better, use some simple JS slider, like Swiper
https://swiperjs.com/demos/#fade_effect

Animate Infinite Scrolling Background Image

I want to infinite Scroll Background image animate. How can I set it just go upwards continuously, not come back down? still, it gives a jerk.
How it is possible? Please help anyone know it.
I have a link:
http://herinshah.com/wp/fortiflex/5-2/
CSS:
.et_pb_section.landing-page .et_pb_column_3_5 {
background-color: #f6eb00;
margin-right: 1%;
padding: 0 10px;
height: 100vh;
background-image: url(images/ragazzi-logo.png);
background-position: 0 0;
background-size: cover;
-webkit-animation: upward 15s linear infinite;
animation: upward 15s linear infinite;
border-right: 4px solid #000;
display: block;
background-repeat: repeat-y;
}
#-webkit-keyframes upward {
to {
background-position: 0 0;
}
from {
background-position: 0 2174px;
}
}
#keyframes upward {
to {
background-position: 0 0;
}
from {
background-position: 0 2174px;
}
}
You need to wrap a div inside a div. Here is the working fiddle for the same
HTML
<div class="main">
<div class="holder"></div>
</div>
CSS
*{
margin:0;
padding:0
}
.main {
height: 100vh;
overflow: hidden;
}
.holder {
height: 200vh;
-webkit-animation: upwards 2.5s linear infinite;
animation: upward 2.5s linear infinite;
background: url(http://herinshah.com/wp/fortiflex/wp-content/themes/Divi/images/ragazzi-logo.png) center yellow;
background-size: 100% 50%;
}
#-webkit-keyframes upward {
from {
background-position: 0% 0%;
}
to {
background-position: 0% -100%;
}
}
#keyframes upward {
from {
background-position: 0% 0%;
}
to {
background-position: 0% -100%;
}
}
I felt so compelled to answer this because I've done something similar :before (pun intended) and your skipping animation was giving me cancer.
You're gonna need to mess around with the pseudo :after element and get the height right. This should get you started.
Also your image isn't cropped perfectly right, so fix that and you'll be good to go.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body onload="onloaded()">
<div class="foo_section">
<div class="foo_container">
<img class="foo_image" src="http://herinshah.com/wp/fortiflex/wp-content/themes/Divi/images/ragazzi-logo.png" />
</div>
</div>
</body>
</html>
.foo_section {
width: 100vw;
height: 100vh;
position: fixed;
min-height: 400px;
}
.foo_container {
width: 100%;
position: relative;
animation: infiniteScrollBg 10s infinite linear;
}
.foo_container:after {
content: "";
height: 500%;
width: 100%;
position: absolute;
left: 0;
top: 0;
background-color: #f6eb00;
background-image: url('http://herinshah.com/wp/fortiflex/wp-content/themes/Divi/images/ragazzi-logo.png');
background-size: 100% 20%;
}
.foo_image {
width: 100%;
}
#-webkit-keyframes infiniteScrollBg {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(-200%);
}
}
Codepen
I see you're using Elegant Themes too. <3 Divi builder
I suggest you to have two div tags with the same background. Then, animate the same div and play with positioning of the divs and animate to make it look continuously scrolling up.
.container{
width:600px;
height:400px;
background-color:yellow;
margin:0 auto;
position:relative;
overflow:hidden;
}
.bg{
width:100%;
height:400px;
background-repeat:no-repeat;
background-size:contain;
position:absolute;
bottom:0;
}
.bg.bg1{
transform: translate(0,0);
animation: upward 3s linear infinite;
}
.bg.bg2{
transform: translate(0,100%);
animation: upward2 3s linear infinite;
}
#keyframes upward {
to {
transform: translate(0,-100%);
}
from {
transform: translate(0, 0);
}
}
#keyframes upward2 {
to {
transform: translate(0,0);
}
from {
transform: translate(0,100%);
}
}
Here's how I would do it. my codepen.

How to add delay on image fade and only make one image visible at the time?e

I have a css fader, but it fades way to fast for anyone to read, and I cant seem to find a solution.
Once a image is fading, its also going 50% into the other image showing both images at 50%, how can I go around this so it only shows 1 image at the time?
Thanks!
There's always a problem with me and adding code somehow.. here's a codepen link.
HTML:-
<div class='slider'>
<img class="slide1" style="background: url(https://i.imgur.com/Jor6iZe.png)no-repeat center;" alt="">
<img id="img2" class="slide1" src="http://i.imgur.com/3N7tUT2.png">
<img class="slide2" style="background: url(https://i.imgur.com/h797HTW.png)no-repeat center;" alt="">
<img id="img2" class="slide2" src="http://i.imgur.com/0GQZobp.png">
<img class="slide3" style="background: url(https://i.imgur.com/n04pyfC.png)no-repeat center;" alt="">
<img id="img2" class="slide3" src="http://i.imgur.com/lfRhiqe.png">
</div>
CSS
.slider {
max-width: 1140px;
height: 200px;
margin: 20px auto;
position: relative;
}
.slide1,.slide2,.slide3,.slide4,.slide5 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
background-size: cover;
animation:fade 15s infinite;
-webkit-animation:fade 5s infinite;
}
.slide2 {
background-size: cover;
animation:fade2 15s infinite;
-webkit-animation:fade2 5s infinite;
}
.slide3 {
background-size: cover;
animation:fade3 15s infinite;
-webkit-animation:fade3 5s infinite;
}
#keyframes fade
{
0% {opacity:1}
33.333% { opacity: 0}
66.666% { opacity: 0}
100% { opacity: 15}
}
#keyframes fade2
{
0% {opacity:0}
33.333% { opacity: 15}
66.666% { opacity: 0 }
100% { opacity: 0}
}
#keyframes fade3
{
0% {opacity:0}
33.333% { opacity: 0}
66.666% { opacity: 15}
100% { opacity: 0}
}
Codepen Link
HTML
<div class='slider'>
<img class="slide1" style="background: url(https://i.imgur.com/Jor6iZe.png)no-repeat center / cover;" alt="">
<img class="slide2" style="background: url(https://i.imgur.com/h797HTW.png)no-repeat center / cover;" alt="">
<img class="slide3" style="background: url(https://i.imgur.com/n04pyfC.png)no-repeat center / cover;" alt="">
</div>
CSS
.slide1 {
animation:fade 10.5s infinite;
-webkit-animation:fade 10.5s infinite ;
}
.slide2 {
animation:fade1 10.5s infinite;
-webkit-animation:fade1 10.5s infinite;
}
.slide3 {
animation:fade2 10.5s infinite;
-webkit-animation:fade2 10.5s infinite;
}
#keyframes fade
{
0% { opacity: 1 }
28.57% { opacity: 1 }
30.95% { opacity: 0 }
97.61% { opacity: 0 }
100% { opacity: 1 }
}
#keyframes fade1
{
0% { opacity: 0}
30.95% { opacity: 0 }
33.33% { opacity: 1 }
61.9% { opacity: 1 }
64.28% { opacity: 0 }
100% { opacity: 0 }
}
#keyframes fade2
{
0% { opacity: 0}
64.28% { opacity: 0 }
66.66% { opacity: 1 }
95.23% { opacity: 1 }
97.61% { opacity: 0 }
100% { opacity: 0 }
}

Using keyframes to create cyclic animation

I am working on a CSS only slider. However I don't have much experience with using keyframes.
I found this pen; could someone explain to me how the keyframes ensure that the animation runs in a cyclic manner rather than at the same time (where all the slides would disappear and reappear together)?
Code pen link
.slider {
max-width: 300px;
height: 200px;
margin: 20px auto;
position: relative;
}
.slide1,
.slide2,
.slide3,
.slide4,
.slide5 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
background-size: cover;
animation: fade 8s infinite;
-webkit-animation: fade 8s infinite;
}
.slide2 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371565525_p17tbqpu0d69c21hetd77dh483.jpeg)no-repeat center;
background-size: cover;
animation: fade2 8s infinite;
-webkit-animation: fade2 8s infinite;
}
.slide3 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
background-size: cover;
animation: fade3 8s infinite;
-webkit-animation: fade3 8s infinite;
}
#keyframes fade {
0% {
opacity: 1
}
33.333% {
opacity: 0
}
66.666% {
opacity: 0
}
100% {
opacity: 1
}
}
#keyframes fade2 {
0% {
opacity: 0
}
33.333% {
opacity: 1
}
66.666% {
opacity: 0
}
100% {
opacity: 0
}
}
#keyframes fade3 {
0% {
opacity: 0
}
33.333% {
opacity: 0
}
66.666% {
opacity: 1
}
100% {
opacity: 0
}
}
<div class='slider'>
<div class='slide1'></div>
<div class='slide2'></div>
<div class='slide3'></div>
</div>
This is due to the each slide using a different keyframe, i.e. slide1 uses fade, slide2 uses fade2 and slide3 uses fade3. These keyframes all last 8 seconds however the frame in which the slide is shown is different:
slide1 is shown at 0% (0 seconds)
slide2 is shown at 33.333% (about 2.6 seconds)
slide3 is shown at 66.666% (about 5.3 seconds)
This particular method will work when you have three slides but would need to be adapted if you were to have a different amount. For example with four you would need to add an extra step to the keyframe:
.slider {
max-width: 300px;
height: 200px;
margin: 20px auto;
position: relative;
}
.slide1,
.slide2,
.slide3,
.slide4,
.slide5 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
background-size: cover;
animation: fade 8s infinite;
-webkit-animation: fade 8s infinite;
}
.slide2 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371565525_p17tbqpu0d69c21hetd77dh483.jpeg)no-repeat center;
background-size: cover;
animation: fade2 8s infinite;
-webkit-animation: fade2 8s infinite;
}
.slide3 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
background-size: cover;
animation: fade3 8s infinite;
-webkit-animation: fade3 8s infinite;
}
.slide4 {
background: red;
background-size: cover;
animation: fade4 8s infinite;
-webkit-animation: fade4 8s infinite;
}
#keyframes fade {
0% {
opacity: 1
}
25% {
opacity: 0
}
50% {
opacity: 0
}
75% {
opacity: 0
}
100% {
opacity: 1
}
}
#keyframes fade2 {
0% {
opacity: 0
}
25% {
opacity: 1
}
50% {
opacity: 0
}
75% {
opacity: 0
}
100% {
opacity: 0
}
}
#keyframes fade3 {
0% {
opacity: 0
}
25% {
opacity: 0
}
50% {
opacity: 1
}
75% {
opacity: 0
}
100% {
opacity: 0
}
}
#keyframes fade4 {
0% {
opacity: 0
}
25% {
opacity: 0
}
50% {
opacity: 0
}
75% {
opacity: 1
}
100% {
opacity: 0
}
}
<div class='slider'>
<div class='slide1'></div>
<div class='slide2'></div>
<div class='slide3'></div>
<div class='slide4'></div>
</div>
As suggested by #ILoveCSS this code can be shortened to just the one keyframe animation by adding a third property to the animation property. This value is the animation-delay property and will stall the animation by the specified time:
.slider {
max-width: 300px;
height: 200px;
margin: 20px auto;
position: relative;
}
.slide1,.slide2,.slide3,.slide4,.slide5 {
position: absolute;
width: 100%;
height: 100%;
}
.slide1 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
background-size: cover;
animation:fade 8s infinite;
-webkit-animation:fade 8s infinite;
}
.slide2 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371565525_p17tbqpu0d69c21hetd77dh483.jpeg)no-repeat center;
background-size: cover;
animation:fade 8s infinite 2.6s;
-webkit-animation:fade 8s infinite 2.6s;
}
.slide3 {
background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
background-size: cover;
animation:fade 8s infinite 5.3s;
-webkit-animation:fade 8s infinite 5.3s;
}
#keyframes fade
{
0% {opacity:1}
33.333% { opacity: 0}
66.666% { opacity: 0}
100% { opacity: 1}
}
<div class='slider'>
<div class='slide3'></div>
<div class='slide2'></div>
<div class='slide1'></div>
</div>
I think what he is trying is:
#keyframes fade
{
0% {opacity:1}
33.333% { opacity: 0}
66.666% { opacity: 0}
100% { opacity: 1}
}
in this case slide1 is getting visible at the start of the animation and stops when it reached 33.333% and 66.666% and starts to visible at the end of the animation which is 100%.
#keyframes fade2
{
0% {opacity:0}
33.333% { opacity: 1}
66.666% { opacity: 0 }
100% { opacity: 0}
}
in the second slide2 at the start of the animation is not showing because slide1 is in the playing of it's animation and when slide1 reaches 33.333% started to stop and slide2 will start to fadeIn.
#keyframes fade3
{
0% {opacity:0}
33.333% { opacity: 0}
66.666% { opacity: 1}
100% { opacity: 0}
}
in the third slide3 the animation start to fadeIn at 66.666% because at this percent slide2 is in fadeOut state and it continue like this infinitely...
Hope you have an idea.