Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Vertically center text using box-align on inline-block element

Vertically center text using box-align on inline-block element

Problem

I'm trying to center text vertically in an inline-block Element (and particularly in webkit browsers). Pretty much exactly what the

I've tried using box-align, as in this question Vertical align text in block element but I don't want to set an explicit width on the element: I want it to fit to its contents, i.e. I want display: inline-block type behavior.

In Firefox, -moz-box appears to behave the way I want, but in Safari and Chrome, -webkit-box makes the div want to fill its container horizontally.

[oops, can't post image as I'm a noob]

Fiddle here with examples of various settings.

Looking at webkit's inspector on an actual

It seems that by adding an extra

into the mix, I can get the behavior I want, but I'd really rather not do that. I'm also aware of the display: table-cell technique for vertical centering; this is not appropriate here as it has other side-effects.

So is webkit's behavior correct? How does the

Solution

use line-height property of css. make it equal to the height of the box containing text.

http://www.w3schools.com/cssref/pr_dim_line-height.asp

Solution courtesy of: Tejasva Dhyani

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Vertically center text using box-align on inline-block element

Email
Facebook
Twitter
×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×