I am struggling to create a bootstrap 4 layout as per my design screenshot. I have researched other Stack Overflow posts without finding a solution.
- The
.container-fluid
layout has a grey fill color, achieved using my custom class.bg-grey
. - As per the design, the body is centered, so I wrapped the columns with the
.container
class. .col-8
has the.bg-white
class and.col-4
has the.bg-dark
class to make them the same height with space in between.- An issue is the extra margin on the right, making the design off-center.
Desired Design
https://i.sstatic.net/U1N41.png
In my attempts to solve the issue, I encountered problems with the following code:
Attempt 1:
I tried different approaches but wasn't successful in fixing the extra margin issue.
- Adding margin to
col-8
pushes.col-4
down due to increased total width. - Assigning
.bg-white
and.bg-dark
to a new child changes the fill color size. - Adding
.h-100
class to the new div didn't resolve the issue.
https://i.sstatic.net/onT2Y.png
<div class="col-sm-8 ">
<div class="content px-4 py-2 bg-white h-100">
<h3 class="heading03">Life at </h3>
<h2 class="heading02">.</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium
quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
</p;
</div>
</div>
<div class="col-sm-4 ">
<div class=" content px-4 py-2 bg-black white-text h-100">
<h5 class="heading05">Latest at </h5>
<h4 class="heading04 text-muted">Top 10 </h4>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa...
</p>
<h5 class="heading05">Latest at </h5>
<h4 class="heading04 text-muted">Top 10 </h4>
<p class="m-0">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa...
</p>
</div>
</div>
Attempt 2: I tried another layout example from Bootstrap's website but faced margin inconsistencies.
https://i.sstatic.net/bBswS.png
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid bg-grey pb-5 ">
<div class="row">
<div class="container">
<!-- second part -->
<div class="row pt-5">
<div class="d-md-flex flex-md-equal w-100 ">
<div class="col-8 bg-white mr-md-3 pt-3 px-3 pt-md-5 px-md-5 overflow-hidden">
<div class="my-3 py-3">
<h3 class="heading03">Life </h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque
eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer
tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
</p;
</div;
</div;
<div class="col-4 bg-dark mr-md-3 pt-3 px-3 pt-md-5 px-md-5 text-white overflow-hidden">
<div class="col-12">
<div class="my-3 p-3">
<h2 class="display-5"> headline</h2>
<p class="lead">subheading.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>