Customize your Bootstrap 4 card: change the header content, keep the body fixed

My current project involves the use of a bootstrap 4 card element:

<div class="card" style="height:"500px;width:100px">
         <div class="card-body">
           <div class="top-portion">
               This section can be variable in height.
           </div>
           <div class="content" style="overflow-y">
               ....
               ....
           </div>
         </div>
       </div>
       

I am facing a challenge with getting the ".content" div to take up the remaining vertical space and become scrollable when needed. I understand that I need to add "max-height:..." to its styling.

The issue arises because the height of the ".top-portion" varies, making it difficult for me to determine the exact value to set for "max-height".

Answer №1

    <div class="card" style="height:500px; width:100px;overflow: hidden;">
        <div class="card-body d-flex flex-column">
          <div class="top-portion mb-auto">
              The content in this section can vary from just a few lines to several paragraphs.
          </div>
          <div class="content" style="overflow-y:auto;max-height: 200px;">
              Lorem Ipsum is simply dummy text of the printing and typesetting industry. It has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. This text has survived for centuries and has adapted into electronic formats without much change. Its popularity soared in the 1960s with Letraset sheets containing Lorem Ipsum passages, and continues to be used today in desktop publishing software like Aldus PageMaker.
          </div>
        </div>
      </div>

Feel free to utilize this code snippet for your card layout. The "top-portion" height adjustment will not affect the content within. By using "mb-auto," you can position the content area at the bottom of the card if desired.

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

Adjust button size on various devices with boostrap classes

I am looking to make my large button (btn-lg) smaller on small devices. How can I achieve this? <div class="col-4 col-md-2 col-lg-1 mt-md-5"> <a href="{{ url_for('remove_favourite', trail_id=fav._id ) }}" class=" ...

Trigger an immediate repaint of a DOM element in the browser

Searching for a way to insert a large HTML markup into a DOM element that will take some time. This is why there's a need to display a preloader indicator before the process begins. Two blocks are involved: #preloader and #container. Initially, the pr ...

Sliced Text Transformation

Recently, I inquired about a pesky text effect that was bothering me. Thanks to the assistance of fellow users, I discovered that the culprit behind the effect was the background color's edge. Eliminating this problem should be simple, but even with ...

Delete the line height (or leading) for bigger text in CSS

Is there a way to eliminate the space above and below the mandatory span, specifically when using << within it? The height of the field row is determined by the default line-height for the text size, but the mandatory field is taller due to its larg ...

Ways to hover and efficiently organize components?

My elements are floated with a width of 20%, resulting in 5 elements per line. The current arrangement looks like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Now, I want to reorganize them vertically as follows: 1 4 7 10 13 2 ...

Make sure your website design is responsive by setting the body to the device's

https://i.sstatic.net/3xHcx.png I'm struggling to make the body of my page responsive for mobile users. Whenever I try using this line of code, it just creates a messy layout. Any advice on how to fix this? <meta name="viewport" cont ...

What is the reason behind div elements shifting when hovering over a particular element?

Currently, I have floated all my div elements (icons) to the left and margin-lefted them to create space in between. I've displayed them inline as well. However, when I hover over one element (icon), the rest of the elements move. Can you please help ...

How can jQuery be utilized to dynamically update the text in a navbar?

<div id="page1" data-role="page"> <div data-role="header" data-position="fixed" align="center"><img src="img/VAWE-long-300x30-transparent.png" width="300" height="30" alt="" /></div> <div data-role="content" style="margin ...

Get rid of the .php extension in the URL completely

Lately, I've been experimenting a lot with the .php extension. I successfully used mod_rewrite (via .htaccess) to redirect from www.example.com/example.php to www.exmaple.com/example. Everything is running smoothly. However, I noticed that even though ...

Ignore the initial children of the highest level divs exclusively

Is there a way to apply a style to all top-level divs within a div, excluding the first one? I have tried using not(:first-child) but it seems to be recursive. How can this be achieved? <div class='want-to-skip-first-a'> <div class= ...

`Switching between two buttons: A guide`

Here is the codepin: https://jsfiddle.net/magicschoolbusdropout/dwbmo3aj/18/ I currently have a functionality in my code that allows me to toggle between two buttons. When I click on one button, content opens and then closes when clicked again. The same b ...

"Enhance User Interactions with Angular-ui Tooltips Featuring

I recently integrated bootstrap tooltips into my application. While the "normal" tooltips are working fine, I encountered an issue with tooltip-html-unsafe. It seems to display an empty tooltip. Here is my tooltip code: <a><span tooltip-placeme ...

What is the correct way to include '?i#efix' in a font directory path in a Rails application?

It is suggested to include ?#iefix at the end of .eot font paths in order to resolve another erratic behaviour issue in IE: @font-face { font-family: 'MyWebFont'; src: url('webfont.eot'); /* IE9 Compat Modes */ src: url(&ap ...

Certain visual elements fail to display properly within the web browser

I have a website with 5 pages (e.g. page1.html, page2.html, etc.), each having its own .css stylesheet. Oddly, some pages display images correctly while others do not. It seems like the issue might be with the specific pages or files, as using the same ima ...

Struggling with the installation of SimpLESS

I encountered an issue while attempting to install SimpLESS on my Windows 7 64bit PC. Upon running the installer, I was met with an error message stating: "Could not query info: Invalid HTTP Status Code (403)". Despite my efforts to search for a solution o ...

The way images appear can vary between desktop and mobile devices

I am in the process of creating a photography website with a simple goal of displaying images down the page one after another. However, I am encountering issues with uniform display across various desktop and mobile platforms. The site appears perfect on i ...

Setting the z-index for a JavaScript plugin

I need help with embedding the LinkedIn plugin into a website that has stacked images using z-index for layout. I have tried assigning the plugin to a CSS class with a z-index and position properties, but it hasn't worked as expected. Can anyone sugge ...

Having trouble with the dropdown menu in Bootstrap?

I'm having trouble creating a responsive dropdown menu. When I click on the dropdown items, nothing happens. Here's the code: <div class="navbar-header"> <button type="button" class="navbar-toggel" data-toggel="collapse" data-target="#m ...

Images Centerfold Team

I am facing a challenge in creating a group of images for an album. There seems to be a significant gap on the right side, which cannot be resolved without using padding. However, adding padding only works for my current PC resolution and creates a larger ...

Guide to implementing a real-time countdown timer for days, hours, minutes, and seconds leading up to a specific date and time with JavaScript

Implement a dynamic countdown timer in JavaScript that counts up to a specific date. See the example image for reference: here ...