Search code examples
bulma

Center image in Bulma


Is there a way to horizontally centered an image inside a card?

I have the following

  <div class='column is-one-quarter has-text-centered'>
    <div class='card equal-height'>
      <div class='card-content'>
        <figure class='image is-64x64'><img src='...'></figure>
      </div>
    </div>
  </div>

and I cannot center the image. I have tried to add is-centered both to the figure and to the parent div but nothing changes.

Thanks.


Solution

  • Change the display property of card-content to flex by using the .is-flex modifier.

    Now you can use flexbox properties to horizontally center the figure. There is no modifying class for this with Bulma, so you can make your own...

    .is-horizontal-center {
      justify-content: center;
    }
    

    Add this to card-content and you're done.

    .is-horizontal-center {
      justify-content: center;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css" rel="stylesheet"/>
    <div class='column is-one-quarter'>
      <div class='card equal-height'>
        <div class='card-content is-flex is-horizontal-center'>
          <figure class='image is-64x64'><img src='https://unsplash.it/64'></figure>
        </div>
      </div>
    </div>