Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Track Down a Sideways Scrollbar

In this lesson, you tracked down the element that made the events page scroll sideways, in three steps, and fixed its size instead of hiding the overflow.

Follow Along

The video starts from events/upcoming.html and events/events.css as you left them in Handle Content That Doesn’t Fit, plus a map of the garden that Rosa added. The map, garden-map.svg, is in the course’s sample code ZIP, next to this lesson’s files: copy it into your images/ folder. Then add the map after the Coming Up heading in upcoming.html:

Language: HTML Filename: events/upcoming.html
<h2>Coming Up</h2>
<figure class="garden-map">
  <img
    src="../images/garden-map.svg"
    alt="Map of the garden: plots 1 to 24 in four rows
      of six, plot 7 in yellow, and the tool shed on
      the right"
    width="640"
    height="360"
  >
  <figcaption>Plots 1 to 24, and the tool shed.</figcaption>
</figure>

And add its rule at the end of events.css:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In the last lesson, you kept a long address inside its card. In this video, you’ll track down what makes a page scroll sideways, and fix it.

00:10 Rosa has added a map of the garden to the Coming Up section, so volunteers can find their plots. In a wide window, it fits. On a phone, the browser would zoom this page out to fit, as it did with the seed swap photo.

00:22 In a narrow window, the same problem shows up as a sideways scrollbar, which is easier to track down. So narrow the page itself. Drag the edge between the page and DevTools to the left, until the page is about 400 pixels wide.

00:37 A scrollbar appears along the bottom. The page scrolls sideways.

00:43 You might guess the map already. On a bigger page, you often can’t, so use a method. It has three steps.

00:52 First, scroll sideways, as far as the page goes, and look at what sticks out. The green column ends here, where the window’s edge was before you scrolled.

01:02 Past it, the map keeps going, with its last plots and the tool shed.

01:08 Second, in the Elements panel, hover over the elements from the outside in. The page draws each one’s box. The Coming Up section’s box ends where the green ends, so the section fits.

01:20 Next in the tree, hover the figure with the map. Its box runs on to the window’s edge, and it’s 600 pixels wide. It spills out of the section, the way overflow does by default.

01:32 Your base stylesheet keeps the image inside no wider than its figure. The figure’s the culprit.

01:39 Third, fix that element. Select it, and the Styles pane shows why. Its garden-map rule sets a width of 600 pixels, and a fixed width doesn’t give way.

01:51 Watch out: hiding the overflow doesn’t fix it. You can confirm this. Select the body, and type overflow-x: hidden into its element.style box. The scrollbar’s gone.

02:04 But the map is still 600 pixels wide. Its right side is cut off, the tool shed with it, and no one can scroll to it. Delete that declaration again.

02:17 So fix the map itself, with a limit instead of a fixed size. In events.css, change width to max-width in the garden-map rule, and save. The scrollbar’s gone again, and this time, the whole map is there, inside the column.

02:33 Check a phone’s width too. Drag DevTools’ edge back, turn on device mode, and type 375. The page shows at full size, not zoomed out, and the map fits.

02:47 So a sideways scrollbar means something runs past the window’s edge. Here, it was one element wider than the window, but anything that pokes past the edge will do it.

02:57 Scroll sideways to see what sticks out. Hover elements until one’s box runs past the edge. Then fix that element’s size. For long text, fix its wrapping instead, with overflow-wrap: anywhere, as in the last lesson.

03:11 Hiding the overflow only hides the scrollbar.

03:15 The events page fits any width again. Next is Exercise: Fit the About Page on a Phone, where you’ll make the garden’s about page work on a phone’s screen.

Become a Member to join the conversation.