Vertically centering text inside flexbox item

ilyo

I want the flex items to take full height, but the content inside them to be vertically centred.

justify-content: centre doesn't work, and align-self: centre on the item itself shrinks its height to its own content, while I want all items to be the same height.

In this example I want the numbers to be vertically centred: http://codepen.io/ilyador/pen/ogYbWO?editors=110

.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;
  display: flex;  
}

.flex-item {
  flex: 1 1;
  background: tomato;
  padding: 5px;
  margin-top: 10px;
  color: white;
  font-weight: bold;
  font-size: 3em;
  text-align: center;
  border: solid 1px red;
}
<ul class="flex-container">
  <li class="flex-item">1fbdms s s sdj dfkg kjfg dkfj gdfjkgdfkj gdfkjg dfkjgdkhdfjk gkjdfkjdfgdfg jkdfgdfjkgk </li>
  <li class="flex-item">2</li>
  <li class="flex-item">3</li>
  <li class="flex-item">4</li>
  <li class="flex-item">5</li>
  <li class="flex-item">6</li>
</ul>

paceaux

I was able to accomplish vertical centering of your numbers with this:

.flex-item {
  display:flex;
  flex-direction:column;
  justify-content:space-around;
}

If you want something to be vertically centered, set the container to display:flex and then use justify-content to accomplish it. With justify-content you could either set it to space-around or to center. Either will accomplish your goal.

http://codepen.io/anon/pen/RNoajg

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Vertically centering single item in flexbox column

From Dev

Centering text vertically and horizontally in a flex item

From Dev

Vertically centering a piece of text inside a div

From Dev

Centering text vertically, inside inline-block

From Dev

Vertically centering a piece of text inside a div

From Dev

Centering text inside rounded rectangle vertically and horizontally

From Dev

Flexbox not centering content vertically

From Dev

Vertically centering with flexbox

From Dev

Centering Elements Vertically with FlexBox

From Dev

Flexbox not centering content vertically

From Dev

Centering an image vertically inside an anchor tag in a flex item

From Dev

Vertically centering overflowed text

From Dev

Vertically centering text in a div

From Dev

text centering on CSS with flexbox

From Dev

Vertically centering inside a div with vh

From Dev

Centering Vertically an UL inside a DIV

From Dev

Vertically Centering Text In A CSS Div

From Dev

Centering text vertically in Bootstrap list

From Dev

Centering text (horizontally and vertically) in nav

From Dev

Centering text (horizontally and vertically) in nav

From Dev

Vertically centering text in a responsive manner

From Dev

centering text inside a div

From Dev

Centering text inside of an element

From Dev

Centering text inside of an element

From Dev

centering text positioning using flexbox

From Dev

Vertically centering a flex item works in Chrome but not Firefox

From Dev

How do I vertically centering text inside a responsive box that has a (fluid height)

From Dev

Vertically align a stretched flexbox item

From Dev

Vertically centering Font Awesome icon inside nav

Related Related

HotTag

Archive