the div refuses to scroll left or right when overflowing

I am encountering the following issue:

.container {
  width: 100%;
  height: 100%;
  position: relative;
}

.contents {
  position: absolute;
  float: right;
  bottom: 0;
  width: 100%;
  top: calc(100% - 37px);
  overflow-x: auto;
  overflow-y: hidden;
}
<div class='container'>
  <div class='contents'>
     The content within the 'contents' div may vary in width, but not in height.
  </div>
</div>

When the contents div overflows, the horizontal scroll bar does not appear. Although the vertical scroll bar is present, it remains hidden and still allows scrolling, only in the vertical direction. What could be missing in this setup?

Answer №1

I made some adjustments to your provided example.

For the display block, it is important that the child element be larger than the parent element. It appears that using position absolute may not be necessary in this context.

.container {
   width:530px;
    height:210px;
    border: 13px solid #bed5cd;
    overflow-x: scroll;
    overflow-y: hidden;
}

.contents {
  display: inline-block;
   float:left;
   height:120px;
   width: 1000px;
   display: block;
}
<div class='container'>
   <div class='contents'>
      The contents of the 'contents' div might vary its width, not its height
      (Content of 'contents' div repeated multiple times for demonstration purposes)
   </div>
</div>

Answer №2

One important point to note is that when using percentages for width, the size of the div becomes relative to its parent container, often the body or html.

In order to make a container div scrollable, you can achieve it by doing something similar to the following:

body {
    min-width: 120%;
}

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

The getElementBy method is failing to pass the value in the document

Here is the javascript code snippet I am using: document.getElementById('district').value = dist.long_name "this line is passing the value" document.getElementById('city').value = route.long_name "this doesn&apos ...

Achieve button highlighting by hovering over the card - Bootstrap 5

Is there a way to make a button focus when hovering over a card in Bootstrap from any place on the card? Currently, the button only focuses when directly hovered over. I want to achieve the effect shown in the second image after hovering over any part of t ...

Storing checkbox status in Angular 7 with local storage

I am looking for a way to keep checkboxes checked even after the page is refreshed. My current approach involves storing the checked values in local storage, but I am unsure of how to maintain the checkbox status in angular 7 .html <div *ngFor="let i ...

Can you provide the distribution of percentages for each heading tag in HTML?

I recently adjusted the font sizes to be more consistent across various elements: html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, ...

Positioning of the footer using CSS: A query

What is the best way to position a footer if we know its height? For instance, if the height of the footer is 100px: footer { position:absolute; bottom: 100px; background: red; } If this approach is not recommended, could someone assist m ...

Modify the background color of the body when hovering over items in the unordered list using CSS

How can I modify the background color of the body when I hover over ul li using CSS? ...

Forwarding to a specific webpage

`<!DOCTYPE html> <html class="no-js"> ... </body> </html> I'm in the process of developing a website where users can enroll in programs by clicking on an ...

Responsive HTML grid with a distinct line separating each row

My challenge is to create a layout that features a grid of floating divs with horizontal lines under intermediate rows. The catch is that there should not be a line under the last row, and if there is only one row of elements, no line should be displayed. ...

The three.js library encountered an ERROR 404 ( File Not Found ) when trying to import an existing file

Error: GET http://localhost:port/js/three net::ERR_ABORTED 404 (Not Found) I am currently working on a web development project using Three JS. I downloaded the master Zip of ThreeJS from the official website of Three JS I copied the JS files from the Bui ...

Whenever I enter a narrative into my text box, it must interact with this API

Whenever I enter a story in the text box, it should trigger this API call: The retrieved data should be displayed in the browser. Currently, the API call is not being made. All the relevant code can be found in 'searchbar.js'. Could you please ...

Creating dynamic HTML elements for each section using JavaScript

Is there a way to dynamically add a task (input + label) for each specific section/div when entering the name and pressing the "Add" button? I attempted to create an event for each button to add a task for the corresponding div of that particular section, ...

How to enable seeking functionality for mp3 files with PHP

I have implemented the following PHP script: video tags are unable to extract metadata from it. Any insights on where I might be going wrong and how to rectify this situation? Your guidance would be greatly appreciated. Thank you.</p> ...

Using jQuery to add emoticons to a div element

I am currently developing a small chat application and I would like to incorporate emojis into it. My goal is to allow users to click on an emoji, which will then appear in the text area where they type their message. When a user clicks on "select," I want ...

iPhone Safari Mobile Browser experiencing issues with sms: and mailto: functionalities

Issue: Encountering a problem with web pages containing sms: and mailto: links not functioning on iOS mobile Safari browser. Clicking on the link redirects to: Safari cannot open the page because it cannot redirect to locations starting with "sms:& ...

Prevent the ability to capture photos using the HTML input file feature within an iOS application

Is there a way to restrict users from taking photos within an iOS app that is WKWebView based, and instead only allow them to select photos from their library or iCloud? Currently, I am aware of the ability to force users to utilize the camera with the ca ...

Styling Material UI height in select elements (React)

Currently, I am developing a react application that utilizes Material Dashboard. I am encountering an issue with the height of a Select (drop-down list) component. See image here On the right side of my app, there is a standard input field and I would li ...

Problem with Bootstrap 4 grid specifically occurring in Safari browser

After creating a website using Bootstrap 4, I encountered an issue where every column in a row starts on a new line instead of wrapping to the previous one when the number of columns is equal to 12. This problem seems similar to flexbug#11, and attempts to ...

Is there a way to retrieve href and src links using mouseover() without encountering the "ERR_FILE_NOT_FOUND" error? I am interested in accessing href and src through mouseover()

I'm struggling to create a mouseover function that can access href and src links, but I keep encountering the error message: "ERR_FILE_NOT_FOUND - Your file couldn’t be accessed. It may have been moved, edited, or deleted." Here is the HTML code sn ...

What is the proper way to ensure a flex item takes up 50% of the space when a gap is included in

It appears that I have misunderstood something about flexbox and am struggling to resolve the issue correctly. In my current setup, I have a flexbox container with four columns as its direct children. I want each .flexbox-item to take up 50% of the contai ...

How can I use React Native to align two text tags differently within the same row?

In this particular scenario, I attempted to showcase two distinct elements within a list item. However, I encountered a challenge in figuring out how to display the "item.date" on the left side of the line, and the string "Click to show.&qu ...