Is there an easy way, using only CSS, to enable background image slideshow?
I have the background image defined as fullscreen and responsive inside the html property in CSS and would like it to have a simple transition effect. The CSS looks like this:
html {
background: url(slike/bg.jpg) no-repeat center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Do I need to define it in html and make a new CSS class? The only 'problem' is that the backgrounds need to be fullscreen and responsive.
You can do so by using the container div like this
html,body {
width:100%;
height:100%;
}
body {
margin: 0;
}
.container
{
width:100%;
height:100%;
}
#slideshow {
list-style: none;
margin: 0;
padding: 0;
position: relative;
width:100%;
height:100%;
display: inline-block;
}
.elemnt,.elemnt1,.elemnt2,.elemnt3 {
position: absolute;
left: 0;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
height: 100%;
display: inline-block;
text-align: center;
}
span{
border: 1px solid #000;
border-radius: 3px;
box-shadow: 0 0 5px 0 hsla(0,0%,30%, .3);
font-size:4em;
background-color:#fff
}
.elemnt {
animation: xfade 16s 8s infinite;
background-image: url('http://desert-maroc.com/wordpress2012/wp-content/uploads/trek-sahara-sauvage-min.jpg');
}
.elemnt1 {
animation: xfade 16s 6s infinite;
background-image: url('http://desert-maroc.com/wordpress2012/wp-content/uploads/sahara-desert-by-ellie-1024x683.jpg');
}
.elemnt2 {
animation: xfade 16s 2s infinite;
background-image: url('https://pbs.twimg.com/media/C4JYsjcWYAAixfx.jpg');
}
.elemnt3 {
animation: xfade 16s 0s infinite;
background-image: url('http://desert-maroc.com/wordpress2012/wp-content/uploads/trek-sahara-sauvage-min.jpg');
}
#keyframes xfade{
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
}
#keyframes xfade1{
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
}
#keyframes xfade2{
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
}
#keyframes xfade3{
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
}
<div class="container">
<div id="slideshow">
<div class="elemnt"><span>Text Slider 1</span></div>
<div class="elemnt1"><span>Text Slider 2</span></div>
<div class="elemnt2"><span>Text Slider 3</span></div>
<div class="elemnt3"><span>Text Slider 4</span></div>
</div>
</div>
Try this now the slider is using only css you can modify the timing, by changing the animation duration
Related
This question already has answers here:
Using percentage values with background-position on a linear-gradient
(2 answers)
Closed 3 years ago.
I can't run linear-gradient animation by #keyframes. I think it is due to background-position property in my code that is causing the problem. However, https://webdevtrick.com/css-gradient-background/'>here, background-position property doesn't cause the problem.
I have compared my code to the code at that site to see what essential property is missing in mine. Here is the CSS code:
body {
margin: 0;
}
.navbar {
background-image: linear-gradient(125deg, #337909, #082a87);
height: 10%;
width: 100%;
position: absolute;
-webkit-animation: animebg 5s infinite;
animation: animebg 5s infinite;
background-size: auto;
}
header {
color: aliceblue;
font-family: cursive;
text-align: center;
}
#-webkit-keyframes animebg {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
#keyframes animebg {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
HTML code:
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='theme.css'>
<style>
</style>
</head>
<body>
<header class='navbar'>
<h1>Welcome!</h1>
</header>
<!--<button type="button" class="button1">Yes!</button>-->
</body>
</html>
I think you can't move position with percentage in animation (Use another unit) unless you set background-size to it. Look at the snippet below:
I hope it helps :)
body {
margin: 0;
}
.navbar {
background-image: linear-gradient(90deg, #337909, #082a87, #337909);
background-size: auto;
height: 10%;
width: 100%;
position: absolute;
-webkit-animation: animebg 2.5s linear infinite;
-moz-animation: animebg 2.5s linear infinite;
animation: animebg 2.5s linear infinite;
}
header {
color: aliceblue;
font-family: cursive;
text-align: center;
}
#keyframes animebg {
0% {
background-position: 100vw 50%;
}
100% {
background-position: 0 50%;
}
}
<header class='navbar'>
<h1>Welcome!</h1>
</header>
I can't seem to make this animation move forever without adding more dots in span.
I would like the amount of dots not to be dependent on the "loading-dots" class, as it is adding more dots increases the duration but its a pain. Could it be possible to have a single dot but animate it forever. I like the ability to change the speed and direction.
Here's the CodePen
* {
box-sizing: border-box;
}
body {
padding: 50px;
background: white;
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px 20px 0px 20px;
}
.loading-container {
overflow: hidden;
float: left;
width: 200px;
}
.loading-dots {
display: inline-block;
animation-name: loading-dots;
animation-duration: 5s;
animation-timing-function: linear;
font-size: 50px;
position: relative;
top: -27px;
color: rgba(blue, 1);
font-family: sans-serif;
white-space: no-wrap;
}
.loading-title {
overflow: display;
position: relative;
font-size: 30px;
top: 10px;
margin-right: 10px;
font-family: monospace;
color: rgba(white, 1);
float: left;
}
#keyframes loading-dots {
0% {
transform: translateX(-600px);
}
100% {
transform: translateX(0px);
}
}
<div class="container">
<span class="loading-title"></span>
<div class="loading-container">
<span class="loading-dots">.................
</span>
</div>
</div>
You can do this with a simple background where it will be easy to control the animation and also the dimension of your dots:
.dots {
height:5px; /*to control the overall height*/
width:200px; /*to control the overall width*/
margin:50px;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px, /*5px of transparent*/
blue 5px,blue 10px); /*then 5px of blue */
background-size:200% 100%;
animation:change 3s linear infinite;
}
#keyframes change{
to {
background-position:right;
}
}
<div class="dots"></div>
To change the direction you simply change the position:
.dots {
height:5px;
width:200px;
margin:50px;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
background-size:200% 100%;
background-position:right;
animation:change 3s linear infinite;
}
#keyframes change{
to {
background-position:left;
}
}
<div class="dots"></div>
You can check this for more details about the different values used: Using percentage values with background-position on a linear gradient
Another idea using animation on transform :
.dots {
height:5px;
width:200px;
margin:50px;
position:relative;
overflow:hidden;
}
.dots::before {
content:"";
position:absolute;
top:0;
left:0;
right:-100%;
bottom:0;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
animation:change 3s linear infinite;
}
#keyframes change{
to {
transform:translateX(-50%);
}
}
<div class="dots"></div>
Changing the direction:
.dots {
height:5px;
width:200px;
margin:50px;
position:relative;
overflow:hidden;
}
.dots::before {
content:"";
position:absolute;
top:0;
left:-100%;
right:0;
bottom:0;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
animation:change 3s linear infinite;
}
#keyframes change{
to {
transform:translateX(50%);
}
}
<div class="dots"></div>
Reduce the negative pixel margin. -600px is pretty excessive for 16 dots.
#keyframes loading-dots {
0% {
transform: translateX(-50px);
}
100% {
transform: translateX(0px);
}
}
I have been trying to create a simple image slider showcasing four images for a website. I have managed to create the slideshow, however the transition between each images is really fast and I want a bit of a fade in effect so that it's smoother. A lot of the questions on here already suggest using jQuery but I am trying to do it with just CSS. I've also explored the animate.css but couldn't get it to work. Appreciate any/all help given. Thanks :)
Heres the code so far:
HTML
<div class="slider">
<div class="feature">
</div>
<div class="overlay">
</div>
</div>
and the CSS
.feature {
animation: slide 3s;
}
.slider {
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 80vh;
animation: slide 10s infinite;
}
.overlay {
color: #fff;
width: 100%;
height: 80vh;
background-color: rgba(0, 0, 0, 0.5);
}
#keyframes slide {
0%{
background-image: url(../resources/feature/Feature1.jpg);
}
25%{
background-image: url(../resources/feature/Feature1.jpg);
}
25.1%{
background-image: url(../resources/feature/Feature2.jpg);
}
50%{
background-image: url(../resources/feature/Feature2.jpg);
}
50.01%{
background-image: url(../resources/feature/Feature3.jpg);
}
75%{
background-image: url(../resources/feature/Feature3.jpg);
}
75.01%{
background-image: url(../resources/feature/Feature4.jpg);
}
100%{
background-image: url(../resources/feature/Feature4.jpg);
}
}
You have to set the opacity and transition of the "sliders" to get the effect.
.feature {
}
.slider {
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 80vh;
transition: all .2s ease-in-out;
animation: slide 10s infinite;
}
.overlay {
color: #fff;
width: 100%;
height: 80vh;
background-color: rgba(0, 0, 0, 0.5);
transition: all .2s ease-in-out;
}
#keyframes slide {
0%{
opacity: 0;
background-color: red;
}
20%{
opacity: 1;
background-color: red;
}
25%{
opacity: 0;
background-color: red;
}
25.1%{
opacity: 0;
background-color: blue;
}
45%{
opacity: 1;
background-color: blue;
}
50%{
opacity: 0;
background-color: blue;
}
50.01%{
opacity: 0;
background-color: yellow;
}
70%{
opacity: 1;
background-color: yellow;
}
75%{
opacity: 0;
background-color: yellow;
}
75.01%{
opacity: 0;
background-color: green;
}
95%{
opacity: 1;
background-color: green;
}
100%{
opacity: 0;
background-color: green;
}
}
<div class="slider">
<div class="feature">
</div>
<div class="overlay">
</div>
</div>
Just change the line
animation: slide 10s infinite;
to
animation: slide 20s infinite;
and it would give some time for transition.
you can try to manege animation Opacity and no any other way to create this slider will show & transition.
#keyframes slide {
0%{
background-image: url(https://image.flaticon.com/sprites/new_packs/178146-business-strategy.png);
}
48%{ opacity:0;
}
50%{
opacity:1;
background-image: url(https://images-eu.ssl-images-amazon.com/images/I/51TxXo0RLgL.png);
}
97%{ opacity:1;
98%{ opacity:0;
100%{
opacity:1;
background-image: url(https://image.flaticon.com/sprites/new_packs/178146-business-strategy.png);
}
}
https://jsfiddle.net/m4tsudc7/21/
This question already has answers here:
Background-position not working with CSS animation and linear gradient
(2 answers)
Use CSS3 transitions with gradient backgrounds
(19 answers)
Closed 4 years ago.
I want to move my background using css horizontally.
I've looked at this demo, but they're using an actual image. I want to be able to use rgba / linear-gradient instead.
This is my code:
.chat {
width: 490px;
float: left;
background: #F2F5F8;
color: #434651;
position:absolute;
overflow:hidden;
}
#keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
.chat .chat-header {
/* padding: 20px; */
border-bottom: 2px solid white;
background-image: linear-gradient(135deg, #FF5572, #FF7555);
width:1000px; /*make bigger in order to move */
overflow:hidden;
background-position: 0px 0px;
background-repeat: repeat-x;
animation: animatedBackground 4s linear infinite;
}
<div class="chat">
<div class="chat-header clearfix">
<div class="chat-about">
hi
</div>
</div>
</div>
I want it to animate in the same way as in the demo. How would i achieve that?
You can use background position to translate it through the image background like the example..
.chat {
width: 490px;
float: left;
background: #F2F5F8;
color: #434651;
position:absolute;
overflow:hidden;
}
#keyframes animatedBackground {
0% {
background-position: 0% 0%
}
50% {
background-position: 0% 100%
}
100% {
background-position: 0% 0%
}
}
.chat .chat-header {
/* padding: 20px; */
border-bottom: 2px solid white;
background-image: linear-gradient(180deg, #FF5572, blue, #FF5572);
width:1000px; /*make bigger in order to move */
overflow:hidden;
background-position: 0px 0px;
background-repeat: repeat-x;
animation: animatedBackground 4s linear infinite;
margin:0;
height:400px;
background-size: 100% 400%;
}
<div class="chat">
<div class="chat-header clearfix">
<div class="chat-about">
hi
</div>
</div>
</div>
.chat {
background: linear-gradient(134deg, #ff5572, #ff7555);
background-size: 400% 400%;
animation: Move 4s ease infinite;
}
#keyframes Move {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
There's a great tool for playing around with gradient animations at https://www.gradient-animator.com/
.crossfade > div {
animation: imageAnimation 30s linear infinite 0s;
backface-visibility: hidden;
background-size: cover;
background-position: center center;
color: transparent;
height: 100%;
left: 0px;
opacity: 0;
position: fixed;
top: 0px;
width: 100%;
z-index: 0;
}
.crossfade {
height: 500px;
}
#fade1{
background-image: url('../images/taxi.jpg');
}
#fade2 {
animation-delay: 6s;
background-image: url('../images/default.jpg');
}
#fade3 {
animation-delay: 12s;
background-image: url('../images/neuroBG.JPG');
}
#fade4 {
animation-delay: 18s;
background-image: url('../images/new4.jpeg');
}
#fade5 {
animation-delay: 24s;
background-image: url('../images/new3.jpg');
}
#fade6 {
animation-delay: 30s;
background-image: url('../images/new1.jpg');
}
#fade7 {
animation-delay: 36s;
background-image: url('../images/new2.jpeg');
}
<div class="crossfade">
<div id="fade1"></div>
<div id="fade2"></div>
<div id="fade3"></div>
<div id="fade4"></div>
<div id="fade5"></div>
<div id="fade6"></div>
<div id="fade7"></div>
</div>
I will like to make a background image fade in and out just like this website www.flitways.com
I have tried replicate this but the images are not fading in properly. I just feel that there is something missing. Will appreciate any help as regards this. Thanks.
To make images fade in and out properly, one need to calculate percentages and timings for it to look good, as done below, or simply give each image a #keyframes rule of their own.
For "n" images you must define:
a=presentation time for one image
b=duration for cross fading
Total animation-duration is of course t=(a+b)*n
animation-delay = t/n or = a+b
Percentage for keyframes:
0%
a/t*100%
(a+b)/t*100% = 1/n*100%
100%-(b/t*100%)
100%
Src: http://css3.bradshawenterprises.com/cfimg/
.crossfade > div {
animation: imageAnimation 8s linear infinite;
backface-visibility: hidden;
background-size: cover;
background-position: center center;
color: transparent;
height: 100%;
left: 0;
position: fixed;
top: 0;
width: 100%;
}
.crossfade {
height: 500px;
}
#keyframes imageAnimation {
0% {
opacity:1;
}
17% {
opacity:1;
}
25% {
opacity:0;
}
92% {
opacity:0;
}
100% {
opacity:1;
}
}
.crossfade div:nth-of-type(1) {
background-image: url(http://placehold.it/200/f00);
animation-delay: 6s;
}
.crossfade div:nth-of-type(2) {
background-image: url(http://placehold.it/200/0b0);
animation-delay: 4s;
}
.crossfade div:nth-of-type(3) {
background-image: url(http://placehold.it/200/00f);
animation-delay: 2s;
}
.crossfade div:nth-of-type(4) {
background-image: url(http://placehold.it/200/ff0);
animation-delay: 0;
}
<div class="crossfade">
<div></div>
<div></div>
<div></div>
<div></div>
</div>