Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 Center element using Flexbox

Using Bootstrap 4 Alpha 6. I have the following markup:

<header class="jumbotron jumbotron-fluid">
  <div class="container">
    <div class="row justify-content-center flex-column-reverse flex-sm-row">
      <div class="col-12 col-sm-6">
        <h1 class="display-4">
          <a class="border-0" href="/@v">Vic</a>
        </h1>
          <p class="lead mb-100">We utilize a default z-index scale in Bootstrap that’s been designed to properly layer navigation, tooltips and popovers, modals, and more.</p>
          <p>
              <svg>...</svg>Boston, MA, US<br>
          </p>
      </div>
      <div class="col-12 col-sm-2">
        <a class="border-0" href="/@v">
          <img class="d-flex rounded-circle avatar--m" alt="Random Name" src="/system/profiles/avatars/000/000/001/avatar_m/firefox-copy-link.jpg?1489589655">
</a>      </div>
    </div>
  </div>
</header>

which produces the following result on mobile and desktop respectively:

Mobile

enter image description here

Desktop

enter image description here

The desktop version currently looks perfect. How do I center the image on mobile only?

like image 746
Victor Avatar asked Mar 02 '26 22:03

Victor


1 Answers

You can use the Bootstrap 4 responsive margin utils on the image. Use mx-auto to center, and then mx-sm-0 to keep normal margins on sm an up.

<img class="d-flex rounded-circle mx-auto mx-sm-0" src="//placehold.it/80">

Demo: http://www.codeply.com/go/qDSHKeueac

like image 160
Zim Avatar answered Mar 05 '26 12:03

Zim