I just started to learn Bootstrap and encountered an issue.
How can I centre the content within the ‘div’?
This is my code
<div class="container px-4 py-5" id="hanging-icons">
<h2 class="pb-2 border-bottom">Work Experience</h2>
<div class="container py-5">
<div class="row">
<div class="col-md-3">
<!-- Company Information Column -->
<div class="company-1">
<h3>Graphic Coordinator</h3>
<p>ABC</p>
<img src="#" alt="company logo">
<p>2020-2023</p>
</div>
</div>
<div class="col-md-9">
<!-- Job Description Column -->
<div class="job-description-1">
<ul class="line-spacing">
<li>Crafted engaging graphics for marketing campaigns, elevating brand messaging</li>
<li>Collaborated on design concepts for seamless cross-platform integration.</li>
<li>Produced captivating social media graphics to enhance online presence.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
I’ve tried using CSS to apply the display: flex and justify-content: center and inline-block properties to the <div> element.
But it doesn’t change anything at all…
Hope there is someone who can help me with this question, thank you very very much!
2
Answers
You can shorten the
.row
and center it, for this effect. It would be wise to do that only on desktop width display.The first block in the row has the
col-md-3
class and the second hascol-md-9
. Therefore, both columns are taking up 100% width of the row and centering styles have no effect. You’ll need to reduce the width of the blocks or the row.I changed the width of the blocks by removing the column classes and declaring
width: auto
to override Bootstrap’srow > * {width: 100%}
. Center inline by adding thejustify-content-center
class to the row.I also went ahead and removed the unnecessary nested
div
s and thecontainer
class.