Having trouble with overflow-x? Instead of scrolling just the element, it's causing

My goal is to have the div ".slide" scroll horizontally only, but for some reason, the entire body is scrolling instead. I'm not sure why.

If you resize the page to mobile and try scrolling horizontally, you'll see what I mean.

Within the div.slide, I have applied the following CSS:

float: left;
width: 620px;
overflow-x: scroll;
background: #ecf2f6;

You can observe the issue here!

Answer №1

To create a scrollable section for your slides, you'll need to nest the .slide class inside another element and apply the CSS property overflow-x:scroll to that wrapping element.

Here's an example:

<div class="slide-wrap">
    <div class="slide">
        ....
    </div>
</div>

.slide-wrap {
    width: 100%;
    overflow-x: scroll;
}

I've quickly put together a demo showcasing this concept. Since jsFiddle isn't working at the moment, you can view the demo on CodePen:

http://codepen.io/anon/pen/bpGdo

.slide-wrap {
  border: 1px solid black;
  width: 320px;
  overflow-x: scroll;
}

.slide {
  width: 640px;
  height: 320px;
}

.box {
  float: left;
  width: 300px;
  height: 300px;
  margin: 10px;
  background: red;
}
<div class="slide-wrap">
  <div class="slide">
    <div class="box">1</div>
    <div class="box">2</div>
  </div>
</div>

Answer №2

One way to stop horizontal scrolling is by using the CSS property overflow-x: hidden;

Answer №3

To enable the vertical scrolling feature on div.slide or its parent container, you must specify a height.

Give this a try:

.slide {
 background: none repeat scroll 0 0 #ECF2F6;
 float: left;
 height: 300px;
 overflow-x: hidden;
 overflow-y: scroll;
 width: 620px;
}

By setting a specific height, the div.slide will only scroll vertically. The horizontal scrollbar appearing on mobile devices is likely due to the content exceeding the page width (specifically, 2 divs with the app-ad class).

Answer №4

To achieve vertical scrolling: You need to set a specific height for the container ".slide", which should be less than the actual content height.

For horizontal scrolling: Ensure that the width of the container ".slide" is narrower than the content width.

Here's an example:

.slide {
    height: 500px;
    overflow-y: scroll;
}

Answer №5

If you want to achieve an overflow-x scroll effect, make sure that the width of your parent element is smaller than the child div inside.

Here's how you can set it up in your HTML:

<div class='box'>
 <div class='content'>Your content here</div>
    Your content here
</div>

And here's the CSS to go along with it:

.box{width:80%;}
.content{width:120%;overflow-x:auto;}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for utilizing backdropFilter in a JavaScript file instead of CSS without encountering any errors

I've come across the following snippet of code: export const ErrorBlur = { width: '95.8%', height: '100vh', backdropFilter: blur('10px'), backgroundColor: 'rgba(124, 146, 153, 0.29)', }; However, an er ...

Webpack doesn't seem to be able to display custom fonts

I have a small project in progress using webpack. One of the tasks I'm facing is loading custom fonts. I followed the official tutorial here, where it explains how to handle assets in webpack configuration. My custom fonts are located within the src ...

Menu elements should display a responsive behavior where on mobile devices, only the icon is shown instead of the word "menu"

Due to the length of our company logo, we need a way to hide certain letters in the Menu and Basket sections, while still displaying the icons. Wrapping the names in span tags and using visibility:hidden; works but leaves empty space visible on the right s ...

Issue with HTML5 video not displaying poster image after using .load() method

I am facing an issue with my video implementation where the poster image is not returning after exiting full screen mode. I have a video with overlay content that requests full screen when the user clicks a custom play button. When the user exits full scre ...

Trouble with the back button functionality following logout

Despite hours of research and following various links, I am still experiencing a problem where my page continues to load after logging out and clicking the back button. Below is the code I have tried for my log out page: protected void Page_Load(object se ...

Changing datetime-local format from European to American dates

<input type="datetime-local"> While this input retrieves the local time from your PC, I'm curious if there's a way to make it display as US time specifically. ...

Elegant Bootstrap 4 Carousel featuring a glimpse of the upcoming slide alongside the primary carousel item

I am in search of a straightforward Bootstrap 4 carousel that showcases a glimpse of the next slide on the right. Despite exploring similar questions, I have not found a suitable solution. The links to those questions are: 1)Bootstrap carousel reveal part ...

Tips for preventing the NaN error in JavaScript

I am trying to calculate the total height of multiple containers and subtract it from a value (for example 1000) that needs to be set as a CSS value (in this case, 1000px). However, when I perform the calculation, I encounter the NaN error. I need a solu ...

Is there a way to implement word wrapping in li text without making any changes to its width

Is there a method to wrap the content inside li elements without modifying their width? As an illustration, consider the following structure - <ul> <li>Text Example</li> <li>Text Example</li> <li>Text Exampl ...

The charset is failing to function properly when using the French language

Encountering an issue with the French language on a website I'm currently developing ... Specifically, there are menu bars, tabs, and text within each tab involved. Upon setting charset=ISO-8859-1, the body text functions correctly, but the menu bar ...

A tutorial on utilizing fopen in PHP to write text lines to a .txt file

Struggling with PHP code utilizing fopen to write text lines into a textarea and save them to a .txt file. Below is the code I've been working on, hoping to get some assistance! <?php session_start(); if (!isset($_SESSION['username&ap ...

Trouble with executing a jQuery dynamic loop for each item

I have a unique situation where I am dealing with a table containing multiple tables for various users. The number of users can vary, so I am aiming to create a dynamic solution. Below are two sample tables for reference. <div class="timecard"> < ...

Comparison between SSD and HDD animation speed in web hosting environments

I am currently in search of a web hosting provider for a website I have created. The site features some performance-heavy animations, particularly due to a fullscreen slider with filter and scaling transitions. I need a provider that can ensure optimal per ...

What is the best way to expand the size of the pagination buttons in a primeng table?

My primeng table is quite large: <p-table #dt [value]="artefacts" [columns]="cols" [paginator]="true" [rows]="numberRows" [tableStyle]="{'table-layout':'auto'}"> With so many entries, the table spans over 100 pages. However, the ...

Capturing and saving location data without internet connection, and then displaying markers once connectivity is restored

I am currently developing a web application that will monitor the user's location. I want to ensure its reliability, so even if the user loses internet connection, the application will continue tracking their location (since GPS does not rely on inter ...

The autogenerated HTML5 constraints in Symfony2 are not functioning properly

I'm currently working on a project using Symfony2 (v2.3.6) and I wanted to utilize the auto-generated HTML5 constraints in my form. For this purpose, I created a simple form with just one field that has a RegEx constraint: public function formAction ...

Differences in tabstrip appearance between FireFox on Mac and Ubuntu compared to FireFox on PC

I've encountered an issue with my simple css tabstrip. It seems to render correctly in: Safari 5.0.2 on Mac IE8 on PC FireFox 3.8.12 on PC However, when viewed on FireFox 3.8.12 on Mac and Ubuntu, the tabs overlap the bottom border of the containe ...

Guide on customizing a dropdown button in a class-based Angular library with version 4 or higher

My dilemma revolves around utilizing the Angular Material library for a drop-down navigation bar. The issue at hand is my desire to hover through the list, yet I am unable to tweak the style within HTML. Fortunately, I can easily make alterations in Chrome ...

Find elements that are not contained within an element with a specific class

Imagine having this HTML snippet: <div class="test"> <div class="class1"> <input type="text" data-required="true"/> </div> <input type="text" data-required="true"/> </div> I'm looking to select ...

Is there a way to deactivate a clickable div immediately after it has been clicked on?

I have been searching for a solution to this particular question on different platforms, including Stack Overflow. However, I am looking for an answer using pure JavaScript only, so please avoid jQuery solutions. In order to provide context, I have includ ...