Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

More issues- positioning of arrows around gallery

Edrol97

Bronze Coder
Hi All,

Trying to position arrows wrapping around an html gallery I've made but I can only seem to get them either both on one side of the image, centred in the middle of the page or on extremes of the page. This is what I've got currently. Screenshot 2024-03-20 at 13.37.11.png
My html is as follows
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Image carousel</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="container">
        <img src="img/Slide%20away.png" alt=" "width="300px" onclick="LaunchLightbox()">


    </div>
    <div class="slide-show_container">
        <div class="next_button" onclick="NextImage()">&#10233</div>
        <div class="previous_button" onclick="PreviousImage()">&#10232</div>
        <div class="close_button" onclick="CloseLightbox()">&#x2717</div>
        <div class="image_slide" onclick="slides()"></div>
        <div class="image_slide">
            <img src="img/A%20Bit%20Of%20A%20Mix%20Up.png"  width="300px">
            <div class="caption_text">Rishi's getting a bit mixed up</div>
        </div>
        <div class="image_slide">
            <img src="img/Culture%20War%20On%20Woke.png" width="300px">
            <div class="caption_text">The Tories are looking for an election strategy</div>
        </div>
        <div class="image_slide">
            <img src="img/Nothing%20to%20see%20here.png" width="300px">
            <div class="caption_text">The Tories are looking for an election strategy</div>
        </div>
        <div class="image_slide">
            <img src="img/Out%20of%20Tune%20ideas.png" width="300px">
            <div class="caption_text">No ideas incoming</div>
        </div>
        <div class="image_slide">
            <img src="img/Budget%20Fare.png" width="300px">
            <div class="caption_text">One way ticket to nowhere for the Tories</div>
        </div>
        <div class="image_slide">
            <img src="img/That's%20Racist.png" width="500px">
            <div class="caption_text">The Frank Hester row wages on, as the Tories are embroiled in a racism row</div>
        </div>
        <div class="image_slide">
            <img src="img/Bad%20Times%20logo%20Colourised%20W.png" width="300px">
            <div class="caption_text">Bad Times continue with the Tories</div>
        </div>
        <div class="image_slide">
            <img src="img/Budget%20Budget.png" width="300px">
            <div class="caption_text">This budget won't stretch far</div>
        </div>
        <div class="image_slide">
            <img src="img/Vultures%20Circling.png" width="300px">
            <div class="caption_text">Rishi doesn't have long if the 1922 Committee have anything to do about it</div>

            <button class="w3-button w3-black w3-display-left" onclick="plusDivs(-1)">&#10094;</button>
            <button class="w3-button w3-black w3-display-right" onclick="plusDivs(1)">&#10095;</button>

        </div>

        </div>
        </div>

    </div slide-show_container>
    </div>


    <script src="script.js"></script>
  </body>
</html>

And my CSS looks like this:

CSS:
@font-face {
    font-family: Eliot Lord;
    src: url(Fonts/EliotlordhandRegular.ttf);
}

body
{
    font-family: Eliot Lord;
}

.caption_text{
font-size: 20pt;


}

.next_button{
font-family: Arial, Helvetica, sans-serif;
font-size: large;
float: right;

}

.previous_button{
font-family: Arial, Helvetica, sans-serif;
font-size: large;
float: left;
}



.image_slide{
    display: none;


}

.slide-show_container{
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;

}

.image_slide{
    height: 400px;
    width: 700px;
    overflow: hidden;
    position:relative
}

.caption_text{
    height: 100%;
    width: 100%;
}


.w3-btn-floating > img {
    position:absolute;
    top:50%;
    left:50%;
    transform:translate(-50%, -50%);
    height: 45px;
    width: 45px;
    color: white;
}


.w3-btn-floating {
    position:absolute;
    top:50%;
    transform:translateY(-50%);
    height: 45px;
    width: 45px;
    color: white;
}


#prev {
    margin-right:10px;
    right:100px;
}

#next {
    margin-left:10px;
    left:100px;
}
.slide-show_container {
    display: none;

}
 
Although you can use float to position the arrows, I wouldn't recommend using that.
I would apply relative positioning to the container element, and then use absolute positioning for the arrows and define their distance from the edges.

When using absolute positioning, the position of the arrows shouldn't be affected by any of the other content in the gallery.

Something like this:
CSS:
.slide-show_container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  position: relative;  /* relative positioning */
}

.previous_button,
.next_button {
  font-family: Arial, Helvetica, sans-serif;
  font-size: large;
  position: absolute;  /* absolute positioning */
}

.previous_button {
  left: 50px;  /* use the 'left' property to define the distance from the left edge of the slide show container */
}

.next_button {
  right: 50px;  /* use the 'right' property to define the distance from the right edge instead */
}
 
Although you can use float to position the arrows, I wouldn't recommend using that.
I would apply relative positioning to the container element, and then use absolute positioning for the arrows and define their distance from the edges.

When using absolute positioning, the position of the arrows shouldn't be affected by any of the other content in the gallery.

Something like this:
CSS:
.slide-show_container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  position: relative;  /* relative positioning */
}

.previous_button,
.next_button {
  font-family: Arial, Helvetica, sans-serif;
  font-size: large;
  position: absolute;  /* absolute positioning */
}

.previous_button {
  left: 50px;  /* use the 'left' property to define the distance from the left edge of the slide show container */
}

.next_button {
  right: 50px;  /* use the 'right' property to define the distance from the right edge instead */
}
Hi Johna,

This has helped a fair amount, thanks. How can I get the arrows directly next to the image though? At the moment, they're quite far out
 

Attachments

  • Screenshot 2024-03-20 at 18.19.33.png
    Screenshot 2024-03-20 at 18.19.33.png
    336.7 KB · Views: 2
That probably means the container element is taking up the width of the entire page.
You could either set a defined width for the container, maybe something like 300px, since that seems to be the width of your images, or you could also set the width to fit-content so that the element only takes the amount of space it's contents use.
 
That probably means the container element is taking up the width of the entire page.
You could either set a defined width for the container, maybe something like 300px, since that seems to be the width of your images, or you could also set the width to fit-content so that the element only takes the amount of space it's contents use.
Also, if a responsive site, a percentage width with margins so as to center it in the window (if desired). Something like:

width: 75%;
margin: 0 auto;
 

New Threads

Buy us a coffee!

Back
Top Bottom