Height Overflow Problem in Three-Column Design

html,body{
  height: 100%;
}
#app{
  height: 100%;
  border: 2px solid black;
}
.row{
display: flex;
height: 100%;
}
.col-3 {
width: 20%;
background: red;
}
.col-6 {
width: 60%;
background-color:blue;
}
#large-item{
  height: 100%;
  width: 100%;
  background: yellow;
  
}
<div id="app">
<div class="row">
<div class="col-3">
<h2>left column</h2>
</div>
<div class="col-6">
<h2>middle column</h2>
      <div id="large-item">Large item</div>
</div>
<div class="col-3">
<h2>right column</h2>
</div>
</div>
  </div>

This is a layout I constructed with three columns according to the guidelines on w3cschools. However, when I set the height of html and body to 100%, the large item in the columns tends to overflow, creating an unattractive look. Is there a way to make it responsive by automatically adding a scroll bar while ensuring that the background color still fills the columns?

Answer №1

If you adjust the height of .col-6 > h2 to 30px and the height of #large-item to calc(100% - 70px);, it will create a better layout. By subtracting 70px (the height of h2 plus its margin) from the total height, we achieve the desired result.

Update 1: Adding a parent container for the large item and setting its height to calc(100% - 70px); with overflow:auto; will enable the scrollbar for content overflow. To see the scrollbar in action, you can set the height of the large-item to 500px.

Check out the snippet below.

html,body{
  height: 100%;
}
#app{
  height: 100%;
  border: 2px solid black;
}
.row{
display: flex;
height: 100%;
}
.col-3 {
width: 20%;
background: red;
}
.col-6 {
width: 60%;
background-color:blue;
}
#large-item-container{
  overflow:auto;
  height: calc(100% - 70px);
}
.col-6 > h2{
  height:30px;
}
#large-item{
  height:500px;
  width: 100%;
  background: yellow;
  
}
<div id="app">
<div class="row">
<div class="col-3">
<h2>left column</h2>
</div>
<div class="col-6">
<h2>middle column</h2>
      <div id="large-item-container">
        <div id="large-item">Large item</div>
      </div>
</div>
<div class="col-3">
<h2>right column</h2>
</div>
</div>
  </div>

https://jsfiddle.net/nimittshah/rkuf49np/1/

If you want to add a scrollbar for the entire col-6, the process is even simpler. No need for large-item-container.

See this

Enjoy! :)

Answer №2

Adjust the height of the large item to 92%.

Setting it to 92% will make it closer in height to the other columns.

html,body{
  height: 100%;
}
#app{
  height: 100%;
  border: 2px solid black;
}
.row{
    display: flex;
    height: 100%;
}
.col-3 {
    width: 20%;
    background: red;
}
.col-6 {
    width: 60%;
    background-color:blue;
}
#large-item{
  height: 92%;
  width: 100%;
  background: yellow;
}

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 H1 tag is mysteriously displaying padding or margin on the bottom, despite not being set

Despite not setting any padding or margin for the H1 tag, it still appears to have some spacing at the bottom. After applying a margin and padding of 0 to both the h1 tag and the text below it, I am still facing an issue where the text doesn't align ...

Is the spacing of the indicators on the bootstrap carousel uneven?

I'm stuck here and trying to figure out why the distance between the bootstrap carousel indicators is not equal. https://i.sstatic.net/n2MQm.jpg If you look at the image, you can see the uneven spacing between the 1st and 2nd indicators. #carou ...

What are the steps to make a dropdown menu using only HTML and CSS?

Can someone please share the most straightforward method for creating a drop-down list using just HTML and CSS? ...

When attempting to load a CSS file, Java automatically redirects to the login page

EDIT** After successfully loading CSS, I encountered an issue where the page kept redirecting back to login.jsp instead of displaying the CSS. Any insights on what might be causing this?https://i.sstatic.net/Ij7Oh.png I attempted to incorporate a custom ...

Using Bootstrap to wrap text around an image on small screens: A step-by-step guide

Recently starting my journey with Bootstrap, I've included a screenshot of my progress below. This is the CSS I'm using: .snippet img{ width: 150px; max-width: 100%; height:auto; } @media(max-width: 767px) { .snippet img{ width:100px; ...

When a two-column layout with a scrollable column experiences difficulty in scrolling continuously

I set out to create a webpage featuring two fixed columns at the top and a footer at the bottom. The main goal is to have the left column remain static while the right column is scrollable. This is what I aim to achieve - When the mouse hovers over the l ...

Arranging element in a vertical column

Looking for Help with CSS Positioning Solution to align 3 divs (left/center/right) inside another div I am struggling to position text in a column order. I have tried using float, but it affects other elements on the page. Below is my code snippet: < ...

Embedding videos in HTML

I am experiencing difficulties with embedding a video in my HTML file. I attempted to use a YouTube video, but when I open it in my browser, it displays an error message stating that the video is unavailable because YouTube has refused to connect. I also ...

Styling pagination for jquery dataTable

I've been looking into how to modify the pagination design, but haven't had much luck finding information on it. Currently, the table displays the standard default pagination style with the following jquery code. $('#id_view_student_table&a ...

Unexpected disturbance in horizontal alignment of bootstrap4 button caused by insertion of additional text above?

I utilized the grid systems layout in bootstrap to present my 3 courses. In this setup, I positioned the course image at the top, the course title in the middle, and the course enroll button at the bottom. However, when inserting a multi-line title for a s ...

html / CSS Center image in div with primary image as background

I am encountering a unique issue that I haven't come across in my search so far. My objective is to create an HTML page where each background image div represents one page for clean printing. .thirdBackgroundPage { background-image: url("images/fir ...

How come the translateX function doesn't function properly for fixed elements in IE9, IE10, and IE11?

Presently, I am endeavoring to obtain the desired outcome in Internet Explorer versions 9, 10, and 11 (functions flawlessly on Chrome and Firefox): When in mobile mode, there is a principal #container envelop that encompasses the entire website content al ...

Implement CSS styling within XML responses in jQuery UI autocomplete

Can you apply a different CSS class to a specific part of the label in the XML response? Currently, the label value is: label: $( "name", this ).text() + ", " + ( $.trim( $( "countryName", this ).text() ) || "(unknown country)" ) + ", " + $( "countryCode" ...

What method can I use to ensure that the sidebar stays fixed at a particular div as the user continues to scroll down the

Is there a way to automatically fix the sidebar once the user scrolls down and hits the top of the .Section2? Currently, I have to manually enter a threshold number which can be problematic due to varying positions across browsers and systems. Fiddle htt ...

How to Align the Button Vertically with the TextField in React Material-UI

Utilizing the Material-UI library for React, I have been working on creating a simple form with the following design: https://i.stack.imgur.com/LY3ZN.png My challenge lies in aligning the button with the TextField element. Adjusting the margin-top proper ...

Tips for creating a responsive layout to ensure that H2 achieves its optimal font size in a one-line DIV

Is there a way to ensure that an H2 headline fits within the width of a DIV element? I am looking for a solution where the font size of the H2 automatically adjusts to display its full text without overflowing or breaking into a second line inside the DIV ...

A fleeting moment reveals a broken image tag

How can I prevent the broken image tag from briefly appearing when the page loads? Take a look at this example: http://jsfiddle.net/v8DLe/196/ I have already implemented: onerror="this.style.display ='none'" Is there a way to still use the img ...

Limit the maximum height of a list within a fluid-width content container

I came across this link The layout works fine when the elements are limited in the #commentWrapper, but adding more items pushes everything downwards. Copying additional <li>test</li> items clearly demonstrates the issue. I want the input box ...

Limit the radius to only apply on big screens using tailwind css

Is there a way to apply border radius to an image only on larger screens and maintain straight edges on smaller screens? I'm working with Nextjs and Tailwind CSS. ...

Having excessive space within an H1 heading

Having an issue with a PHP file on my test server that is displaying extra white space, which is highlighted by a red box. This whitespace is also shown in the developer tools view. When the file is outputted, all of the content appears on one line. Code: ...