Monday 11 March 2013

CSS : Create horizontally / vertically aligned elements without a table



A label is actually a -by default- inline HTML element, therefore no standardized width can be applied​ to it. Eventually this means that developers end up with elements that basically look vertically unaligned.

The solution is to add the following CSS rule on your stylesheet:

label
{
    vertical-align: central;
    display: inline-block;
    width: auto;
    min-width:90px;
    text-align: left;
}

thus, a static width can be defined and the vertical alignment can finally be fixed. I hope this helps someone.

No comments:

Post a Comment