Open main menu

CDOT Wiki β

CSS GUIDE VERTICAL ALIGN

Revision as of 13:59, 6 December 2006 by Elichak (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This document is a work in progress and is subject to change.

Summary

The vertical-align property affects the vertical inside a line box of the boxes generated by an inline-level element. The following values only affect a parent inline-level element, or to a parent block-level element. If that element generates anonymous inline boxes (refer to this), they have no effect if no such parent exists.

Vertical-align attribute only considers the alignment within the current line, not within the containing box.

Applicability:The vertical-align property can be used for all CSS elements.
Media Group: Visual
Inherited:No

Syntax

Vertical aligning
element
  • Mozilla cannot do vertical-align for a
    element.
  • The only way to get mozilla to put something in the middle of a containing box vertically is to use a table cell or set the padding top and bottom to be equal or to make the line-height equal to the height of the containing box and then use vertical-align: middle (this last way required the content to be only a single line).
  • The reason for this is that the vertical-align attribute only considers the alignment within the current line, not within the containing box.
  • Vertical aligning images

    • Mozilla aligns images differently then old browsers, in order to be in compliance with the W3C specifications. When placing an image inside of a box, padding appears below the image. The gap you're seeing is space that's reserved for the descenders in text.
    • Mozilla places images on the baseline, so the descender space is visible as a few-pixel gap underneath the image.
    • Mozilla recommends that you use this CSS rule:
    img { vertical-align: text-bottom; }
    

    General usage

    
    

    Legal Values

    The following units are valid for defining vertical-align:

    • baseline
    • sub
    • super
    • top
    • text-top
    • middle
    • bottom
    • text-bottom
    • length
    • %

    See usage examples section for more details.

    Mozilla Recommended Values

    Usage Examples

    img{vertical-align:baseline}  	/*The element is placed on the baseline of the parent element*/
    img{vertical-align:sub} 	/*Aligns the element as it was subscript*/
    img{vertical-align:super}	/*Aligns the element as it was superscript*/
    img{vertical-align:top} 	/*The top of the element is aligned with the top of the tallest element on the line*/
    img{vertical-align:text-top} 	/*The top of the element is aligned with the top of the parent element's font*/
    img{vertical-align:middle} 	/*The element is placed in the middle of the parent element*/
    img{vertical-align:bottom} 	/*The bottom of the element is aligned with the lowest element on the line*/
    img{vertical-align:text-bottom} 	/*The bottom of the element is aligned with the bottom of the parent element's font*/
    img{vertical-align:length} 	
    img{vertical-align:% }	/*Aligns the element in a % value of the "line-height" property. Negative values are allowed*/


    Notes

    The World Wide Web Consortium (W3C) provides a free online CSS validation service.

    Specification Conformance

    Browser Compatibility

    • Internet Explorer
    • Firefox
    • Opera

    See Also