Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline-block not vertically aligning div-elements correctly

I've got a problem with Chrome.

I'm trying to vertically-align some divelements using display: inline-block; instead of floating them. The problem occurs when I put some text into them: for a strange reason, Chrome displays differently filled divs onto different lines.

Firefox and IE are working correctly. For better understanding check this example

How can I avoid this?

like image 503
Alex van Avatar asked Apr 18 '13 08:04

Alex van


People also ask

How do I vertically align a div content?

To center a div vertically on a page, you can use the CSS position property, top property, and transform property. Start by setting the position of the div to absolute so that it's taken out of the normal document flow. Then set the top property to 50%.

How do I vertically align two divs?

To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.

How do you center a block element vertically?

When the element to be centered is an inline element we use text-align center on its parent. When the element is a block level element we give it a width and set the left and right margins to a value of auto. With text-align: center in mind, most people look first to vertical-align in order to center things vertically.


1 Answers

You need to add for global wrapper font-size: 0; and set regular font size for your inline blocks, you can also add: letter-spacing: 0; and word-spacing: 0;, something like this:

.wrapper {
  font-size: 0;
  letter-spacing: 0;
  word-spacing: 0;
}

  .wrapper .inline_block {
    display: inline-block;
    font-size: 12px;
    letter-spacing: 1px;
    word-spacing: .1em;
    vertical-align: top;
  }

and example fiddle: http://jsfiddle.net/3ab22/ and updated fiddle: http://jsfiddle.net/3ab22/3/

like image 88
Lukas Avatar answered Sep 28 '22 14:09

Lukas