Reputation: 29
I've been working on making my on image slider (based on w3schools slider), but I wanted it a bit different. Now I am not that good yet with html and css and I cant seem to find why the overlay(See image) is ever so slightly bigger than the img and I could not find a solution to match the img height.
Thought it was the image changed that a couple of times but that doesn't seem to solve it.
Also included the code
HTML
<div class="slideshow-container">
<div class="mySlides fade">
<img src="img/img1.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<img src="img/img2.jpg" style="width:100%">
</div>
<div class="mySlides fade">
<img src="img/img3.jpg" style="width:100%">
</div>
<div class="prev" onclick="plusSlides(-1)">
<a class="arrows" onclick="plusSlides(-1)">❮</a>
</div>
<div class="next" onclick="plusSlides(1)">
<a class="arrows" onclick="plusSlides(1)">❯</a>
</div>
<div class="dot-container">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
</div>
CSS
/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
overflow: hidden;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 0;
height: 100%;
padding-left: 5%;
padding-right: 5%;
transition: 0.6s ease;
}
.arrows{
position: absolute;
top: 50%;
left: 40%;
color: white;
font-weight: bold;
font-size: 18px;
}
/* Position the "next button" to the right */
.next {
right: 0;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.4);
}
/* Caption text */
.dot-container {
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* The dots/bullets/indicators */
.dot {
cursor:pointer;
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
@media only screen and (max-width: 500px) {
.slideshow-container {
max-width: 80%;
}
}
Javascript
var slideIndex = 0;
var clicked;
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
slide();
function slide()
{
if(!clicked){
autoSlide();
}else{
showSlides(slideIndex);
}
}
function plusSlides(n) {
showSlides(slideIndex += n);
clicked = true;
}
function currentSlide(n) {
showSlides(slideIndex = n);
clicked = true;
}
function showSlides(n) {
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "";
dots[slideIndex-1].className += " active";
}
function autoSlide()
{
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slideIndex++;
if (slideIndex> slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
setTimeout(slide, 5000); // Change image every 5 seconds
}
Upvotes: 0
Views: 63
Reputation: 8667
You can use this trick to achieve your goal:
.slideshow-container {
font-size: 0;
}
Upvotes: 1