Issue
I am having a problem to center vertically a responsive image inside its container.
I have tried a few things but those are works on fixed size, not in responsive.
I am using Bootstrap 4.
Below my code and an attempt with line-height
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-7 img-container" style="line-height:100%">
<img src="sample.jpg" alt="Sample" class="img-fluid">
</div>
<div class="col-md-5">
<h3>Title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore aperiam, sit placeat corporis architecto praesentium facere aut rem quis odio ab voluptates sunt, eum harum ipsam, fugit numquam aliquid laboriosam.</p>
<h3>Title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore aperiam, sit placeat corporis architecto praesentium facere aut rem quis odio ab voluptates sunt, eum harum ipsam, fugit numquam aliquid laboriosam.</p>
<h3>Title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore aperiam, sit placeat corporis architecto praesentium facere aut rem quis odio ab voluptates sunt, eum harum ipsam, fugit numquam aliquid laboriosam.</p>
</div>
</div>
</div>
Solution
Since you're using Bootstrap, you can add d-flex align-items-center
to your col-md-7
div. This will force the column to use CSS flex box for layout, and align-items-center tells the content to vertically positioned.
Answered By - Graham Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.