'Bootstrap align items in column
I got the following problem:
Picture 1 shows the prototype:

Im using Bootstrap 5 as css framework. I thought i can handle it through the built in columns, but i dont find any solution and struggling hard right now.
Picture 2 shows my solution:

I tried flexbox but couldnt find any solution.
<div class="col-lg-6 col-md-1">
<div class="row">
<img src="https://place-hold.it/90" class="col-lg-3 col-md-12 facts-img">
<h3 class="facts-header col-lg-2 col-md-12">
Licht
</h3>
<p class="facts-p col-lg-6 col-md-12 facts-text">
Das zentrale Element in unserem Leben. Es weckt Emotionen, beeinflusst unser
Wohlbefinden und füllt unsere Energiespeicher auf. Durch das Licht nehmen wir die
unterschiedlichen Farben wahr. Licht schafft Ambiente.
</p>
</div>
</div>
Solution 1:[1]
Your structure is not correct. You need a row to enclose the immediate col's and then a new row for the next col. Try this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="row">
<div class="col-lg-6">
<div class="row">
<div class="col-sm-2 d-flex align-items-center justify-content-center">
<img src="https://place-hold.it/90" class="col-lg-3 col-md-12 facts-img">
</div>
<div class="col-sm-10">
<h3 class="facts-header col-lg-2 col-md-12">
Licht
</h3>
<p class="facts-p col-lg-6 col-md-12 facts-text">
Das zentrale Element in unserem Leben. Es weckt Emotionen, beeinflusst unser Wohlbefinden und füllt unsere Energiespeicher auf. Durch das Licht nehmen wir die unterschiedlichen Farben wahr. Licht schafft Ambiente.
</p>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="row">
<div class="col-sm-2 d-flex align-items-center justify-content-center">
<img src="https://place-hold.it/90" class="col-lg-3 col-md-12 facts-img">
</div>
<div class="col-sm-10">
<h3 class="facts-header col-lg-2 col-md-12">
Licht
</h3>
<p class="facts-p col-lg-6 col-md-12 facts-text">
Das zentrale Element in unserem Leben. Es weckt Emotionen, beeinflusst unser Wohlbefinden und füllt unsere Energiespeicher auf. Durch das Licht nehmen wir die unterschiedlichen Farben wahr. Licht schafft Ambiente.
</p>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>
Solution 2:[2]
Just to give eagle eye view. Use classes in following hierarchy
.Container
. row //main row
.col //block for Licht
.row // wrapper for Licht
.col // column for round object
.col // column for text element
.row // for heading Licht
.row // for description
.col // column for Design
.row // wrapper for Design
.col // column for round object
.col // column for text element
.row // for heading Design
.row // for description
Solution 3:[3]
you can try with media object
Example 1
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex">
<div class="flex-shrink-0">
<img src="https://www.pavilionweb.com/wp-content/uploads/2017/03/man-300x300.png" class="mr-3" width="150" alt="...">
</div>
<div class="flex-grow-1 ms-3">
<h5 class="mt-0">Media heading</h5>
<p>
This is some content from a media component. You can replace this with any content and adjust it as needed.
</p>
</div>
</div>
Example 2
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-lg-6">
<div class="row">
<div class="col-sm-3">
<img src="https://www.pavilionweb.com/wp-content/uploads/2017/03/man-300x300.png" class="mr-3 img-fluid" alt="...">
</div>
<div class="col-sm-9">
<h3 class="facts-header col-lg-2 col-md-12">
heading
</h3>
<p class="facts-p col-lg-6 col-md-12 facts-text">
This is some content from a media component. You can replace this with any content and adjust it as needed.
</p>
</div>
</div>
</div>
</div>
Solution 4:[4]
You can also use flex for this
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="d-flex flex-column flex-md-row p-4 w-100">
<div class="d-flex flex-row align-items-center">
<div class="p-2">
<img src="https://place-hold.it/90" class="col-lg-12 col-md-12 facts-img rounded-circle">
</div>
<div class="d-flex flex-column ">
<h3 class="facts-header col-lg-2 col-md-12">
Licht
</h3>
<p class="facts-p col-lg-8 col-md-12 facts-text">
Das zentrale Element in unserem Leben. Es weckt Emotionen, beeinflusst unser
Wohlbefinden und füllt unsere Energiespeicher auf. Durch das Licht nehmen wir die
unterschiedlichen Farben wahr. Licht schafft Ambiente.
</p>
</div>
</div>
<div class="d-flex flex-row align-items-center">
<div class="p-2">
<img src="https://place-hold.it/90" class="col-lg-12 col-md-12 facts-img rounded-circle">
</div>
<div class="d-flex flex-column ">
<h3 class="facts-header col-lg-2 col-md-12">
Licht
</h3>
<p class="facts-p col-lg-8 col-md-12 facts-text">
Das zentrale Element in unserem Leben. Es weckt Emotionen, beeinflusst unser
Wohlbefinden und füllt unsere Energiespeicher auf. Durch das Licht nehmen wir die
unterschiedlichen Farben wahr. Licht schafft Ambiente.
</p>
</div>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Paramjot Singh |
| Solution 3 | |
| Solution 4 | mohit maroliya |
