English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS basic tutorial

CSS box model

CSS3Tutoriales básicos

CSS reference manual

CSS @rule (RULES)

CSS vertical-align (vertical alignment)

CSS vertical-The align vertical alignment attribute is used to define the vertical alignment of embedded or table cell frames. vertical-Align is one of the important features of CSS. It may be difficult for beginners to master at the beginning, and examples are provided at the bottom of the article to help you quickly understand and master this attribute.

What can it do

  1. It applies to inline or inline block elements.

  2. It affects the alignment of the elements without affecting their content. (Except for table cells)

  3. When applied to table cells, it affects the content of the cells, not the cells themselves.

CSS vertical-align vertical alignment value

valuedescription
base lineAlinea la línea base del elemento con la línea base del elemento padre. Este es el valor predeterminado.
longitudSe utiliza para aumentar o disminuir la longitud del elemento según la longitud especificada. También se pueden usar valores negativos.
%Se utiliza para aumentar o disminuir el elemento en porcentajes del atributo 'height' de línea. Permite valores negativos.
subAlinea el elemento, como si fuera un subíndice.
superAlinea el elemento, como si fuera un superíndice.
topAlinea la parte superior del elemento con la parte superior del elemento más alto de la línea.
bottomAlinea la parte inferior del elemento con el elemento más bajo de la línea.
text-topLa parte superior del elemento está alineada con la parte superior de la fuente del elemento padre.
middleEl elemento se coloca en el medio del elemento padre.
text-bottomLa parte inferior del elemento está alineada con la parte inferior de la fuente del elemento padre.
initialEstablece este atributo en su valor predeterminado.
inheritHereda este atributo de su elemento padre.

Ejemplo en línea de alineación vertical de CSS

<!DOCTYPE html>  
<html>  
<head>  
<style>  
img.top {  
    vertical-align: text-top;  
}  
img.bottom {  
    vertical-align: text-bottom;  
}  
</style>  
</head>  
<body>  
<p><img src="/run/images/heart.jpg" alt="patrón de corazón"/> Esta es la imagen con alineación predeterminada.</p>   
<p><img src="/run/images/heart.jpg" style="vertical-align: text-top;" alt="patrón de corazón"/> Esta es la imagen con alineación de texto superior.</p>   
<p><img src="/run/images/heart.jpg" style="vertical-align: text-bottom;" alt="patrón de corazón"/> Esta es la imagen con alineación de texto inferior.</p>  
</body>  
</html>
Prueba y mira‹/›

Salida:

Esta es la imagen con alineación predeterminada.

Esta es la imagen con alineación de texto superior.

Esta es la imagen con alineación de texto inferior.