Alignment in a table cell HTML CENTER

Due to the fact that the content of table cells can be simultaneously aligned to the
horizontal and vertical directions, expanding possibilities for the management position of the elements
relative to each other. Tables allow you to set the alignment of the images,
text, form fields, and other elements relative to each other, and web pages
in general. Generally, alignment basically necessary to install a visual
connection between the various elements and their grouping.

Centering vertically

One way to show the visitor orientation and the name of the site is
the use of splash pages. This is the first page, on which, as a rule,
is flash-saver or a picture that expresses the main idea of the site. The image
is also a reference to the other sections of the site. It takes place this
figure at the center of the browser window, regardless of screen resolution. For
this purpose one can use the table with the width and height of 100% (Example 1).

Example 1. Centering pattern

alt="Рецепты HTML">

In this example, the horizontal alignment is established using the parameter
align = »center» tag ,
and the vertical cell contents can not be centered because this position
is the default.

The height of the table was set to be 100%, it is necessary to remove the , the code at the same time cease to be valid.

Using the width and height of the entire available area of the webpage ensures
that the contents of the table will be aligned exactly in the center of the browser window, regardless
of its size.

Horizontal Alignment

By combining the attributes of the align (horizontal
alignment) and valign (vertical alignment)
tag , allowed to establish multiple
types of positions relative to one another. Fig. 1 shows how to
align the elements horizontally.

Fig.  1. Align elements Horizontal

Fig. 1. Align elements Horizontal

Consider some examples of the alignment of the text according to given pattern.


Align Top

To specify the alignment of cell contents along the top edge, the tag
you want to set the attribute valign with a value of
top (Example 2).

Example 2. Using valign

Колонка 1 Колонка 2

In this example, the characteristics of the cells are controlled by the parameters of the tag
, but also easier to edit through the styles.
In particular, alignment in the cells indicated properties vertical-align
and text-align (Example 3).

Example 3. Application of styles for alignment

Колонка 1 Колонка 2

To shorten the code used in this example grouping selectors
because the properties vertical-align and padding
are applied simultaneously to the two cells.

Align Bottom is similar, but instead of the top
used bottom .


By default, the contents of the cell is aligned with the center of the vertical, so
in the case of different height columns is required to set the alignment of the top edge.
Sometimes still need to leave the original alignment method, for example, when placing
the formulas, as shown in Fig. 2.

Fig.  2. Addition of formula document

Fig. 2. Addition of formula document

In this case, the formula is strictly on the center of the browser window, and its
number - to the right. For this you will need to deploy elements of
a table with three cells. The last cell should be the same size, in
the middle cell alignment is done in the center and on the right - on the right
edge (Example 4). This number of cells is required in order to ensure
the positioning of the formula in the middle.


Example 4. Alignment of formula

alt="Формула 18.6"> (18.6)

In this example, the first table cell is left blank, it only serves to
create the indentation, which, incidentally, can be installed and via styles.

Alignment members form

The tables conveniently determine the position of the form fields, especially when they
are interspersed with the text. One of the variants of registration form, which is designed
to enter a comment is shown in Fig. 3.

Figure 3. Location of the form fields and text

Figure 3. Location of the form fields and text

To make the text near the fields of the form is aligned to the right, and the elements themselves
form - on the left, will require a table with an invisible border and two
columns. The left column will place their own text in the right text
field (example 5).

EXAMPLE 5 Alignment fields form


In this example, for the cell where you want to set the alignment of the right
edge of the added attribute of the align = »right» .
To the words "Note" located at the upper end of multiline
text to the corresponding cell is set by the alignment of the top
edge with the attribute valign .


Internet Explorer Chrome Opera Safari Firefox Android iOS
6.0+ 8.0+ 1.0+ 3.5+ 1.0+ 1.0+ 1.0+ 1.0+

brief information

default value baseline
inherited Not
applicable By the built-in elements, or table cells.
Link to specification
Read more:   AS WITH WINDOWS 8 enter the BIOS

CSS version

CSS 1 CSS 2 CSS 2.1 CSS 3


It aligns the element vertically relative to its parent, the surrounding
text or table cell.


vertical-align: baseline | bottom | middle | sub | super | text-bottom | text-top | top | inherit | value | interest


Aligns the baseline current element at the base of the parent line. If
the parent element has no baseline, then it is taken for the lower
boundary of the cell.
Aligns base current element at the lower part of the string member
is located below all.
Aligning element point average baseline parent plus half
the height of its parent.
The element is indicated as a subscript, as a subscript. The font size
is not changed.
The element is indicated as a superscript, as a superscript. Font size
remains the same.
The lower boundary of the element is aligned on the bottom edge of the current line.
The upper limit of the element is aligned on the highest text element
of the current line.
Alignment of the upper edge of the top element the highest line element.
Inherits the parent's value.

The value can also be used percentages, pixels, or other available
units. Positive numbers element displaces upwardly relative to the base line,
whereas a negative number lowers it down. When using percent, counting from the property value line-height , while similar to the value 0% baseline .

For vertical alignment in table cells following values ​​apply.

Aligns baseline cell with the baseline of the first text string or another sub-element.
Aligns the bottom edge of the cell.
Aligns the middle of the cell.
Aligns the contents of the top edge of the cell.



TEX и L style="vertical-align: 5px; font-size: 0.8em">AT style="vertical-align: sub">EX

The result of this example is shown in Fig. one.

Application properties vertical-align

Fig. 1. The use of vertical-align properties

object model



Internet Explorer up to and including version 7.0 does not support the value of the inherit .

Read in other languages

 BelorussianEnglish Deutsch Spanish French Italian Portuguese Turkish Arab Ukrainian Swedish Hungarian Bulgarian Estonian Chinese (Simplified) Vietnamese Romanian Thai Slovenian Slovak Serbian Malay Norwegian Latvian Lithuanian Korean Japanese Indonesian Hindi Hebrew Finnish Greek Dutch Czech Danish Croatian Chinese (Traditional) Philippine Urdu Azeybardzhansky ArmenianPolish Bengal Georgian Kazakh Catalan Mongolski Russian Tadzhitsky Tamilʹskij telugu Uzbetsky

Add a comment

Your e-mail will not be published. Required fields are marked *