I've just copied this codepen to my page.
It works well, but I have some other content on my page as well, and the problem is that when I import this code, it destroys all links and other images on my page. Does anyone know why is this happening, and how to solve this? :)
HTML
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<div id="slider">
<figure>
<img src="austin-fireworks.jpg" alt>
<img src="taj-mahal_copy.jpg" alt>
<img src="ibiza.jpg" alt>
<img src="ankor-wat.jpg" alt>
<img src="austin-fireworks.jpg" alt>
</figure>
</div>
CSS
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
body { margin: 0; }
div#slider { overflow: hidden; }
div#slider figure img { width: 20%; float: left; }
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
It probably destroys all links and everything else because of
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
Which will make it so that your links and references are based on off of that. As per mozilla developers:
The HTML <base> element specifies the base URL to use for all relative
URLs contained within a document. There can be only one element
in a document.
Solution for you case in particular:
Remove that base href element on top of your page, and update the sources for each image in the slider individually for its absolute URL.
**here's what i have so far and it's working properly **
<div id="slider">
<div class="slider-title">
<h2>best seller</h2>
</div>
<figure>
<img src="simon-lee-TW93DCT6T_U-unsplash.jpg" alt="sample photo">
<img src="colin-cassidy-wdG7v-9pJ1A-unsplash.jpg" alt="sample photo">
<img src="massimiliano-corradini-Nylf-HeGX2w-unsplash.jpg" alt="sample photo">
<img src="studio-blackthorns-C7vX_SBPrqk-unsplash.jpg" alt="sample photo">
<img src="simon-lee-TW93DCT6T_U-unsplash.jpg" alt="sample photo">
</figure>
</div>
and this is my css
#slider {
margin-top: 25px;
background: #417378;
border-radius: 10px;
overflow: hidden;
}
#slider figure {
border-radius: 10px;
position: relative;
width: 500%;
margin: 0;
left: 0;
animation: 20s slider infinite;
}
#slider figure img {
width: 20%;
height: 400px;
float: left;
margin-top: -25px;
}
#keyframes slider {
0% {
border-radius: 10px;
left: 0;
}
20% {
border-radius: 10px;
left: 0;
}
25% {
border-radius: 10px;
left: -100%;
}
45% {
border-radius: 10px;
left: -100%;
}
50% {
border-radius: 10px;
left: -200%;
}
70% {
border-radius: 10px;
left: -200%;
}
75% {
border-radius: 10px;
left: -300%;
}
95% {
border-radius: 10px;
left: -300%;
}
100% {
border-radius: 10px;
left: -400%;
}
}
Related
I just made a slider with the help of this site: https://la-cascade.io/un-carrousel-responsif-en-pur-css/.
it works very well only it is way too big on my site I would really like to provide the modification but I can not do it someone knows how to do it
My CSS:
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
body { margin: 0; }
div#slider { overflow: hidden; }
div#slider figure img { width: 20%; height: auto; float: left; }
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
My HTML:
<figure id="slide">
<img src="img/6.jpg" alt>
<img src="img/7.jpg" alt>
<img src="img/8.jpg" alt>
<img src="img/9.jpg" alt>
<img src="img/10.jpg" alt>
</figure>
I checked the material you linked to. This post shows how tag <figure> is wrapped in an additional div, with id slider:
<div id="slider">
...
</div>
To set dimensions, you can assign a width rule to css for #slider. Like here:
div#slider {
...
width: 500px;
}
body {
margin: 0;
}
div#slider {
overflow: hidden;
width: 500px;
}
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
div#slider figure img {
width: 20%;
height: auto;
float: left;
}
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
<div id="slider">
<figure>
<img src="https://st.depositphotos.com/2000885/1902/i/600/depositphotos_19021343-stock-photo-red-heart.jpg" alt>
<img src="https://st.depositphotos.com/2000885/1902/i/600/depositphotos_19021343-stock-photo-red-heart.jpg" alt>
<img src="https://st.depositphotos.com/2000885/1902/i/600/depositphotos_19021343-stock-photo-red-heart.jpg" alt>
<img src="https://st.depositphotos.com/2000885/1902/i/600/depositphotos_19021343-stock-photo-red-heart.jpg" alt>
<img src="https://st.depositphotos.com/2000885/1902/i/600/depositphotos_19021343-stock-photo-red-heart.jpg" alt>
</figure>
</div>
i am trying to create my slider by using css animation properties. for this i have created slider which is working but when i tried to add captions its working too but caption are showing below the slider images not at center of the images even i added absolute position. here is my code. i also gave relative position to its parent div but still not working
*{
margin: 0;
padding: 0;
}
#fullwrapper{
width: 100%;
height: auto;
}
/*=========================Slider Style======================*/
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
#keyframes caps {
0% { left: 0%; float: none; }
20% { left: 0%; float: none;}
25% { left: -100%; float: none;}
45% { left: -100%; float: none;}
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
#slider { overflow: hidden; }
#slider figure img { width: 20%; float: left; }
#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
#captions{
position: absolute;
top: 50%;
left: 50%;
width: 500%;
animation: 30s caps infinite;
}
.caption{
width: 20%;
float: left;
font-size: xx-large;
font-weight: bold;
color: red;
font-variant: small-caps;
}
/*=========================Slider Style======================*/
#navbar{
width: 100%;
height: 40px;
background-color: transparent;
position: absolute;
top: 0;
}
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<div id="fullwrapper"> <!-- Start of Full Body Wrapper-->
<div id="header"> <!-- Start of of Header-->
<div id="slider">
<figure>
<img src="austin-fireworks.jpg" alt>
<img src="taj-mahal_copy.jpg" alt>
<img src="ibiza.jpg" alt>
<img src="ankor-wat.jpg" alt>
<img src="austin-fireworks.jpg" alt>
</figure>
<div id="navbar">
<nav>
Home
</nav>
</div>
<figure id="captions">
<span class="caption">some caption text 1</span>
<span class="caption">some caption text 2</span>
<span class="caption">some caption text 3</span>
<span class="caption">some caption text 4</span>
<span class="caption">some caption text 5</span>
</figure>
</div>
</div><!-- End of Header-->
</div> <!-- End of Full Body Wrapper-->
I solved it by myself. I wrapped the caption div in one other div then I set it to use absolute position and it is working fine.
I have successfully implemented a slide show here is my code
HTML
<div id="slider">
<figure>
<img src="images/slides/1.jpg" alt>
<img src="images/slides/1.jpg" alt>
<img src="images/slides/1.jpg" alt>
<img src="images/slides/1.jpg" alt>
<img src="images/slides/1.jpg" alt>
<img src="images/slides/1.jpg" alt>
</figure>
<div>
CSS:
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%; }
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; }
}
div#slider { overflow: hidden; }
div#slider figure img { width: 20%; float: left; }
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 30s slidy infinite;
}
Live Demo:
https://codepen.io/RamBM/pen/PEJXqg
Now here is my question is how to implement the next button arrow and previous button arrow in the slide show.
EDIT:
Good progress... By updating the following code, I almost get exactly what I want to achieve, but I don't understand exactly why it almost works. Spacing both sides during transition, spacing hidden after transition, but with a slight amount of clipping of image: https://codepen.io/anon/pen/LWqPJB
body {
margin: -6%;
}
div#slider {
overflow: hidden;
}
div#slider figure img {
width: 18%;
float: left;
padding-left: 1%;
padding-right: 1%;
}
Although, it's not a perfect solution, the second alternative that seems to do the job is:
div#slider {
margin-left: -6%;
margin-right: -6%;
overflow: hidden;
}
div#slider figure img {
width: 18%;
margin-left: 1%;
margin-right: 1%;
float: left;
}
Problem
I'm implementing a simple image slideshow in a webpage using only HTML and CSS. The code I am starting with is below and at https://codepen.io/anon/pen/wJRVwP
Currently each slide follows the next with no space between images (image 1). However, I'm trying to add a 100px space between each image that is only visible during the transition. So attempting to add a gap, I change the CSS code below;
from:
div#slider figure img { width: 20%; float: left;}
(demo 1: https://codepen.io/anon/pen/wJRVwP)
to:
div#slider figure img { width: 20%; float: left; padding-left: 100px;}
(demo 2: https://codepen.io/anon/pen/vxvoNy)
The result of changing the code adds a 100px space between all images, but, the code change introduces a new problem — images no longer align and progressively get worse after each slide change (image 2).
Question
How can I achieve a space between images and fix this? In code, how
can I change the CSS code to add a 100px space between each image, and keep
all images aligned during and after transition?
Images
demo 1 during transition.
demo 1 after transition.
required outcome.
Code
https://codepen.io/anon/pen/wJRVwP
#keyframes slidy {
0% {
left: 0%;
}
20% {
left: 0%;
}
25% {
left: -100%;
}
45% {
left: -100%;
}
50% {
left: -200%;
}
70% {
left: -200%;
}
75% {
left: -300%;
}
95% {
left: -300%;
}
100% {
left: -400%;
}
}
body {
margin: 0;
}
div#slider {
overflow: hidden;
}
div#slider figure img {
width: 20%;
float: left;
}
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 20s slidy infinite;
}
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<div id="slider">
<figure>
<img src="austin-fireworks.jpg" alt>
<img src="taj-mahal_copy.jpg" alt>
<img src="austin-fireworks.jpg" alt>
<img src="ankor-wat.jpg" alt>
<img src="austin-fireworks.jpg" alt>
</figure>
</div>
apply a box-sizing:border-box property to all img. Add padding left and right (it look somewhat odd if you don't pad both sides).
These are the css adjustments
div#slider figure img {
width: 20%;
float: left;
padding-right: 50px;
padding-left: 50px;
box-sizing:border-box
}
Snippet below
#keyframes slidy {
0% {
left: 0%;
}
20% {
left: 0%;
}
25% {
left: -100%;
}
45% {
left: -100%;
}
50% {
left: -200%;
}
70% {
left: -200%;
}
75% {
left: -300%;
}
95% {
left: -300%;
}
100% {
left: -400%;
}
}
body {
margin: 0;
}
div#slider {
overflow: hidden;
}
div#slider figure img {
width: 20%;
float: left;
padding-right: 50px;
padding-left: 50px;
box-sizing: border-box
}
div#slider figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 20s slidy infinite;
}
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<div id="slider">
<figure>
<img src="austin-fireworks.jpg" alt>
<img src="taj-mahal_copy.jpg" alt>
<img src="austin-fireworks.jpg" alt>
<img src="ankor-wat.jpg" alt>
<img src="austin-fireworks.jpg" alt>
</figure>
</div>
Change the CSS like below:
#keyframes slidy {
0% { left: 0%;}
20% { left: 0%; }
25% { left: -100%;}
45% { left: -100%; }
50% { left: -200%; margin-left: 100px;}
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%; margin-left: 0px;}
}
<base href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/">
<div id="slider">
<figure>
<img src="austin-fireworks.jpg" alt>
<img src="taj-mahal_copy.jpg" alt>
<img src="austin-fireworks.jpg" alt>
<img src="ankor-wat.jpg" alt>
<img src="austin-fireworks.jpg" alt>
</figure>
</div>
<style>
#keyframes slidy {
0% { left: 0%; }
20% { left: 0%; }
25% { left: -100%;}
45% { left: -100%; }
50% { left: -200%; }
70% { left: -200%; }
75% { left: -300%; }
95% { left: -300%; }
100% { left: -400%;}
}
body { margin: 0; }
div#slider { overflow: hidden;}
div#slider figure img {
width: 19%; float: left;margin-left:0.5%;margin-right:0.5%;
}
div#slider figure {
position: relative;
width: 500%;
margin: 0px;
left: 0;
text-align: left;
font-size: 0;
animation: 20s slidy infinite;
}
</style>
So I have an image slider and it works... kind of. My problem lies that I have 3 images. The slider slides through those images, but when it slides off the 3rd image (last one) it just dissappears, but then it slides back to the first image again? I need it so it slides from the last one to the first one, instead of going invisible for an interval. Here is my code for it currently:
#imgslide {
width: 550px;
height: 300px;
border-radius: 10px;
position: relative;
top: 25%;
left: 50%;
margin-top: -150px;
margin-left: -225px;
overflow: hidden;
}
#imgslide figure img {
width: 20%;
float: left;
}
#imgslide figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 15s slidy infinite;
}
/* Keyframes */
#keyframes slidy {
0% {
left: 0%;
}
20% {
left: 0%;
}
25% {
left: -100%;
}
45% {
left: -100%;
}
50% {
left: -200%;
}
70% {
left: -200%;
}
75% {
left: -300%;
}
95% {
left: -300%;
}
100% {
left: -400%;
}
}
<div id="imgslide">
<figure>
<img src="http://www.indraneelghosh.com/img/sport/sport_318_test-201.gif" alt="">
<img src="http://www.indraneelghosh.com/img/sport/sport_318_test-201.gif" alt="">
<img src="http://www.indraneelghosh.com/img/sport/sport_318_test-201.gif" alt="">
</figure>
</div>
try this
#imgslide {
width: 450px;
height: 300px;
border-radius: 10px;
position: relative;
top: 25%;
left: 50%;
margin-top: 100px;
margin-left: -225px;
overflow: hidden;
}
#imgslide figure img {
width: 20%;
float: left;
}
#imgslide figure {
position: relative;
width: 500%;
margin: 0;
left: 0;
text-align: left;
font-size: 0;
animation: 15s slidy infinite;
}
/* Keyframes */
#keyframes slidy {
0% {
left: 0%;
}
20% {
left: 0%;
}
25% {
left: -100%;
}
45% {
left: -100%;
}
50% {
left: -200%;
}
70% {
left: -200%;
}
75% {
left: 0%;
}
}
<div id="imgslide">
<figure>
<img src="http://demosthenes.info/assets/images/austin-fireworks.jpg" alt="">
<img src="http://demosthenes.info/assets/images/taj-mahal.jpg" alt="">
<img src="http://demosthenes.info/assets/images/ankor-wat.jpg" alt="">
</figure>
</div>
your images filling only 60% of space(3x 20%), add 2 more images to fill space or stretch your images to 33.33% of width and figure to 300%(adjust animation to 0%,100% and 200%)