Guide to aligning text vertically in a column alongside an image using Bootstrap 5

I have been using the Bootstrap 5.3.2 grid system for most of my website. I am trying to create a layout with an image on the left and text on the right. However, I am facing an issue with aligning the text vertically in the column. Is there a way to achieve this without compromising the full-width of the h2 and p elements?

I tried using d-flex to vertically align the content, but it only partially solves the problem. I want the h2 and p elements to span the full width of the column. Are there any other solutions that could work better for this layout? Thank you!

<div class="container">
<div class="row">
  <div class="col-lg-4"><img src="https://placehold.co/600x400" alt=""/></div>
  <div class="col-lg-8">
    <h2>A header goes here</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Incidunt vitae quisquam, non quaerat mollitia sit rem omnis ducimus nulla harum at minima enim, ipsa soluta laudantium.</p>
  </div>
</div>
<div class="row">
  <div class="col-lg-4"><img src="https://placehold.co/600x400" alt=""/></div>
  <div class="col-lg-8 d-flex align-items-center">
    <h2>A header goes here</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Incidunt vitae quisquam, non quaerat mollitia sit rem omnis ducimus nulla harum at minima enim, ipsa soluta laudantium.</p>
  </div>
</div>

Answer №1

you should give this a shot

<div class="container">
<div class="row">
  <div class="col-lg-4"><img src="https://placehold.co/600x400" alt=""/></div>
  <div class="col-lg-8">
    <h2>Here is a header</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Incidunt vitae quisquam, non quaerat mollitia sit rem omnis ducimus nulla harum at minima enim, ipsa soluta laudantium.</p>
  </div>
</div>
<div class="row">
  <div class="col-lg-4"><img src="https://placehold.co/600x400" alt=""/></div>
  <div class="col-lg-8 d-flex flex-column justify-content-center">
    <h2>Here is another header</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Incidunt vitae quisquam, non quaerat mollitia sit rem omnis ducimus nulla harum at minima enim, ipsa soluta laudantium.</p>
  </div>
</div>

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

Changing Background Images Based on Screen Size in CSS Media Queries

Hey there, I am currently using two different header images - one for desktop and another for both tablet and mobile devices. I am wondering how I can automatically switch from the desktop header image to the mobile/tablet header image when the screen siz ...

Having trouble loading static CSS files in Django

Need help linking the main.css file in my index.html <link rel="stylesheet" href="{% static 'assets/css/main.css' %}"/> I have also included {%load static%} Here is my file structure: signup/static/assets/css/main.css In settings.py S ...

``I'm having trouble getting the onchange event to function properly in a customized

After following a tutorial, I successfully created a custom select dropdown using the provided link. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_custom_select However, I am facing an issue with the onchange event not working for the select ...

Guide on how to modify the CSS styling of a particular <td> element when its parent contains a specific class

.webgrid-table td, th { border: 1px solid #98bf21; padding: 3px 7px 2px; } I am facing an issue where the style defined above is being applied to all td elements. However, I want to exclude the styling for a td that is within a tr element with the ...

Issues arise when dealing with a CSS and HTML accordion

I decided to create a CSS and HTML collapsing menu system, also known as an accordion. I found a tutorial on how to do it here. However, I had to make some modifications because I wanted to include images in the 'sections' later on. Instead of us ...

Ways to update the div's color according to a specific value

Below are the scripts and styles that were implemented: <script src="angular.min.js"></script> <style> .greater { color:#D7E3BF; background-color:#D7E3BF; } .less { color:#E5B9B5; background-co ...

How can I align multiple lines of text vertically?

Currently employing: #leftfoot {padding-left: 20px; vertical-align: middle;} Unfortunately, this code is not yielding the desired results. Despite searching through numerous explanations, I haven't been able to find a solution that works for me. Can ...

Eliminate list items with a keyboard stroke

I am currently developing a straightforward todo list application using JavaScript. The main functionality I am trying to implement is the ability to add new items from an input field to a list, as well as the option to remove items from the list. While ...

Code snippets to reduce excess white space on a website using HTML and CSS

On my website, there are multiple tabs, each containing content from an HTML file. When a user clicks on Tab1, boxes with images are displayed. The layout can be seen in the following Code Demo: Code Demo here There seems to be extra space before and afte ...

Trouble clicking the web-page menu icon once it collapses

The collapse class I applied to the navbar is not functioning properly. When the button is clicked, the menu does not display. Here is the complete code for the navbar: <nav class="navbar navbar-expand-md navbar-light bg-light"> &l ...

Creating a circular frame for your image to use as a Facebook profile picture

In the process of developing an input feature that allows users to upload file images for avatar changes, similar to Facebook's functionality. However, I am aware that Facebook utilizes a circular area for avatars and enables users to adjust the image ...

Modifying the appearance of Bootstrap button colors

I recently came across this code on the Bootstrap website. I am curious about how to change the text color from blue to black in this specific code snippet. Currently, the text is appearing as blue by default. For reference and a live example, you can vis ...

Is it possible to make changes to local storage data without impacting the rest of the data set?

https://i.sstatic.net/BBcJF.pngI am looking for a way to modify specific data in the local storage without affecting any other stored information. However, I have encountered an issue where editing values works correctly for the first three attempts, but ...

Create a log table specifically for tracking changes made to the drop-down menu

I need to create a Change log table that will track any changes made in the drop-down menu. For instance, I am working on a worksheet with a select menu called Results which includes options like Positive, Negative, Unknown. I want the system to log any ch ...

What is the process for adding color to the rows of a table?

Hello, I have a table with various fields that include: I am looking to assign colors to entire rows in the table based on certain criteria. For example, if the ASR value falls between 75 and 100, it should be assigned one color; for values between 50 and ...

What is the best way to create a responsive menu in code?

I am working on creating a responsive menu. Check out cuppcomputing For the desktop version, the whole panel will be displayed when it meets the max-width: 600px (tablet and mobile size). Initially, only the title is shown, and clicking on it will reveal ...

Exploring CSS3 animations: customizing animations for individual elements based on scroll movements

Can you help me with CSS3 animations triggered by scrolling? I came across a code that reveals a DIV element as the user scrolls down: <script type="text/javascript"> $(document).ready(function() { /* Every time the window ...

The float:left property within a div is not behaving as anticipated

I am having trouble positioning my second div. In order to have 70% of my website for posts and 30% for a small text display, I created a new div. I believe the correct way to position it is by using "float: left" so that the div goes under the banner whe ...

hover-triggered keyframe animation

Recently, I've been experimenting with CSS keyframe animation using the code below: .pulse-animation { margin: 50px; display: block; width: 52px; height: 52px; border-radius: 50%; background: #ff8717; cursor: pointer; animation: pul ...

Is it possible to create a resizable menu without distorting its appearance?

After setting up a menu on my website, I noticed that when resizing the window, it spills over into other divs on the same line. Despite trying multiple solutions, I have been unsuccessful in resolving this issue. The navigation for the menu is contained w ...