Ensure that the content inside the page has an overflow auto setting

When looking at the image, it is clear that I do not want my page to be scrollable. Researching the issue, I discovered that setting the height to 100vh is the solution (How to make a div 100% height of the browser window). I then set elements like 4 and 5 to overflow:auto, but unfortunately, there is no scrollbar and the content exceeds the screen height.

Continuing my research, I came across this answer: Make a div fill the height of the remaining screen space

Even following that answer did not resolve my issue. It is possible that using mdbootstrap in my project is causing complications.

My inquiry is how I can achieve the desired layout without using specific values such as 100px:

https://i.sstatic.net/Ik9kN.png

Below is an example snippet that is not functioning as expected:

html,
body {
  height: 100%;
  margin: 0;
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
}

.row {
  border: 1px dotted grey;
}

.header {
  flex: 0 1 auto;
  background-color: grey;
}

.content {
  flex: 1 1 auto;
  background-color: #C4C4C4;
}

.scrollableContent {
  flex: 1 1 auto;
  background-color: #7D7D7D;
  overflow: auto;
  margin: 5px;
}

.item {
  background-color: black;
  color: white;
  margin: 5px;
}

.footer {
  flex: 0 1 40px;
  background-color: grey;
}
<div class="box">
  <div class="row header">
    <b>Navigation Bar</b>
  </div>
  <div class="row content">
    <div class="item">
      Some Content
    </div>
    <div class="item">
      Some Content
    </div>
    <div class="item">
      Some Content
    </div>
    <div class="row scrollableContent">
      Long Content...
    </div>
    
  </div>
  <div class="row footer">
    <b>Footer</b>
  </div>
</div>

The Long Content should be scrollable while the header and footer remain fixed in position.

Edit: I have noticed that setting the height of .scrollableContent to a specific value like 200px does achieve the desired effect in some capacity. However, I aim for it to adjust dynamically to fit the available space.

Answer №1

as per my understanding:

* {
    margin:0;
}
html {
    height:100%;
}
body {
    height:100%;
    display:flex;
    flex-direction:column;
}
.header {
    background:tomato;
    color:#fff;
    padding:10px;
}
.content {
    padding:10px;
    flex:1;
    max-height:calc(100% - 76px) /* 76 is header plus footer total*/;
    overflow-y:scroll;
}
.footer {
    background:dodgerblue;
    color:#fff;
    padding:10px;
}
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8>
    <title></title>

    <link rel="stylesheet" href="style.css" />
</head>
<style type="text/css">

</style>
<body>
    <header class="header">Header</header>
    <main class="content">Content
      <div class="scrollableContent">
      Long Content<br>
      Long Content<br>
      Long Content<br>
      ...
      Long Content<br>
    </div>
    </main>
    <footer class="footer">Footer</footer>
</body>
</html>

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

Send the selected dropdown value to two separate PHP pages without using JavaScript

I am specifically looking for PHP programming, not JavaScript. My requirement is to have a dropdown menu containing 15 weeks. When a user selects a week from the dropdown, they should be redirected to a page that displays a message saying: Welcome! You h ...

Having difficulties updating a value in Angular through a function written in HTML- it refuses to update

<select ng-model="currentTimeStartHour" style="width: 33%" ng-change="UpdateTime(this)"> <option ng-repeat="hour in choices" value="{{hour.id}}">{{hour.name}}</option> </select> Somewhere else on the page... {{totalHours}} Whe ...

What is the best way to preserve the allocated space in the DOM while utilizing CSS display:none?

I have explored the functionalities of display:none and visibility:hidden. However, I need to utilize display:none for a specific reason while still preserving the element's allocated space in the DOM to prevent any impact on adjacent elements. Is thi ...

Adjustable height and maximum height with overflow functionality

Currently, I am in the process of developing a task manager for my application and facing an obstacle when trying to calculate the height of a widget. My goal is to determine the maximum height (assuming a minimum height is already set) by subtracting a ce ...

Please select an HTML file to upload and preview it using Thymeleaf before finalizing the upload

I'm currently working on a Spring Boot project that utilizes Thymeleaf for the front end. I want to allow users to upload a plain HTML file and also display a preview of the HTML file before uploading. While I've found options for previewing imag ...

The libmagic library detects the MIME type of files as text/plain rather than text/javascript or

In my web project's interface, I am using libmagic to retrieve the MIME type of a file. Interestingly, I am encountering issues where css and js files are being identified as text/plain MIME type. When using Chromium, the following warnings are displ ...

Ways to acquire ttf files from a third-party domain without encountering CORS issues

I am attempting to obtain a .ttf file from an external website for use in my web application. However, when I try the following code: @font-face { font-family: 'font'; src: url('http://xxx.xyz/resources/tipografias/font.ttf') forma ...

What seems to be the issue with my code for Javascript Math functions?

Welcome to the number game slider! If you roll above 50, you will get double the amount bet. Use the slider to choose your desired betting amount. Issue 1: After a win, the score does not update correctly. Instead of showing increments of 5, it displays s ...

Ways to display jQuery values as HTML text

Trying to concatenate the HTML text with the values of item.certificate_name has been a challenge for me. I've experimented with various methods, but none of them seem to work. The specific line I'm referring to is where I wrote . I have alread ...

React Native buttons are displaying at a fixed width and not adjusting as expected

Within a row, I have two buttons with a padding of 20 between them, and they are only taking up the necessary width for the button text. The width remains constant! Here is the code for the buttons: <View style={styles.buttonContainer}> &l ...

Creating a seamless integration of images and backgrounds using CSS

Can you help me find a way to blend the image with the background to eliminate the visible separation between them? Here is the link to the image: https://i.stack.imgur.com/VB9in.jpg ...

Using the width property to style a div element

There are two div elements in my HTML, each with a specified width. However, I want both divs to take up the full space as designated in the width property, regardless of the content inside them. Currently, the divs adjust their size based on the content a ...

Tips for choosing the class=" * " using jQuery's .html() function

Is there a way to target the string "class" or any other specified string within code retrieved from .html()? If we have an element's HTML content stored in another element (similar to a snippet with preview) <div class="myClass">1</div> ...

Maintain consistent spacing after receiving a value

I have a content editable span where you can write whatever you want. For example: Hello, My name is Ari. However, when I try to retrieve the text and alert it using my program, it displays without any line breaks or spacing like this: "Hello,My name is ...

The dragging functionality in gridstack.js doesn't seem to be functioning correctly

I have been implementing GridStack.JS in the code snippet below (Basic Structure) <div class="grid grid-stack"> <div class="grid-item cards grid-stack-item" data-gs-width="4" data-gs-height="2"> <div class="inner-grid"> </div& ...

Utilizing a 100% width Bootstrap form with SelectBoxIt inputs

Utilizing SelectBoxIt inputs () in Bootstrap 3 horizontal forms is causing an issue. I want the input to adjust and collapse along with the form width, but setting the widths to 100% is causing them to collapse instead. To demonstrate the problem, I' ...

Spacing vertically within a table cell

I'm currently experimenting with creating a vertical text-align: justify effect between divs. I am working with a structure that includes 4 div elements inside a td, like this: <td> <div></div> <div></div> <div ...

Generate interactive jQuery slideToggle containers that monitor user clicks via Google Analytics

I have been working on a PHP and mySql project where I need to retrieve a list of businesses from a database. Once I have the desired businesses, I want to display them consecutively inside their own "clickDiv" container using jQuery slideToggle to reveal ...

The current issue with this javascript function is that it is failing to produce any output

function calculateOverallCGPA() { let cumulativeGPA = 0.00; for (let i = 1; i <= semNum; i++) { const GPAforOneSubject = parseFloat(getElementById(`subs${i}`).value); cumulativeGPA += GPAforOneSubject; } const finalCGPA = ...

How can I make a Material UI element fill the entire remaining width of the Grid?

Is there a way to make the child element take up the remaining width of the grid in Material UI? I am trying to have the "User Name" text field fill up the rest of the space in the grid cell but so far I have not been successful. I have even attempted us ...