Bummer! You must be logged in to access this page.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

slideshow styling

I have successfully created a javascript slideshow, but the buttons are stacked vertically above and below the image instead of on either side of the image. Here's my code... <html> <head> <link rel = "stylesheet" href = "style.css"> </head> <body> <header> <h1 class = "place">Hawaii</h1> </header> <main> <br><br> <button id = "back">back</button> <img class = "slides" src = "https://www.wallpapersbrowse.com/images/xa/xa9j99h.jpg"> <img class = "slides" src = "https://cdn-image.travelandleisure.com/sites/default/files/styles/1600x1000/public/1502722460/hanauma-bay-nature-preserve-oahu-hawaii-HAWAIIFLIGHTDEAL0817.jpg?itok=5RHXufdE"> <img class = "slides" src = "https://www.hawaiidiscount.com/Portals/0/hawaii-vendors.jpg"> <img class = "slides" src = "https://i.ytimg.com/vi/L3V7LKYPIUQ/maxresdefault.jpg"> <button id = "next">next</button> </main> <script> let back = document.getElementById("back"); let next = document.getElementById("next"); let num = 0; let imgs = document.getElementsByTagName("img"); imgs[0].style.display = "block" next.addEventListener("click", () => { if (num == imgs.length-1) { num = 0; console.log(num) imgs[num].style.display = "block"; imgs[num+imgs.length-1].style.display = "none"; } num += 1; console.log(num) imgs[num].style.display = "block"; imgs[num-1].style.display = "none"; })

                        back.addEventListener("click", () => {
                                               if (num == 0) {
     num = imgs.length-1;
                        console.log(num)
                        imgs[num].style.display = "block";
                        imgs[0].style.display = "none";
  }
                        num -= 1;
                        console.log(num)
                        imgs[num].style.display = "block";
                        imgs[num+1].style.display = "none";
                        })

                        back.style.display = "inlineBlock";
  next.style.display = "inlineBlock";
</script>

</body> </html>

here's my css if that's necessary...

h1 { font-family: system-ui; font-weight:400; font-size: 60px; margin-top: 0; padding-top: 15px; } header { text-align: center; border-bottom: 4px solid coral; } img { width: 70%; margin-top: 20px; } a { text-transform: capitalize; font-family: system-ui; color: black; font-weight: 200; font-size: 300%; text-decoration: none; } main { text-align: center; padding: 30px; } button { background-color: coral; border: none; color: white; padding: 10px 30px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; transition: .5s; font-size: 30px; border-radius: 20px; cursor: pointer; margin: 5px; } button:hover { background-color: white; color: black; } input:focus { outline:0; } input { font-size: 30px; padding: 10px; border-radius: 20px; background-color: #F0F0F0; border: none; text-align: center; font-weight: 300; } button:focus { outline:0; } .destination { display: inline-block; width: 70%; padding: 0px; margin-bottom: 100px; } .place { margin-left: 5%; text-align: left; font-weight: 200; } .slides { display: none; }

Please fix your backticks (```)

1 Answer

Steven Parker
Steven Parker
243,186 Points

You could wrap the set of image in a container to constrain their width and to set alignment with the buttons. For example, if you put a div around them with a class of "images":

.images {
  display: inline-block;
  width: 70%;
  vertical-align: middle;
}

For future questions, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.