Modify the content of the bootstrap modal-body to become scrollable

Bootstrap is a familiar tool for me, but I'm fairly new to flexbox css.

In my bootstrap modal, I typically have a header, body, and footer. I'm trying to modify the model-body class so that if the content exceeds a certain size, it becomes scrollable, while keeping the model-header and model-footer fixed in position. I've considered using flexbox css, but I'm unsure of its functionality. Below are the flexbox css properties I've used:

Template:

<div class="modal-header">
   <!-- contents.. -->
</div>
<div class="modal-body">
   <!-- contents.. -->
</div>
<div class="modal-footer">
   <!-- contents.. -->
</div>

CSS:

.modal-content {
 display: flex;
 flex-direction: column;
 max-height: calc(100vh - 60px);
}

.modal-body {
   overflow: auto;
}

.modal-header, .modal-footer {
 flex-grow: 1;
 flex-shrink: 0;
 flex-basis: auto;
}

I've set the model-content to be the maximum viewport height minus 60 pixels. This setup works well except in IE, where the content spills over and doesn't hide properly. If anyone has suggestions or comments on how to address this issue, I would greatly appreciate it!

Answer №1

Fixing the issue was quite simple; just add max-height: calc(100vh - 60px); to the modal-content selector, remove it from there and add it to the modal-body selector instead.

CSS

.modal-content {
    display: flex;
    flex-direction: column;
}
.modal-body {
    overflow: auto;
    max-height: calc(100vh - 60px);
}
.modal-header, .modal-footer {
    flex-grow: 1;
    flex-shrink: 0;
    flex-basis: auto;
}

Modal

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                This Is header
            </div>
            <div class="modal-body">
                This is content...
            </div>
            <div class="modal-footer">
                This is footer
            </div>
        </div>
    </div> 
</div>

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

Fiddle Tested in IE-10

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

Centering a button within a table-cell through movement

I'm facing an issue with aligning a button placed inside a table cell. The table setup is as follows: <b-table v-if="rows.length" :thead-tr-class="'bug-report-thead'" :tbody-tr-class="'bug-report-tbody& ...

Achieving consistent alignment within table rows of divs with varying heights using a fluid layout - CSS

Currently, I am developing a mobile site with a fluid layout. The main page features a table that displays several products. Within each product, there are 3 divs: product-image, product-name, and prices-container. I'm faced with the challenge of ...

Semantic UI table with rowspan feature

I am a beginner with semantic ui and I have been trying to replicate this specific layout. While going through semantic ui's documentation, I found something similar but not quite identical. Below is the HTML code: <div class="ui celled grid cont ...

Modify CSS according to the selected value from a dropdown menu

I have a form in which users can select options, and based on their selection, certain questions need to be hidden. I am looking for a way to use jQuery to detect when a specific option is chosen and then modify the CSS of the page accordingly. <sele ...

Tips for converting plain text output into HTML tags

I recently set up a contact form 7 on my website, and I'm trying to customize the message that appears after submission. However, I'm running into an issue when attempting to split the message into two different colors. I created a span class to ...

Is it possible to adjust the font size based on the dimensions of the page?

Is there a method to adjust the font-size based on the size of the page? Using percentages as the unit seems to refer to the standard font size (such as 90% of 12px, not 90% of the page itself!). This differs from how most other elements behave. Is there ...

Looking for assistance in creating a stunning portfolio showcase?

As I work on building my portfolio webpage, I've realized that with my limited knowledge of HTML/CSS, creating a great gallery might be challenging. In search of an efficient solution, I ventured across the web but couldn't find anything that ful ...

Unable to utilize CSS to swap out background image in Bootstrap 3

I am attempting to use Bootstrap 3 to display a smaller image instead of a larger one on small devices. However, when I implement the code provided, nothing appears. If I directly put the image source in the HTML, both images are displayed in specific vie ...

Is there a way to update the button's value upon clicking it?

I've hit a roadblock in my tic tac toe game project during class, and I've been struggling for the past two days to get the X's and O's to show up. The deadline for this assignment is tomorrow! Here are the task requirements: COMPSCI20 ...

Using JavaScript, what is the best way to change the x/y position of an element?

https://i.sstatic.net/5jUa4.png I have included an image to illustrate my request. In the setup, there is a container with a yellow border and content enclosed in a red border. My goal is to have the content scroll left by the width of one container when t ...

The HTML form label offers a choice between two alternatives

My usual method of styling forms involves organizing elements like this: <label for="CompanyNameTextBox"> <span>Company</span> <input name="CompanyNameTextBox" type="text" id="CompanyNameTextBox" /> </label> This set ...

Mastering the art of combining images and text harmoniously

I am having trouble aligning my lion image and h1 tag side by side. There seems to be an issue but I can't figure out what it is. h2 { width:50%; float:right; padding:30px 0px 0px 0px; margin:0 auto; } .lion { width:10%; float: left; paddin ...

Creating a slanted bottom edge on a div without compromising responsiveness

Is there a way to create a skew on the bottom side of a div without it being affected when the height and width change in responsive design? Check out the image for reference. I've attempted using the CSS transform property, but haven't been able ...

Creating a div caption that mimics a form label, but with the background div border removed, can be achieved

Is there a way to create a div caption similar to a form label (positioned in the middle of the border), but without the div's border interfering? The issue is that I can't just use a background color for the H1 (caption) element because there is ...

Ensuring a smooth user experience on Internet Explorer with CSS backup

I am looking to incorporate a CSS 3D effect into a website. I have successfully implemented it on all browsers except Internet Explorer (including IE 11). As far as I know, IE does not support preserve-3d. Can someone help me add a fallback option for IE, ...

Move the close button on Bootstrap's Modal to the left side

I am currently in the process of building a new website and I am still learning HTML, CSS, and other related technologies. I am utilizing Bootstrap to assist me, but I have run into a problem. The website I am working on is in Hebrew and I am struggling to ...

displaying and concealing elements with jquery

Is there a way to hide a div if the screen size exceeds 700px, and only show it when the screen size is less than 700px? Below is the jQuery code I'm attempting to use: jQuery(document).ready(function() { if ((screen.width>701)) { $(" ...

I customized the navbar in Bootstrap by centering it with custom CSS, but whenever I click on it, it suddenly shifts to one side. I'm puzzled as to why this is happening and

I attempted to center my navbar-toggler element, but was only successful in centering the navbar-contend using Bootstrap. I then took it a step further by trying to center the navbar-toggler icon with custom CSS, however, it now shifts to the left when cli ...

Customizing the appearance of a radio button within a form

I need assistance with styling a form that contains a radio button. I'm looking to customize the appearance of the radio button by adding a background image and also changing the default view of the check image. Additionally, I want the form to be cen ...

Utilize jQuery to alter the global CSS declaration

I have been utilizing Twitter Bootstrap to generate form components as illustrated below. Typically, the 'submit' button should be placed outside of the 'controls' container, however, for my specific layout requirements, I need it to be ...