The CSS reference
"vertical-align" - css property (v. css 1)
- Indicates the vertical alignment of an element
- Initial value: baseline
- The property is not inherited
- HTML usage: inline-level and 'table-cell' elements
-
Browsers that support the vertical-align - property :
Possible vertical-align values:
value | Comments | CSS |
---|---|---|
baseline | Align the baseline of the box with the baseline of the parent box. If the box does not have a baseline, align the bottom margin edge with the parent's baseline. | 1 |
middle | Align the vertical midpoint of the box with the baseline of the parent box plus half the x-height of the parent. | 1 |
sub | Lower the baseline of the box to the proper position for subscripts of the parent's box. (This value has no effect on the font size of the element's text.) | 1 |
super | Raise the baseline of the box to the proper position for superscripts of the parent's box. (This value has no effect on the font size of the element's text.) | 1 |
text-top | Align the top of the box with the top of the parent's content area. | 1 |
text-bottom | Align the bottom of the box with the bottom of the parent's content area. | 1 |
top | Align the top of the aligned subtree with the top of the line box. Allways relative to the line box. | 1 |
bottom | Align the bottom of the aligned subtree with the bottom of the line box. Allways relative to the line box. | 1 |
percentage | Raise (positive value) or lower (negative value) the box by this distance (a percentage of the 'line-height' value). The value '0%' means the same as 'baseline'. | 1 |
length | Raise (positive value) or lower (negative value) the box by this distance. The value '0cm' means the same as 'baseline'. With this you specify a positive(+) or negative(-) value followed with a unit identifier. | 2 |
inherit | Will inherit the value from parent specification. | 2 |
Possible unit identifier:
unit identifier | Comments | CSS |
---|---|---|
em | The relative unit 'em' is relative to the font size of the element itself. | 1 |
ex | The relative unit 'ex' is relative to the font size of the element itself. | 1 |
px | Pixels, relative to the viewing device | 1 |
in | inches -> 1 inch is equal to 2.54 centimeters. | 1 |
cm | centimeters. | 1 |
mm | millimeters. | 1 |
pt | points -> the points used by CSS2 are equal to 1/72th of an inch. | 1 |
pc | picas -> 1 pica is equal to 12 points. | 1 |
Property "vertical-align" example:
<!DOCTYPE HTML >
<html >
<head>
<title>Test</title>
<style type="text/css">
div {border: blue 1px solid; color:black;
padding: .5em .5em .5em .5em; width: 400px;
}
.middle { vertical-align: middle; }
.length { vertical-align: 0.5em; } /* length */
.percentage { vertical-align: 10%; } /* percentage */
</style>
</head>
<body>
<br>vertical-align: 0.5em; /* length */ <br>
<div >
<img class="length" src="images/Trophy.png"
alt="Trophy"
width="30" height="30"/>
Raise (positive value) or
lower (negative value) the box by this distance.
The value '0cm' means the same as 'baseline'.
</div>
<br>vertical-align: 10%; /* percentage */ <br>
<div >
<img class="percentage" src="images/Trophy.png"
alt="Trophy"
width="30" height="30"/>
Raise (positive value)
or lower (negative value) the box by this
distance (a percentage of the 'line-height' value).
The value '0%' means the same as 'baseline'.
</div>
<br>vertical-align: middle;<br>
<div >
<img class="middle" src="images/Trophy.png"
alt="Trophy"
width="30" height="30"/>
Align the vertical midpoint of
the box with the baseline of the parent box
plus half the x-height of the parent.
</div>
</body>
</html>
Javascript access:
// To SET values ([o] is the target object)
[o].style.textAlign="text-align value"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.textAlign;
/* Don not expect that alle browsers
returns the right initial value when a
text-align values is NOT set.*/
/* The returned value is not cross-browser reliable.
The value can vary in accuracy and notation,
which depends on the browser, whether the value is preset or not
and which option that was used to set the value.*/
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.