Create a scrollable modal body that dynamically adjusts its content to the end, situated between the header and footer

I am facing an issue with my modal setup. The content in the body is quite lengthy and I want it to be scrollable, but the height of the body should end where the footer begins.

Currently, the height of the body extends over the footer, making it impossible to view the content at the bottom.

Since I do not know the height of the device, how can I make the body dynamic so that it fits between the header and footer, allowing for seamless scrolling and visibility of all elements?

PS: The height of the header can vary, but the height of the footer can be specified.

https://i.sstatic.net/hkrK9.jpg

body {
  width:450px;
  background:#f4f4f4;
  margin:0 auto;
}

.modal {
  visibility:visible;
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 10;
  background: #fff;
  width:inherit;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.modal-header {
  background: gray;
  padding:20px;
}

.modal-body {
  -webkit-box-flex: 1;
  flex-shrink: 1;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
  overflow-y: scroll;
  display: block;
  position: fixed;
  height: 100%;
}

.modal-footer {
  display: block;
  -webkit-box-flex: 0;
  flex-shrink: 0;
  z-index: 1;
  background:#FFF;
  bottom: 0;
  height: auto;
  position: fixed;
  width:100%;
  padding:10px;

}
<body>
  <div>
  <p>
  content
  </p>
  </div>
  <div class='modal'>
    <div class='modal-header'>
      <input type='text'/>
      <input type='text'/>
    </div>
    <div class='modal-body'>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>a</div>
      <div>b</div>
      <div>c</div>
      <div>d</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>too long</div>
      <div>LAST VISIBLE ELEMENT</div>

    </div>
    <div class='modal-footer'>
      <button>
      click
      </button>
    </div>
  </div>

</body>

Answer №1

It was mentioned that the bottom height can be adjusted as needed.

To achieve this, assign a height to the modal-footer and calculate the body height using the calc property,

this will ensure that the body takes up the entire height excluding the space for the footer content.

Give it a try:

body {
      width:450px;
      background:#f4f4f4;
      margin:0 auto;
    }
    
    .modal {
      visibility:visible;
      bottom: 0;
      display: flex;
      flex-direction: column;
      height: 100%;
      left: 0;
      position: fixed;
      right: 0;
      top: 0;
      z-index: 10;
      background: #fff;
      width:inherit;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }

    .modal-header {
      background: gray;
      padding:20px;
    }

    ...

    LAST VISIBLE ELEMENT</div>

    </div>
    <div class='modal-footer'>
      <button>
        click
      </button>
    </div>
  </div>

</body>

Answer №2

Take a look at this response How can I add a scrollbar specifically to the modal body in a Bootstrap modal dialog?

.modal-dialog{
   overflow-y: initial !important
}
.modal-body{
   height: 250px;
   overflow-y: auto;
}

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 text-transform property in Css is not functioning as expected

Can anyone explain to me why the text-transform: none property is not working on my div? Any ideas? HTML <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <link href='https://fonts.googleapis.com/css?f ...

Which font file format is the most suitable for my website?

I've been doing some research on fonts for my website, and I've come across various formats available. Now I'm curious about what the standard format is or if there are multiple standard formats. .TTF (True Type Font) .EOT (Embedded OpenTyp ...

Using JavaScript to open links in a new tab with the target

document.getElementById("mahacareer").onclick = function () { window.open("http://www.mahacareermitra.in", '_blank'); }; <a href="" id="mahacareer">Access the portal</a> Hi there, I am looking to have the link above open in a new tab ...

Switching classes on the currently active tab

I have implemented Angular UI tabs with buttons that switch to different tabs. I am attempting to change the style of a button when its corresponding tab is active by using ng-class to dynamically apply styles. Inside my scope, I have a function that retu ...

Does scaling images for responsive web design help conserve bandwidth?

As I dive into the realm of creating responsive websites, I have encountered discussions about the challenges that arise when handling images. It seems that using images can consume a significant amount of bandwidth, especially when scaling down a larger i ...

Leverage scope variables and dynamic CSS properties when using ngClass

Is there a way to manipulate the CSS dynamically in HTML using a scope variable? <div ng-class="myClassScope, { 'dynamic-class': !ifIsNot }"> ...

Elevation of the specific area in my design

Can someone help me with a height issue I am experiencing? You can find the page in question here: The problem arises when zooming all the way out - the background of the #article div does not extend to the footer. How can I adjust the height of the #art ...

Achieve a translucent look for your text with a stylish border

I am attempting to showcase a number on a background image. Currently, my setup looks like this: body { background-image: url("https://i.picsum.photos/id/10/800/800.jpg"); background-repeat: no-repeat; background-position: center; width: 400px; ...

Adjusting the character limit for my textarea input

Here is the styling for my textarea: textarea { min-width: 120px; min-height: 90px; padding: 8px 10px; background: #FFF; border: 1px solid #E0E0E0; border-radius: 2px; outline: none; padding: 8px 10px; box-shadow: inset ...

Different method for adding child elements to the DOM

When creating a DOM element, I am following this process: var imgEle = document.createElement('img');     imgEle.src = imgURL;             x.appendChild(imgEle); Instead of appending the last line which creates multiple img elements ev ...

Issue with text not truncating in nested flexbox, and min-width is ineffective

I've been struggling for hours to implement text truncation in a flexbox layout (mainly with Bootstrap 5) but have had no success. I've come across suggestions to use min-with: 0 on the parent div, but despite trying various combinations, I can&a ...

Navigating through the website has become quite challenging due to the malfunctioning navigation bar. Instead

I recently completed a website and designed an awesome navigation bar in a separate file. However, when I combined them together, the navigation bar disappeared. The background of my "list" div should be filled in and larger, but it's not working as e ...

What could be causing the padding of my anchor element to extend outside the boundaries of its parent list

In the provided images, it is evident that the <li> element is failing to expand and is disregarding the padding of the parent element.</p> <p><a href="https://i.stack.imgur.com/4ZH65.png" rel="nofollow noreferrer"></a></p& ...

The functionality of Bootstrap is not meeting our expectations

My Node.js UI is using Twitter Bootstrap and Jade to generate HTML. I am trying to implement the jumbotron feature from http://getbootstrap.com/examples/jumbotron/. Additionally, I want to align tabs 1 & 2 in the same row as the project name on the nav-bar ...

Show varying HTML headers on the initial page as opposed to subsequent pages

Currently, I am utilizing an HTML to PDF Library known as Nreco for converting HTML Pages into PDF format. The task at hand involves implementing a consistent header on every page, with the exception of the first page that should display the Recipient Addr ...

I'm unable to adjust the font size of the final h3 element

I'm currently designing a webpage with various titles, but I've encountered an issue. I am unable to adjust the font size of the last h3 title without affecting the rest of the titles. I'm curious as to why this is happening and how I can re ...

What is the method to have a video automatically play as soon as the webpage is loaded?

Is there a way to have a video play automatically as soon as the page loads? Also, can you provide guidance on setting up multiple videos that can be switched using elements like buttons? Here's the source code: `https://codepen.io/yasgo/pen/BjbK ...

A guide on incorporating a component from a nested directory with webpack

https://i.sstatic.net/kLB0S.png The directory structure above shows how my react app 'MyProject' is organized. Using this structure, I successfully utilize the Layout component in Main.jsx (located at src/Main.jsx) by : import Layout from &apo ...

Tips for creating a double background color effect outside of a container

I want to create a footer similar to this design: https://i.sstatic.net/BIn4C.png html <footer> <div class="container"> <div class="row"> <div class="col-7 copyright__text py-3"> COPYRIGHT ...

A div housing a jQuery progress bar within an unordered list (ul)

Having an issue incorporating a jQuery progress bar into a ul li tag. <ul> <li> <a href="test">test</a> <div id="progressbar"></div> </li> </ul> I have set display: block for the anchor tag and ...