Ensuring Uniform Column Height in Bootstrap 4 With align-items-center

Utilizing Bootstrap 4, my goal is to create a row where all columns are vertically centered. To achieve this, I am implementing the Bootstrap 4 class align-items-center, as recommended in this SO answer.

Here is a simplified version of what I have:

.yellow-row {
  background-color: #f2c14e;
  color: #141823;
}

.blue-col {
  background-color: blue;
  color: white;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <title>Test</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
</head>

<body>
  <div class="container">
    <div class="row yellow-row align-items-center">
      <div class="col-lg-7 blue-col text-center">
        <h1>Testing</h1>
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos quasi omnis accusantium deserunt laboriosam magni veniam reprehenderit </p>
      </div>
      <div class="col-lg-5 text-center">
        <h1>Just a test</h1>
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusamus exercitationem mollitia officia natus tempora eos alias velit odit vitae ex! Nemo sint molestias deleniti corrupti placeat& lt;/p>
        <p>Officiis repudiandae obcaecati temporibus adipisci aliquam eius quo architecto similique corporis reiciendis vel repudiandae pariatur? Fugiat saepe voluptates autem fugit molestiae asperiores atque quam illo eligendi doloremque& lt;/p>
      </div>
    </div>
  </div>
</body>

</html>

The code snippet above renders output on wider screens like this:

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

The expected result is for the blue column to match the height of the parent row (and therefore the other column). I've experimented with adding min-height: 100% and height: 100% to the .blue-col class without success. Additionally, applying the Bootstrap 4 class h-100 to the blue-col didn't yield the desired outcome.

I believe there might be a gap in my understanding of how flexbox and vertical centering function in Bootstrap 4.

Answer №1

If you need to center align the content of a column without affecting the column itself, consider making use of flexbox. By setting the blue-col as a flexbox column (d-flex flex-column) and then applying justify-content-center, you can easily achieve the desired alignment...

<div class="container">
    <div class="row yellow-row">
        <div class="col-lg-7 blue-col text-center d-flex flex-column justify-content-center">
            <h1>Testing</h1>
            <p>Lorem reiciendis fuga possimus quibusdam doloribus Quos eaque earum voluptatem culpa vel obcaecati, ducimus sed Necessitatibus repudiandae suscipit ipsam magni laudantium? Inventore iusto sequi excepturi voluptatibus totam cupiditate. Dignissimos
                    quasi</p>
        </div>
        <div class="col-lg-5 text-center">
            <h1>Only a test</h1>
            <p>Lorem quisquam dolor velit maxime officia. Quos quo nihil sint sequi iste. Sed praesentium nihil illum amet tempora. Dolore exercitationem praesentium iure accusantium quibusdam? Fuga ex inventore dignissimos aut quas</p>
            <p>Lorem dolorum officiis velit deserunt facere? Dolorum provident aliquid sapiente quam perferendis Repellendus magni culpa nesciunt laborum dolorum Pariatur similique ullam quasi sit doloremque cupiditate! Autem odit mollitia libero magnam!</p>
        </div>
    </div>
</div>

https://www.codeply.com/go/kSvLCODvZC


For more on equal height columns and vertical/horizontal centered content in Bootstrap 4, check out this Stack Overflow post.

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

Formatting an invoice document with Bootstrap 4

Currently in my VueJS project, I am constructing an invoice form with the help of Bootstrap 4. Utilizing this snippet, everything has been running smoothly so far. However, I seem to be struggling when it comes to styling the UI at the moment. The issue I ...

Determining when all textures have successfully loaded in Three.js and ensuring there are no lingering black rectangles

I'm currently developing a web platform that allows users to customize and preview 3D house models. If the user's browser doesn't support WebGL, the server renders the house and sends screenshots to the client. However, if the screenshots ar ...

The presence of element hr within element ul is not permitted in this particular context. Additional errors from this subtree will not be displayed

Here is the code snippet that I have been working on recently: Originally, I had an "hr" tag directly included in my code which worked perfectly but caused a site validation error. So, I made some changes to the code as shown below: <nav> ...

Discovering the value of an HTML element node in the TinyMCE editor through the use of JavaScript or jQuery

Is there a way to retrieve the node name value using JavaScript or jQuery within the TinyMCE editor? Currently, I am only able to access the nodeName using the code snippet below: var ed = tinyMCE.activeEditor; var errorNode = ed.selection.getNode().node ...

css: align elements at the top with another element instead of the bottom

Currently, I have three elements displayed inline block with each other. The two smaller grids are flush with the bottom of the larger chart by default. Is there a way to make them flush with the top of the larger chart instead? Check out the layout here: ...

The console is showing an error message that reads: "Uncaught SyntaxError:

After making changes to the function moveElement by switching its formal parameter from elementID to just element, I encountered an issue. I wanted to directly pass the DOM object from the function positionMessage to the function moveElement. However, Chro ...

Load ajax asynchronously once the page has finished loading

I am exploring the world of AJAX with jQuery for the first time, and I am still relatively new to jQuery. Here is the code structure: $(document).ready(function(){ data_url = $('.lazy_content').attr("data-url"); data_id = $( ...

The selection will remain hidden and attempting to make a choice will be ineffective

Received an HTML sample from another company () and now I am attempting to create a web form based on it (). Using the same scripts, the basic structure mirrors the sample closely. After meticulously comparing the code, I can't find any discrepancies. ...

Is there a specific CSS selector that targets elements with "multiline" content?

My website has a menu that displays with the following CSS: a { background:red; } <a href="#">Home</a> <a href="#">Downloads</a> <a href="#">Contact</a> <a href="#">FAQ</a> <a href="#">Disclaimer&l ...

Sketch the borders of the element (animated)

Seeking a way to create a button with an animated border that looks like it is being drawn. Current progress involves some code, but it's not working smoothly with border-radius set. (keep an eye on the corners) https://codepen.io/anon/pen/MbWagQ & ...

Using the arrow keys to navigate through a list of items without using jQuery

Exploring ways to develop a basic autocomplete feature without relying on third-party dependencies has been my recent project. So far, I have managed to populate a results list using an ajax call and complete fields with mouse onclick events for each optio ...

Display or conceal various objects using a single button in HTML

I've been working on creating a chatbot widget for my website, but I've run into an issue. The "Chat with us" button only shows the bot and not the close button as well. Here's what I've attempted: <input id="chat" type="button" on ...

Modify the image inside a div when hovering

How can I create a product card that displays thumbnails of images when hovered over, and changes the main image to the thumbnail image? My current challenge is getting this functionality to work individually for each card on an e-commerce site. Currently, ...

Customize card borders with Handlebars and BootStrap styling

I am utilizing Bootstrap 4 with nested cards containing tabs and headers, which also house forms. Additionally, I am using Handlebars to retrieve JSON data and fill in the form fields. However, upon transitioning from hardcoded data to using Handlebars fo ...

Displaying text from an array in a div using JavaScript with a 2-second delay

I am relatively new to this, so please forgive me if something is not quite right. I have an array filled with different strings of text, and I want to display each string in an HTML div with a 2-second delay between each line. While I have managed to show ...

Creating custom styles for select dropdowns using only CSS

After spending nearly two hours scouring the internet, I couldn't find a single example of how to style a select dropdown with CSS. I was particularly interested in using z-index to display the select dropdown under an absolutely positioned div block. ...

Split the output into two separate columns in a cshtml file using a foreach

Is there a way to modify my current code so that the output is displayed in two columns instead of one? Would using flex grid be the best approach, or is there another method I should consider? <div class="col-12 box-container"> <div class=" ...

Clicking on the element will delete the containing parent div

I'm attempting to remove a specific div when clicking on a link. The issue I'm facing is that there are multiple instances of the same div and link structure, and when I tried creating a function for it, it ends up removing all of the divs. $( ...

After sending a post request, the form in HTML with Node.js is returning an undefined response

Upon creating an HTML <form></form> object to capture a username, email, and password, I encountered an issue where the value returned is always undefined when accessing req.body.name or any other field. It seems like the form is not functionin ...

Optimal Strategy: Utilizing Spring Boot for Backend Development and jQuery for Frontend Interface

I am currently tackling a project that involves a Spring Boot 2 Backend and a jQuery Frontend. The frontend communicates with the backend by sending Ajax requests to Spring REST controllers in order to interact with database entities. One of the challenge ...