Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertically align text based on image using bootstrap

I have an image and want a text next to it centered vertically. I can use text-center if its horizontal aligning but I need to align vertically. How can I do that? Is there any way in bootstrap to do this?

  <div class="col-md-12 well">
      <div class="col-md-3">
        <img src="http://placehold.it/100x100"></img>

      </div>
      <div class="col-md-3">
        <div>
        This text should be centered vertically
        </div>
      </div>
    </div>

Here is the codepen

like image 545
Abhilash Avatar asked Feb 07 '23 18:02

Abhilash


2 Answers

How about using flexbox:

.well {
  display: flex;
  align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-12 well">
  <div class="col-md-3">
    <img src="http://placehold.it/100x100"></img>
  </div>
  <div class="col-md-3">
    <div>
      This text should be centered vertically
    </div>
  </div>
</div>
like image 117
Ryan Avatar answered Feb 16 '23 04:02

Ryan


<html><head>    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
<div class="row">
<div class="col-3">
    <img src="https://media.haircutinspiration.com/photos/20181204011855/boy-hairstyle-e1536810585307.jpg" class="img-fluid">
</div>
    <div class="col-3 align-self-center">
        hello hello
    </div>
 
</div>
  </body>
like image 41
Wria Mohammed Avatar answered Feb 16 '23 04:02

Wria Mohammed