Center content in bulma column
Asked Answered
S

3

14

I have multiple columns. Each column contains a circle in the CSS within a font awesome icon centered in it. Now I wanna make align the circle itself in the middle of the column. However, it keeps staying on the left while the text itself gets centered.

HTML

<div class="features">
  <div class="container">
    <div class="columns is-mobile ">
      <div class="column">
        <div class="community">
          <font-awesome-icon col size="2x" :icon="['fas', 'tasks']" />
        </div>
        Features
      </div>
    </div>
  </div>
</div>

CSS

.features {
  background: #2a3a4c;
  height: 200px;
}

.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}
Schedule answered 17/5, 2018 at 18:54 Comment(1)
Did you forgot to add css code for drawing a circle? Try removing text-align and add margin:0 auto; for the .community css or do it for .column if still not centered..Berezina
T
29

<div class="columns is-centered">...</div> centeres the column. You have to set a width for the column inside to make it work. The class is-narrow takes only the space it needs.

Example

.features {
  background: #2a3a4c;
}

.features .columns {
  height: 200px;
}

.circle {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css" rel="stylesheet" />
<div class="features">
  <div class="container">
    <div class="columns is-centered is-vcentered is-mobile">
      <div class="column is-narrow has-text-centered">
        <div class="circle">
          <font-awesome-icon col size="2x" :icon="['fas', 'tasks']" />
        </div>
        Features
      </div>
    </div>
  </div>
</div>

More information: Bulma columns sizes

Tardy answered 17/5, 2018 at 19:45 Comment(0)
F
7

This will make your text, buttons or images centred

Add to the HTML content:

class="has-text-centered"

And if you want file upload input centred

Add to the HTML content:

class="is-centered"
Farmyard answered 13/8, 2020 at 16:49 Comment(1)
It would be nice if you edited your answer to show some more effort (small explanation, specify where to put it, etc.). Also see How to AnswerStrade
P
0

Do you need to use table-cell for .community? It didn't appear to be doing anything. If not you can change

.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}

to

.community {
  width: 5rem;
  height: 5rem;
  background: linear-gradient(135deg, #b15757 0%, #b96868 100%);
  border-radius: 100%;
  text-align: center;
  margin: 0 auto;
}

and add

.column {
  text-align: center;
}

That will make everything centered.

You can see the working example at https://codepen.io/anon/pen/odQGoj

PS you're missing a closing </div> for <div class="features">

Porpoise answered 17/5, 2018 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.