Tutorial on achieving full screen height for Bootstrap card within a column

I am working on a React grid layout with two cards, each in one column. My goal is to make the card on the left fill the entire column height (screen height), and if its content expands, have a scrollbar while keeping the second card intact and aligned to the middle of the screen.

<header className="App-header">
  <Container>
    <Row>
      <Col md={4}>
        <Card>some text here</Card>
      </Col>
      <Col md={8} className="align-self-center">
        <Card>some other text here</Card>
      </Col>
    </Row>
  </Container>
</header>

Here is the CSS code snippet:

.App-header {
  background-color: #282c34;
  min-height: calc(100vh - 59px);
  max-height: calc(100vh - 59px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
}

This is the current UI design: https://i.sstatic.net/3vdmh.png

You can also view the code on CodeSandbox here

Answer №1

To ensure your layout is properly adjusted, make sure to include the following classes in your HTML structure:

Within your container element, row element, column with a medium breakpoint of 4, and card element, add the class "h-100". This will set the height of both the column and card to be equal to 100vh - 59px.

Additionally, you can enable vertical scrolling by applying the style "overflow-y: auto" or using Bootstrap's predefined class "overflow-auto" on the card element.

To center the right card within the row, apply the class "align-items-center" to the row element.

Here is an example snippet:

import React from "react";
import "./App.css";
import { Card, Col, Container, Row, Button } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";

export default function App() {
  return (
    <div className="App">
      <header className="App-header">
        <Container className="h-100">
          <Row className="h-100 align-items-center"> /* <-- put the align items here */
            <Col md={4} className="treeViewComponent h-100">
              <Card className="h-100 overflow-auto">
                <Card.Body>Text here</Card.Body>
                <Card.Footer>
                  <Button>Do stuff</Button>
                </Card.Footer>
              </Card>
            </Col>
            <Col md={8} className="compressionComponent align-items-center">
              <Card>
                <Card.Body>
                  More text here text here text here text here text here text
                  here text here text here text here text here{" "}
                </Card.Body>
              </Card>
            </Col>
          </Row>
        </Container>
      </header>
    </div>
  );

Don't forget to style the .App-header as well:

.App-header {
  background-color: #282c34;
  height: calc(100vh - 59px);
  font-size: calc(10px + 2vmin);
}

Answer №2

In my opinion, adding height: 100% to the css of the specific column you want to extend should automatically fill up the container.

If you want scrolling to be enabled only when necessary, simply set the css property overflow: auto on the scrollable container.

Based on your css code, it seems like the other card is meant to remain centered despite these adjustments.

Answer №3

To incorporate Bootstrap classes, simply include the vh-100 class on the left card. Additionally, in your custom CSS, remember to add overflow-y : auto to enable scrolling only when necessary.

Answer №4

It appears that you have implemented flexbox in your layout. To optimize the use of flex, consider utilizing the align-items: stretch; property alongside setting a maximum height for the parent container.

  • The align-items: stretch; declaration enables child elements to occupy the entire available height within the container.
  • If you set a restriction on the parent container's height, you can apply overflow settings to an internal element as needed.

Answer №5

Include overflow-hidden, vh-100, and mh-100 in the styles for the left column...

       <div className="App">
          <header className="App-header">
            <Container className="">
              <Row className="align-items-center overflow-hidden">
                <Col
                  md={4}
                  className="treeViewComponent vh-100 mh-100 overflow-hidden"
                >
                  <Card className="h-100 overflow-auto">
                    <Card.Body>Text goes here</Card.Body>
                    <Card.Footer>
                      <Button>Perform action</Button>
                    </Card.Footer>
                  </Card>
                </Col>
                <Col md={8} className="compressionComponent align-items-center">
                  <Card>
                    <Card.Body>
                      More text here more text here more text here more text here more text
                      here more text here more text here more text here more text{" "}
                    </Card.Body>
                  </Card>
                </Col>
              </Row>
            </Container>
          </header>
       </div>

https://codeply.com/p/vbMAhSXkLm

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

Issue with Bootstrap Navbar dropdown causing page refresh instead of menu dropdown activation

<!DOCTYPE html> <html lang="en" dir="ltr" style="style.css"> <!-- All icons were courtesy of FlatIcon : www.flaticon.com and FreePik : www.freepik.com --> <head> <meta charset="utf-8"&g ...

Tips for centering fontawesome icons in your design

https://i.sstatic.net/Atian.pngI'm facing an issue with aligning 3 icons. My goal is to align them, but every time I attempt something, the first icon ends up in the middle of the page instead of the second icon where I want it to be. .item-icon { ...

Utilizing numerous script elements for three.js library

Today, I ventured into the world of three.js for the first time, along with exploring html and js in general. While experimenting with some example code, I encountered an issue. It seems that importing the three.js file from the script tag in my Main.js ...

Is it possible to adjust the width of the comment box on the Facebook "Like" button?

Is there a way to set the width of the comment box that appears after clicking the Facebook "Like" button? I know how to adjust the width of the button itself and related content, but can't find any options for the comment box: I've tried overri ...

Retrieve the chosen option within the current page

Currently, I am working with a select button on my webpage: <form method="post"> <label> <select id="label" name="challengeX" style="margin-top:150px;"> <option selected value="0"> Global Statistics </opt ...

Tips for arranging 3 cards in a straight line across the horizontal axis

I'm new to coding and I've recently started using HTML, CSS, and Bootstrap 4. Currently, I'm working on a webpage that includes a navigation bar, 4 cards, and a footer with information. I utilized Bootstrap to create rows and columns, but I& ...

The modal feature is malfunctioning on a dynamic Flask website across all web browsers

I've encountered a peculiar issue while developing a Flask website that involves the functionality of a Bootstrap modal. This problem is consistent across different browsers like Firefox, Chrome, and Safari. On the main route of my website, users can ...

What is the best way to programmatically select a checkbox that was created dynamically using jQuery?

I've been scouring the internet trying to find information on what I'm attempting to accomplish, but so far I haven't come across anything helpful. The issue I'm facing is with a form that has a section dynamically added using JavaScri ...

Change the maximum width of the parent element when it is positioned relatively

In my web design project, I have a full-container with a maximum width of 1080px and positioned relatively to hold all content. Within this container, there is another div element (.portfolio) that I want to extend to the full width of the page (max-width: ...

What is the appropriate syntax for the second division?

<style> .panel{ border:1px solid #000; } </style> <div class="body"> <div class="panel"></div> <div class="panel" style="border-top:0px;"></div> </div> In order to apply the style border-top:0px; to ...

Display a loading GIF for every HTTP request made in Angular 4

I am a beginner with Angular and I am looking for a way to display a spinner every time an HTTP request is made. My application consists of multiple components: <component-one></component-one> <component-two></component-two> <c ...

Make sure the text fits perfectly without any extra spaces

When working with CSS/HTML, I noticed that using a simple text within a div without any margin or padding, and specifying a font-size of 36px with a line-height also set to 36px doesn't fit perfectly - there is always some spacing at the top of the li ...

Neglecting to include an external CSS file within a .aspx content page in an ASP.NET WebForms application

I've been facing some challenges while trying to incorporate an external CSS file into the content pages of my asp.net WebForms application. The content pages have a master page (Site.Master) which includes the following code in the head section: < ...

What is the best way to align the logo image in the center of the header vertically?

I am trying to vertically center my logo, but I have not been successful with using margin: auto or margin: center. Here is what I have tried so far: ・text-align: center; ・margin: auto; ・margin: center: ・navbar-brand-center The logo currently app ...

To retrieve data with Bootstrap modal, simply pass the ID to the URL and utilize it for querying in the Laravel controller

Is there a way for me to extract the ID from my blade template and send it to a URL using a bootstrap modal? Take a look at the code snippet below. Controller I'm trying to figure out how to pass the ID to the URL so that I can retrieve "17" in orde ...

Update the CSS of a different element when hovering

Hello to all the jQuery developers out there! I have a question that's fairly simple. I'm trying to change a CSS attribute for an element when I hover over a different element on the page. I've created a fiddle for you to review, and I&apos ...

Incorporate Arabic typography into the React Material Theme

My goal is to utilize the Noto Sans Arabic font within my React material UI theme. Everything seems to be functioning correctly, including overrides. Despite consulting the React Material UI documentation and attempting to follow similar steps as outlined ...

Ensuring the height of the HTML element for menu items matches the navigation bar

I've been struggling to customize a navigation bar styled with Bootstrap 4. My goal is to create a hover effect on the menu items similar to the image or code snippet provided, but without that annoying thin blue flashing offset below the item. Despit ...

Optimal method for retrieving data in JSON format

Hey everyone, I've been using Ajax to modify a div on my website. I have a function that works perfectly, but I'm having trouble retrieving the value it returns. updatecart = function(qty, id_product) { var currentVal, data, id, item_hash, ...

How to create a clickable link that functions as a file upload button

I am working on a project where I need to create a link that acts as a file input when clicked. Here is the code for the link: <a id="upload-file">Upload your photo</a> Is there a way to make this link function as a browse file input? Any ...