put arrows left and right of an element - html

I have an icon in the center and two arrows on the right and left to scroll through the icons present.
I would like the arrows on the sides of the icon to be positioned horizontally in the center of the icon itself. How can I do? In this way the arrows are located at the top right and left and the icon displays it in the center but lower.
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.mySlides {
display:flex;
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto;
top:250px;
left:0;
right:0;
bottom:0;
position: absolute;
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides" shadow-lg p-3 mb-5 src="https://image.flaticon.com/icons/png/512/945/945170.png" ";>
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>

In your case I don't think that styling with position: abosolute on the icon would be a wise idea. I changed it to be a flex child of .icon-container. You can see if it helps.
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.icon-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.mySlides {
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="icon-container col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides shadow-lg p-3 mb-5" src="https://image.flaticon.com/icons/png/512/945/945170.png">
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>

Related

Embedding previous and next button onto image

I am trying to embed a previous and next button onto the image such that both buttons resize and stay on the image when resized. But the problem is the buttons don't stay on the image and resize in a way that isn't consistent with what I want. I also want my image to be on the right side of the screen and text on the left side instead of on the center.
I thought if I had put the button in a div that is the child of the div my photos were in, the buttons would automatically be embedded onto the photo but that didn't work. I also set my parent container to relative and child container to absolute thinking that would work.
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
}
* {
box-sizing: border-box
}
body {
font-family: Verdana, sans-serif;
margin: 0
}
.mySlides {
display: none
}
img {
vertical-align: middle;
}
/* Slideshow container */
.photos {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -200px;
color: aqua;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
position: absolute;
color: aqua;
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
.active,
.dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page</title>
<link rel="stylesheet" href="./styles/test.css">
</head>
<body>
<div class="center">
<div class="photos">
<img class="mySlides fade" src="photos/quote1.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/quote2.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/quote3.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/quote4.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/quote5.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/quote6.jpg" style="width:95.7%" />
<img class="mySlides fade" src="photos/photo8.png" style="width:95.7%" />
<div class="img-overlay btn-responsive">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
<script>
</script>
</body>
</html>
Set the <img>s to expand edge to edge of it's container .photos and keep aspect ratio as well by changing img ruleset:
img {
object-fit: contain;
width: 100%;
}
Also, remove margin-top: -200px from .next, .prev
I didn't see any text in OP code and didn't quite understand exactly what you wanted with text.
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.querySelectorAll(".slides");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
}
* {
box-sizing: border-box
}
body {
font-family: Verdana, sans-serif;
margin: 0
}
.slides {
display: none
}
img {
object-fit: contain;
width: 100%;
}
.photos {
max-width: 1000px;
position: relative;
margin: auto;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
color: aqua;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
user-select: none;
}
.prev {
left: 0;
border-radius: 0 3px 3px 0;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.4);
}
.btn-responsive {
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
.active,
.dot:hover {
background-color: #717171;
}
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page</title>
<link rel="stylesheet" href="./styles/test.css">
</head>
<body>
<div class="center">
<div class="photos">
<img class="slides fade" src="https://www.pcgamesn.com/wp-content/uploads/2022/05/v-rising-castle-heart-decay-900x506.jpg" />
<img class="slides fade" src="https://www.pcgamesn.com/wp-content/uploads/2022/05/jurassic-world-evolution-2-dominion-dlc-900x506.jpg" />
<img class="slides fade" src="https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans//41627993/0bc70a88bed9dad1ba5898beb33c72476c2ccc10.jpg" />
<img class="slides fade" src="https://www.pcgamesn.com/wp-content/uploads/2022/05/lost-ark-character-creation-900x506.jpg" />
<img class="slides fade" src="https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans//9164327/b4569cd9085bd5d186c30877bc1251f03fc6e06a.jpg" />
<div class="img-overlay btn-responsive">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
<script>
</script>
</body>
</html>
iceiscold! Welcome to Stack Overflow.
I don't know if you have a specific reason for your widths, but setting the images to 100% width and set object-fit: contain should solve your resizing issues. If you need them smaller, you can control that by setting the photo container size, or creating a custom container for the <img>.
As for the layout question, to have a text and an image side by side, I recommend you to use display: flex. Flex is a nice CSS property for handling layouts. Another option would be to use display: grid, which is another way to handle layouts (see Grid). For your case, I think flex is a bit more straightforward.
Basically what you need:
.parent{
display: flex;
}
.child1, child2{
flex: 1;
}
.parent will create a column layout, and with flex:1 you are telling the flex property that both child1 and child2 should have the same width. You can play with that by setting flex: 0.25, etc. I used this on your code to create a description column and a photo column.
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "block";
}
.center {
display: flex;
border: 1px solid black;
}
.descriptions {
flex: .75;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid red;
}
.mySlides {
display: none
}
img {
object-fit: contain;
vertical-align: middle;
width: 100%;
}
.photos {
flex: 1;
max-width: 1000px;
position: relative;
margin: auto;
border: 1px solid blue;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
color: aqua;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
user-select: none;
}
.next {
position: absolute;
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
.active,
.dot:hover {
background-color: #717171;
}
.fade {
animation-name: fade;
animation-duration: 1.5s;
}
<div class="center">
<div class="descriptions">
<p>I am a test description</p>
</div>
<div class="photos">
<img class="mySlides fade" src="https://pbs.twimg.com/profile_images/1498641868397191170/6qW2XkuI_400x400.png" />
<img class="mySlides fade" src="https://upload.wikimedia.org/wikipedia/en/9/95/Test_image.jpg" />
<img class="mySlides fade" src="https://pbs.twimg.com/profile_images/1498641868397191170/6qW2XkuI_400x400.png" />
<div>
<a class="prev" onClick="plusSlides(-1)">❮</a>
<a class="next" onClick="plusSlides(1)">❯</a>
</div>
</div>
</div>
Return to post

how to get the pop up images all the same size and in the centre

I have been asked to create an image gallery for a test website for a mini project at work with a few other people. I have created the gallery and the pop up images based on the code here: http://www.w3schools.com/howto/howto_css_modal_images.asp
The layout of the gallery itself is fine as there will be more images, but when I click on the images in the gallery, the images that pop up are all different sizes. We have been trying for a while now to give the images a fixed width and height to ensure that when they pop up they are all the same size and centred in the middle so that the user does not have to scroll up and down. Changing the width then results in the next and previous arrows being all over the place. We have made a few tweaks to the code but so far have been unable to get the desired result.
Can someone please point us in the right direction on how we can achieve this.
This is the code we have:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<title>PRINTS</title>
<style>
body {font-family: Arial, Helvetica, sans-serif;}
/* Style the Image Used to Trigger the Modal */
* {
box-sizing: border-box;
margin: 0;
padding: 0 10px;
}
.image-container {
width: 100%;
height: 70%;
columns: 4;
}
.myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
max-width: 100%;
padding: 1px;
}
.myImg:hover {opacity: 0.7;}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}
/* Modal Content (Image) */
.modal-content {
margin: auto;
padding: 0;
width: 90%;
max-width: 100px;
position: relative;
}
/* Add Animation - Zoom in the Modal */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
#-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}
#keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.mySlides {
display: none;
}
.image-wrapper {
position: absolute;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 20px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 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.8);
}
img.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
img.hover-shadow {
transition: 0.3s;
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: relative;
top: 0;
}
/* 100% Image Width on Smaller Screens */
#media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Trigger the Modal -->
<div class="image-container">
<img class="myImg" src="https://images.unsplash.com/photo-1526512340740-9217d0159da9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80.jpg" onclick="openModal();currentSlide(1)" class="hover-shadow">
<img class="myImg" src="https://images.all-free-download.com/images/graphiclarge/bridge_holiday_horizontal_landscape_nature_nobody_603727.jpg" onclick="openModal();currentSlide(2)" class="hover-shadow">
<img class="myImg" src="https://cdn.fstoppers.com/styles/full/s3/photos/2019/02/857ebd7658e56c84a4dc65cc4453a305.jpg?itok=rpCL6_UU.jpg" onclick="openModal();currentSlide(3)" class="hover-shadow">
<img class="myImg" src="https://www.difrusciaphotography.com/wp-content/uploads/2015/04/The-Awakening_Moraine-Lake-Alberta-Canada_03.jpg" onclick="openModal();currentSlide(4)" class="hover-shadow">
<img class="myImg" src="https://www.jessleephotos.com/images/xl/overlook-autumn.jpg" onclick="openModal();currentSlide(5)" class="hover-shadow">
<img class="myImg" src="https://images.freeimages.com/images/small-previews/7cb/father-tree-1377206.jpg" onclick="openModal();currentSlide(6)" class="hover-shadow">
<img class="myImg" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQnERA1ahoVfRaMs2rPHKYlx-cUXeA8_N2DWA&usqp=CAU.jpg" onclick="openModal();currentSlide(7)" class="hover-shadow">
<img class="myImg" src="https://images.unsplash.com/photo-1506522167817-40236fa71038?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxjb2xsZWN0aW9uLXBhZ2V8M3wxMzc4NDI3fHxlbnwwfHx8fA%3D%3D&w=1000&q=80.jpg" onclick="openModal();currentSlide(8)" class="hover-shadow">
</div> <!-- end image-container div -->
<!-- The Modal -->
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<div class="mySlides">
<div class="numbertext"> 1 / 46</div>
<img src="https://images.unsplash.com/photo-1526512340740-9217d0159da9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8dmVydGljYWx8ZW58MHx8MHx8&w=1000&q=80.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 2 / 46</div>
<img src="https://images.all-free-download.com/images/graphiclarge/bridge_holiday_horizontal_landscape_nature_nobody_603727.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 3 / 46</div>
<img src="https://cdn.fstoppers.com/styles/full/s3/photos/2019/02/857ebd7658e56c84a4dc65cc4453a305.jpg?itok=rpCL6_UU.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 4 / 46</div>
<img src="https://www.difrusciaphotography.com/wp-content/uploads/2015/04/The-Awakening_Moraine-Lake-Alberta-Canada_03.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 5 / 46</div>
<img src="https://www.jessleephotos.com/images/xl/overlook-autumn.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 6 / 46</div>
<img src="https://images.freeimages.com/images/small-previews/7cb/father-tree-1377206.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 7 / 46</div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQnERA1ahoVfRaMs2rPHKYlx-cUXeA8_N2DWA&usqp=CAU.jpg">
</div>
<div class="mySlides">
<div class="numbertext"> 8 / 46</div>
<img src="https://images.unsplash.com/photo-1506522167817-40236fa71038?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxjb2xsZWN0aW9uLXBhZ2V8M3wxMzc4NDI3fHxlbnwwfHx8fA%3D%3D&w=1000&q=80.jpg">
</div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<script>
function openModal() {
document.getElementById("myModal").style.display = "block";
}
function closeModal() {
document.getElementById("myModal").style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
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 = "block";
dots[slideIndex-1].className += " active";
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
</body>
</html>
Try setting a max height on your images, max-height: 90vh; for example. VH units are the height of the viewport, so the images won't ever be taller than 90% of the viewport height in this instance. Then you can set the image widths to have max-width: 100%; and the user won't need to scroll. Also change your .mySlides CSS when the slide is active to use display: flex; rather than display: block; to allow you to center the image easily.
Try this adding these updated CSS rules:
.modal-content {
width: 500px;
max-width: 100%;
}
.mySlides img {
max-height: 90vh;
max-width: 100%;
}
When slide is active:
.mySlides {
display: flex;
flex-direction: column;
}

HTML CSS Carousel Homepage

Hi I am relatively new to Html and css and have recently started making and designing my own website. What I have done so far is have 4 images that are going to be part of my carousel on the websites home and made them to be the width and height of whatever screen it is on. I have an overlay over the carousel as i want to make the website content ie next/prev buttons, carousel dots and navigation bar more noticable. The carousel will allow the user to navigate to a different page on the website. I also what to have carousel dots to show the user how many slides there are but so far i have only been about to get the dot to display at the top of the screen which is not what i want as i want to eventually put my navigation bar there. I have tried to set the position of it to absolute but it only displayed the one dot when there should be four. If anyone can help me with this and explain what i am doing wrong would be great and also point me in the direction of adding different content to the carousel show i can take the user to another part of the website for example slide 1 on the carousel is a Gallery page and slide 2 on the carousel is the contact page.
I know i have asked a lot so i really appreciate you taking the time to read this and help.
Here is my HTML:
<div class="carousel-content">
<!--<div>-->
<img class="image1" src="Images/WebTest_Image.jpg">
<!--<div class="carousel-text">Caption</div>-->
<!--</div>-->
<img class="image1" src="Images/Carlingford_Fourseasons_HQ.jpg">
<img class="image1" src="Images/Flowers.jpg">
<img class="image1" src="Images/WebTest_Image3.png">
<div class="overlay" />
<a class="carousel-left" onclick="plusSlides(-1)">❮</a>
<a class="carousel-right" onclick="plusSlides(1)">❯</a>
<!--</div>-->
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
<span class="dot" onclick="currentSlide(4)"></span>
</div>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("image1");
var dots = document.getElementsByClassName("dot");
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 = "block";
dots[slideIndex - 1].className += " active";
}
</script>
And here is my CSS:
.carousel-content {
background-position: center;
width:100%;
height:100%;
top:0;
left:0;
position: fixed;
margin:auto;
}
.overlay {
position: fixed;
left: 0;
top: 0;
min-height: 100%;
min-width: 100%;
background: rgba(0,0,0,0.5)
}
.image1 {
display:none;
width:100%;
min-height:100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
background-position:center;
background-size:cover;
}
.carousel-nav {
border: none;
display: inline-block;
outline: 0;
padding: 8px 16px;
vertical-align: middle;
overflow: hidden;
text-decoration: none;
background-color: inherit;
text-align: center;
cursor:pointer;
white-space: nowrap;
background-color: transparent;
color: #fff;
font-size:xx-large;
font-weight:bold;
width: 3%;
height: auto;
}
.carousel-left {
position: absolute;
top: 50%;
left: 0%;
transform: translate(0%,-50%);
-ms-transform: translate(-0%,-50%);
color:#b2acab;
}
.carousel-right {
position: absolute;
top: 50%;
right: 0%;
transform: translate(0%,-50%);
-ms-transform: translate(0%,-50%);
color:#b2acab;
}
.dot {
display:inline-block;
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
Thanks
You can absolute position the div so that the dots are at the bottom of the parent div.
div class="rel">
<span class="dot" onclick="currentSlide(1)"></span>
...
.rel {
position: absolute;
left: 50vw;
bottom: 0;
}
Simple give the parent element a class name
<div style="text-align:center" class ="dot-container">
<span class="dot" onclick="currentSlide(1)"></span>
and position it asabsolute
.dot-container{
display: block;
position: absolute;
bottom: 0px;
right: 50vh;
z-index: 99;
}
Also make sure that the carousel's main container has a relative position

Trouble keeping buttons positioned at the bottom of the image - In responsive image gallery

I've made a image gallery and I'm stuck on this problem from from quite time now as I want to position next and previous button on the bottom of the image but how can I make the buttons relative to the image as images are different and changes. How to put controller button at the bottom of the image.
What I'm trying to do:
It has Full Screen background modal. (Done)
Upon that modal it shows images. (Done)
On image's bottom I want to keep a constant showing controller buttons which are next and previous button to change through images. (Stuck from two days)
Tried Till Now:
Tried to make buttons relative to div's class "modal-content and image" but according to width size my buttons moves.
Tried changing heights and widths of the divs and tried some other things too.
At the end when nothing worked. I tried to achieve layout in a improper way by positioning buttons all the way from 1900px to 400px by media queries. But it still doesn't look good and accurate. (Have to use media queries only.)
I know this is not a right way. What am I missing here? how to make elements responsive in this type of situations?
Please let me know by your expertise if I should try any different approach or If I do some mistakes with my CSS code.
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
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 = "block";
dots[slideIndex - 1].className += " active";
}
.photos-thumbnail {
width: 440px;
}
.photos-thumbnail img {
margin: 10px 2px 0 0;
width: 140px;
height: 100px;
cursor: pointer;
}
.view-all-photos:hover {
opacity: 0.7;
}
.column {
float: left;
width: 16.6%;
}
.pro-modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
}
.modal-content {
position: relative;
margin: 50px auto 0;
width: 100%;
height: 90%;
background-color: rgba(0, 0, 0, 0.1);
}
.myslides img {
object-fit: contain;
background-color: rgba(0, 0, 0, 0.1);
width: 100%;
height: 100%;
}
.mySlides {
display: none;
}
.column img {
width: 100%;
}
.controller {
position: absolute;
background: linear-gradient(transparent, #1A1A1A);
text-align: center;
height: 12%;
width: 100%;
padding-top: 20px;
margin-top: -110px;
}
.prev,
.next {
position: absolute;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.4);
color: #ffffff;
border: 1px solid #02BFC1;
border-radius: 50%;
width: 33px;
padding: 15px;
font-size: 25pt;
transition: 0.6s ease;
user-select: none;
-webkit-user-select: none;
}
.next {
margin-left: 50px;
}
.prev {
margin-left: -50px;
}
<div class="photos-thumbnail">
<img class="hover-shadow" onclick="openModal(); currentSlide(1)" src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(2)" src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(3)" src="http://fextralife.com/wp-content/uploads/2015/01/Far-Cry-4-Tiger.jpg">
</div>
<div id="myModal" class="pro-modal">
<div class="modal-content">
<div onkeydown="ff(e)" class="mySlides">
<img src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="http://fextralife.com/wp-content/uploads/2015/01/Far-Cry-4-Tiger.jpg">
</div>
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
Output I want Even While Resizing
This happens after Browser window Resize. Image will start to fit the window and shrink as I want but buttons will be statically at the bottom.
If you change the display of the slides to this:
slides[slideIndex - 1].style.display = "inline-grid";
and with a few additionally changes at the css it should work.
The green marks are my changes.
I inserted a smaller image so that you can see the result in the code below.
I hope it helps.
EDIT:
To make the images resizing just add to your css:
img{
max-width: 100%;
height: auto;
}
And if you want the buttons staying in the middle during resizing, just put the controller div into the mySlides div -> see my code snippet
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
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 = "inline-grid";
dots[slideIndex - 1].className += " active";
}
.photos-thumbnail {
width: 440px;
}
.photos-thumbnail img {
margin: 10px 2px 0 0;
width: 140px;
height: 100px;
cursor: pointer;
}
.view-all-photos:hover {
opacity: 0.7;
}
.column {
float: left;
width: 16.6%;
}
.pro-modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
}
.modal-content {
text-align: center;
position: relative;
width: 100%;
height: 90%;
background-color: rgba(0, 0, 0, 0.1);
}
.mySlides img {
padding-left:75px;
object-fit: contain;
background-color: rgba(0, 0, 0, 0.1);
}
img{
max-width: 100%;
height: auto;
}
.mySlides {
display: none;
margin-right:75px;
margin-top:25px;
}
.column img {
width: 100%;
}
.controller {
background: linear-gradient(transparent, #1A1A1A);
height: 100px;
width: 100%;
padding-top: 20px;
margin-top: -100px;
}
.prev,
.next {
text-align: center;
position: absolute;
cursor: pointer;
background-color: rgba(0, 0, 0, 0.4);
color: #ffffff;
border: 1px solid #02BFC1;
border-radius: 50%;
width: 50px;
padding: 15px;
font-size: 25pt;
transition: 0.6s ease;
user-select: none;
-webkit-user-select: none;
}
.next {
margin-left: 50px;
}
.prev {
margin-left: -50px;
}
<div class="photos-thumbnail">
<img class="hover-shadow" onclick="openModal(); currentSlide(1)" src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(2)" src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<img class="hover-shadow" onclick="openModal(); currentSlide(3)" src="http://lorempixel.com/400/200/">
</div>
<div id="myModal" class="pro-modal">
<div class="modal-content">
<div onkeydown="ff(e)" class="mySlides">
<img src="https://wallpaperscraft.com/image/hitman_xbox_360_absolution_76000_1280x720.jpg">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="https://www.technobuffalo.com/wp-content/uploads/2014/03/Hitman-Absolution-2-1280x720.jpg">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
<div onkeydown="ff(e)" class="mySlides">
<img src="http://lorempixel.com/400/200/">
<div class="controller">
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="sep">|</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
</div>
</div>
You can add display: flex, justify-content: (wherever in the image you want your buttons to be), and text-align to centre your buttons and their text.

Indent even rows of hexagons in CSS

I currently have a list of hexagons (images) that I have wrap to the next line when the browser width decreases. However, when this happens, they form even lines as seen in the first image, each starting at the same point on the x axis.
Here is the JS Fiddle (albeit, the hexes don't flow right because they aren't images). The real code for this is:
<div class="container">
<span>
<img class="hex" src="img/hex.png">
</span>
...
</div>
And the CSS is:
.container {
padding-top: 80px;
width: 50%;
margin-left: auto;
margin-right: auto;
}
.container span {
line-height: 129px;
display: inline-block;
}
.container .hex {
display: block;
margin-left: auto;
margin-right: auto;
}
What I would like to do is alternate the rows such that every other row starts at an offset of the hexagon size as seen in figure two. It should also be noted that this example also has a negative y position relative to the respective position as determined from the first image.
Is there a way to do this with just CSS? I'd like to avoid using a library if at all possible.
This is similar to the question asked here, but I need the entire structure to be able to have an undetermined number of rows, so the solution where I specify which items are in which rows isn't feasible for my application.
Solution in JS Fiddle Demo :
Demo 1 :
http://jsfiddle.net/mkginfo/bhxohocv/
HTML Code :
<div class="container">
<!-- odd line -->
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<!-- even line -->
<span class="odd">
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<!-- odd line -->
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
<span>
<div class="hexagon"> </div>
</span>
</div>
CSS Code :
.container {
padding-top: 80px;
width: 65%;
margin-left: auto;
margin-right: auto;
}
.container span {
line-height: 129px;
display: inline-block;
position: relative;
margin-bottom: 25px;
}
.container span.odd {
line-height: 129px;
display: inline-block;
position: relative;
margin-bottom: 25px;
margin-left: 52px;
margin-top: -20px;
}
.container .hex {
display: block;
margin-left: auto;
margin-right: auto;
}
.hexagon {
width: 100px;
height: 55px;
background: red;
position: relative;
}
.hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid red;
}
.hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid red;
}
Demo 2 :
http://jsfiddle.net/mkginfo/wnsjfwt0/
Here's a solution that uses javascript to add the necessary transformations to the elements.
CSS:
.container {
padding-top: 80px;
width: 65%;
margin-left: auto;
margin-right: auto;
}
.floatBox {
margin-left: 15px;
margin-right: 15px;
}
.floatBox div {
display: inline-block;
}
.floatBox div.odd {
margin-left: 67px;
}
JS:
var floatBox = $(".floatBox");
var elements = floatBox.children();
var numElements = elements.length;
//reset all styles so they don't compound
elements.removeClass("odd");
elements.css("transform", "translateY(0)");
elements.css("-ms-transform", "translateY(0)");
elements.css("-webkit-transform", "translateY(0)");
var width = $(window).width() *.65;
var evenRowWidth = Math.floor(width / 135);
var oddRowWidth = Math.max(evenRowWidth - 1, 1);
var numberOfRows = 0;
var floatBoxWidth = evenRowWidth *138;
var delta = Math.floor((width-floatBoxWidth)/2);
floatBox.css("margin-left", delta);
floatBox.css("margin-right", delta);
var test = numElements;
var j = 2;
while (test > 0)
{
if (j % 2 == 0)
{
test -= evenRowWidth;
}
else
{
test -= oddRowWidth;
}
numberOfRows++;
j++;
}
j = 0;
var actionRow = 2;
var rowCount = 1;
var first = true;
for (var i = evenRowWidth; i < numElements; i++)
{
var translationAmt = -37*(actionRow-1);
if (actionRow % 2 == 0 && first)
{
first = true;
}
if (first)
{
$(elements.get(i)).addClass("odd");
first = false;
}
$(elements.get(i)).css("transform", "translateY(" + translationAmt + "px)");
$(elements.get(i)).css("-ms-transform", "translateY(" + translationAmt + "px)");
$(elements.get(i)).css("-webkit-transform", "translateY(" + translationAmt + "px)");
if (actionRow % 2 == 0)
{
if (rowCount == oddRowWidth)
{
actionRow++;
rowCount = 0;
}
}
else
{
if (rowCount == evenRowWidth)
{
actionRow++;
rowCount = 0;
first = true;
}
}
rowCount++;
}
HTML:
<div class="container">
<div class="floatBox">
<div>
<span>
<img src="image.png">
</span>
</div>
...
</div>
</div>