The content in the flex box item with horizontal scroll is overflowing beyond its boundaries

I am working with a flex box container that contains two child elements: a left side and a right side. I want the right side item to have a horizontal scrollbar in order to fit its content.

.container {
  display: flex;
  overflow: hidden;
  height: 300px;
}

.left-side {
  min-width: 100px;
  background-color: red;
  text-align: center;
}

.right-side {
  background-color: blue;
  overflow-x: auto;
}

.right-side > div {
  height: 50px;
  background-color: yellow;
  text-align: center;
  line-height: 50px;
}

.right-side > p {
  white-space: nowrap;
  background-color: yellow;
}

.notes {
  padding-top: 20px;
}
<div class="container">
  <div class="left-side">
    left side
  </div>
  <div class="right-side">
    <div>
      right side
    </div>
    <p>
      Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph
      Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph
      Paragraph Paragraph Paragraph Paragraph
    </p>
  </div>
</div>

Is there a way to achieve this using flexbox or any alternative methods?

Check out the demo here

Answer №1

I am creating blocks here to serve as containers.

  • Parent => Left : Right

Within these three container concepts, there is some super unattractive content.

  • The background colors and borders in this setup are deliberately ugly to illustrate the layout structure.
  • The body has been set to a standard default of 16px font size with no margins or padding for most browsers.
  • The parent-container has been given a grid layout with left and right columns; The left column has a specified min/max size, while the right column adjusts based on its contents.
  • A grid gap has been added to the parent container to visually separate the left and right sections.
  • The elements in the left side have been aligned to display how much control can be exerted within the container.
  • The right side is configured to align to the top of the block and include a scroll bar per the original poster's query.
  • Various elements with unappealing backgrounds have been placed on the right side to demonstrate both control within the container and containment due to the scroll setting.
  • The excessive CSS styling present serves the sole purpose of illustrating the structure, resulting in an overly exaggerated appearance.

body {
  font-size: 16px;
  margin: 0;
  padding: 0;
}

.parent-container {
  display: grid;
  grid-template-columns: minmax(6.25rem, 25%) 1fr;
  grid-gap: 0.25em;
}

.left-side {
  align-self: start;
  background-color: #FF000011;
  height: 100%;
  text-align: center;
  border-right: 2px solid #FF000088;
  display: grid;
}

.right-side {
  background-color: #90EE90;
  align-self: start;
  scrollbar-color: rebeccapurple green;
  overflow-x: auto;
}

.right-side>.right-header {
  grid-row: 1 / 1;
  background-color: #FFFF00;
  text-align: center;
}

.right-side>.right-content {
  background-color: #FF80FF;
  display: grid;
}

.right-side .right-text {
  background-color: #FFFF00;
}

.next-child-right {
  justify-self: safe center;
  align-self: baseline;
  border: outset 1px #00FF00AA;
  border-radius: 1em;
  padding: 0.5em;
  background-color: #00FF00;
  margin-bottom: 1em;
}

.block-thing {
  justify-self: end;
  align-self: end;
  height: 3rem;
  width: 8ch;
  border: double #00FF00;
}

.blocky-child-right {
  width: 50rem;
  height: 3rem;
  border: solid blue 1px;
  text-align: end;
}

.block-header {
  text-transform: uppercase;
  font-size: 1.5rem;
  font-weight: 600;
  font-family: sans-serif;
}
<div class="parent-container">
  <div class="left-side">
    <div class="block-header">left side</div>
    <div>Next left</div>
    <div class="block-thing">block thing</div>
  </div>
  <div class="right-side">
    <div class="right-header block-header">
      right side
    </div>
    <div class="right-content">
      <p class="right-text">
        Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph
        Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph Paragraph
        Paragraph Paragraph Paragraph Paragraph
      </p>
      <div class="next-child-right">I am the next content</div>
      <div class="blocky-child-right">blocky I am</div>
    </div>
  </div>
</div>

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

Trouble exporting to Excel on Chrome and Firefox browsers

I am having an issue with exporting tables to Excel using JS. The <table> tag contains some descriptions and a class (<table class="someClassName" border="0" cellpadding="0" cellspacing="0">). When the table is exported to Excel, the Excel fil ...

Troubleshooting: Why isn't my CSS fixed position working for my sticky

I have a simple jQuery code snippet that is supposed to make the navigation element sticky by applying a class with position: fixed. However, I'm facing an issue on my Commerce platform where the fixed position property doesn't seem to work corre ...

The HTML attribute "hasbox" specifies the presence of a box within the element

I am currently working on resolving some rendering issues specifically in IE9 and have encountered a tag attribute that I am not familiar with - hasbox. Upon further investigation, it seems like IE is injecting this attribute at runtime as it does not app ...

Adjust the size of the container DIV based on the content within the child DIV

I have been searching for a solution to my question without success. Here is the issue: I have a DIV that acts as a container for a Post in my project. Inside this post are classes for the poster avatar, name, timestamp, text, and more. The problem arise ...

Creating nested tables by assigning unique Div IDs to each table element

Can we utilize a straightforward JavaScript/jQuery function to nest elements inside table elements? For instance, every square comes with its own unique ID (A1, B7, C5). How can I use this ID to insert the checker image in any selected tile upon clicking? ...

setting the child div's margin in relation to its parent div

Here is my HTML: <div class='mainDiv'> <div class='subDiv'></div> </div> This is the corresponding CSS code: .mainDiv { margin-top: 200px; width: 700px; height: 800px; background-color: red ...

Difficulty in managing vertical overflow in a dynamically sized table using Bootstrap

I am facing an issue with the table-responsive class that is causing a scroll on the y-axis even though it is not specified in the CSS. Shown below is a screenshot of the problem, and I have also managed to replicate the bug: <div id="app"> <d ...

Is your Javascript navigation functioning properly on some submenus while encountering issues on others?

If you visit , you'll notice that it's a visually appealing site. The navigation submenus seem to be functioning properly, HOWEVER upon inspecting the element, you'll notice that under the PRICING tab, there are submenus that have the same c ...

Adjust the dimensions of the icon

My current project involves creating a sidebar with icons and associated text to represent each icon. However, I encountered an issue while trying to adjust the size of the icons within the sidebar using the "useStyles()" method. For some reason, the size ...

I am looking to dynamically insert a text field into an HTML form using jQuery or JavaScript when a specific button is clicked

This is my code snippet: <div class="rButtons"> <input type="radio" name="numbers" value="10" />10 <input type="radio" name="numbers" value="20" />20 <input type="radio" name="numbers" value="other" />other </div> ...

Use jQuery to switch back and forth between two different sets of classes

I am attempting to switch between two different sets of classes using jQuery. My goal is to change from one custom icon to a font-awesome icon upon clicking an element. While I have been successful in changing a single class, I am facing challenges when tr ...

Switching between vertical and horizontal div layouts while reorganizing text fields within the top div

function toggleDivs() { var container = document.querySelector(".container"); var top = document.querySelector(".top"); var bottom = document.querySelector(".bottom"); if (container.style.flexDirection === "column") { container.style.flexDirec ...

Is there a distinction between the values 'normal' and 'stretch' in the CSS property known as 'align-content'?

When it comes to the CSS declaration 'align-content', the default value is 'normal'. But, there is also another option: 'stretch'. I have been having a hard time figuring out if there is any actual difference between the two. ...

"Implemented a user-friendly header and footer that stick to the top and

My goal is to create a fixed header and footer, allowing the main content to scroll underneath while keeping the right navigation in place. To achieve this effect, I've been experimenting with different solutions. One of my attempts can be viewed her ...

Troubleshooting problem with ion-input in Ionic 3 regarding the keyboard issue

Issue with Keyboard Overlaying Button In my ionic3 app, I am facing an issue where the keyboard overlaps the "Registrarse" button when it is open, as shown in the image. The button is positioned at the bottom of the ion-content using CSS rules such as pos ...

Catalog of items in Mustache

I am currently working on generating HTML content using the mustache template engine. However, I have encountered an issue when trying to render a list of objects. Below is an example of my object: var Prod={ "Object1": { "name": "name1", "cat ...

What are some effective ways to analyze jQuery and JavaScript using web development tools?

I'm struggling to use web development tools to inspect the JavaScript on websites. It's challenging to identify which parts of a site are utilizing JS, unlike CSS or HTML where it's more visibly defined. Even when I attempt to delete some J ...

When the user clicks the back button in AngularJS

After searching extensively, I have yet to find a straightforward solution to my issue. The problem lies in a search/filter field that filters the page based on user input. While this filter works efficiently, it clears whenever a navigation item is clicke ...

Discovering additional element information while utilizing the 'Sortable' feature

My Current Objective: In my setup, I have a 'calendar' comprising 5 columns, each column containing 5 separate divs known as timeslots. The main purpose here is to show appointments in these specific timeslots and utilize JQuery's Sortable ...

Include a CSS file from an external JavaScript file

Is there a way to include an external CSS file in an external JS file? I am trying to reference and load Default.css inside Common.js like the image below shows. Any suggestions are greatly appreciated! BB ...