Ensure the div has a scrolling feature activated when the content surpasses the height limit

I am attempting to make the middle div #content scroll when its content exceeds the available height (calculated as innerWidth - header height - footer height).

However, rather than scrolling, the div has a scrollbar that is unresponsive, and the entire page ends up with a scrollbar.

body {
margin: 0;
}
#header {
background-color: silver;
height: 100px;
width: 100%;
}
#content {
overflow: scroll;
}
#footer {
background-color: silver;
bottom: 0px;
height: 100px;
position: fixed;
width: 100%;
}
<div id="header">header</div>

<div id="content">
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
</div>

<div id="footer">footer</div>

Answer №1

To make #content work properly, you need to give it a fixed height. Currently, it does not function correctly because #content has a variable height. Instead of scrolling when it overflows (which it won't because the content will always fit), it expands indefinitely.

Take a look at the code snippet below for reference.

(I have set the heights of body and html to height: 100%, and adjusted #content with a height of calc(100% - 200px) to utilize all available space excluding the header and footer).

body, html {
margin: 0;
    height: 100%;
}
#header {
background-color: silver;
height: 100px;
width: 100%;
}
#content {
overflow: scroll;
    height: calc(100% - 200px);
}
#footer {
background-color: silver;
bottom: 0px;
height: 100px;
position: fixed;
width: 100%;
}
<div id="header">header</div>

<div id="content">
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
a<br>b<br>c<br>d<br>e<br>f<br>g<br>h<br>i<br>i<br>j<br>k<br>l<br>m<br>n<br>o<br>p<br>q<br>r<br>s<br>t<br>u<br>v<br>q<br>x<br>y<br>z<br>
</div>

<div id="footer">footer</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

Moving the webpage into the realm of mobile and tablet devices

Over the next few weeks, I will be working on transitioning my website content to have both a mobile and tablet version. During this process, I have some questions: What is the best way to redirect users to the correct site based on their device/browse ...

The style from '<URL>' was not applied as it has a MIME type of 'text/html', which is not a compatible stylesheet MIME type

After attempting to run the angular application with the home component, an error appeared stating that styles were refused and images could not be found. It's puzzling because the CSS and image folder are located in the /src/assets folder. I have tr ...

Internet Explorer 11 fails to interpret the attribute attr.xlink:href

I am a beginner in Angular 2 and I'm working on creating an icon component. The code I have below works perfectly in Chrome and Firefox, but unfortunately, it's not functioning in Internet Explorer 11. Here is what my component looks like: @Com ...

Fuzzy text in drop-down box on Chrome, clear on Firefox

I've encountered an issue with a dropdown menu in Google Chrome where the content appears blurry, while it displays correctly in Firefox. The problem arises when the dropdown exceeds a certain height, and I've tried setting a max-height with over ...

Customize the fieldset style in Bootstrap 5

In earlier versions of Bootstrap (or with plain CSS), the following HTML code used to result in a fieldset with a visible border, where the legend sat on top: <fieldset> <legend>Test</legend> Welcome! </fieldset> Here is how ...

What is the best way to vertically align an InputLabel within a MUI Grid item?

I'm trying to vertically center the InputLabel inside a MUI Grid item. Here's what I've attempted: import { FormControl, Grid, Input, InputLabel, TextField } from "@mui/material"; export default function App() ...

Addressing the status bar gap issue on the iPhone X with Cordova for iOS 11.0

After receiving helpful feedback on my previous Cordova question regarding status bars, I've encountered a new issue with the iPhone X on iOS 11.0. I came across this thread: Users are reporting a white bar appearing specifically on the iPhone X run ...

Can you explain the process of NuxtJS css extraction for creating static websites?

I am currently working on creating a static website using my minimal code with Nuxt. This code includes integration of the tailwindcss toolkit and vue2-leaflet. When I run nuxt generate I end up with two CSS files - one for the tailwindcss styles and an ...

Start fresh with your list styling in Sass/CSS

I'm attempting to revert ul and li elements to their default styles using a specific class, but I'm encountering difficulties in doing so. I've experimented with the inherit and initial values, but they haven't proven effective. This i ...

Troubleshooting: React CSS Transition Fails to Trigger on Exit and Entry

This code is located inside my component file <CSSTransition classNames="method" in={radio === 'add-card'} exit={radio !== 'add-card'} timeout={500} unmountOnExit> < ...

Techniques for Adding Background Color to Fieldset Border

Recently starting to learn HTML and stumbled upon a question: How can I create a background color or image for a field set border? Can I simply use regular color values, or do I need special codes for creating a background color in a field set? Any insig ...

How to eliminate the external white border from a Java applet when it is integrated into an HTML webpage

As someone experienced in dotnet, I decided to venture into creating a Java applet for my application. After successfully developing and signing the applet, it functioned perfectly within my application. However, one issue perplexed me - when I attempted ...

Choosing a menu option with jQuery

Can someone help me with making a menu option selected in HTML? Here is my code: <ul class="ca-menu"> <li> <a href="#"> <span class="ca-icon"><img src="images/home.png" ...

Setting the color of an element using CSS based on another element's style

I currently have several html elements embedded within my webpage, such as: <section id="top-bar"> <!-- html content --> </section> <section id="header"> <!-- html content --> </section> <div id="left"> &l ...

Designing materials involves organizing 5 items in a section, as dividing 12 by 5 results in an unattractive

Incorporating the Material Design Light library into my webpage, I have a section with 5 items that I want to evenly occupy the space: <section class="section--center mdl-grid mdl-grid--no-spacing mdl-shadow--2dp social-section"> <a href="http: ...

Is Safari causing issues with the CSS slider animation?

Currently, I am working on implementing a CSS-only slider (no jQuery) in WordPress using the code from this source: http://codepen.io/dudleystorey/pen/kFoGw An issue I have encountered is that the slider transitions are not functioning correctly in Safari ...

Strange outcomes observed with CSS Selector nth-child

When utilizing the CSS nth-child selector, I am encountering some peculiar issues. The HTML structure is as follows: <div class="block feature-callout-c" id="overview"> <div class="row"> <div class="span twelve"> ...

Methods like jQuery blink(), strike(), and bold() offer dynamic ways to manipulate

I'm currently tackling an inquiry. The code I crafted seems to be functioning without any issues: (function () { if($('#target:contains("bold")')) { $('#target span:first').css('font-weight','bold ...

Issue with div element not stretching to 100% width

I am currently working on a fluid layout design where the template includes a header, menu, and body section. <div class="w100 h100"> <div id="headerBox" style="height: 10%;" class="w100"> <div style="width: 80%;" class="lfloat ...

Ensure that the div is completely filled by the button and input elements

My dilemma involves filling a div element with a button and an input field. I'm struggling to set the exact width of the button, which is causing the input field to overflow the parent container. Despite many attempts with various properties, includin ...