Propiedad de posición CSS
Ejemplo
Coloque un elemento <h2>:
h2
{
position: absolute;
left: 100px;
top: 150px;
}
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La position
propiedad especifica el tipo de método de posicionamiento utilizado para un elemento (estático, relativo, absoluto, fijo o fijo).
Valor por defecto: | estático |
---|---|
Heredado: | No |
Animable: | No. Leer sobre animable |
Versión: | CSS2 |
Sintaxis de JavaScript: | objeto .style.position="absoluto" |
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
position | 1.0 | 7.0 | 1.0 | 1.0 | 4.0 |
Nota: el sticky
valor no es compatible con Internet Explorer o Edge 15 y versiones anteriores.
Sintaxis CSS
position: static|absolute|fixed|relative|sticky|initial|inherit;
Valores de propiedad
Value | Description | Play it |
---|---|---|
static | Default value. Elements render in order, as they appear in the document flow | |
absolute | The element is positioned relative to its first positioned (not static) ancestor element | |
fixed | The element is positioned relative to the browser window | |
relative | The element is positioned relative to its normal position, so "left:20px" adds 20 pixels to the element's LEFT position | |
sticky | The element is positioned based on the user's scroll position
A sticky element toggles between |
|
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Más ejemplos
Ejemplo
Cómo colocar un elemento en relación con su posición normal:
h2.pos_left {
position: relative;
left: -20px;
}
h2.pos_right {
position: relative;
left: 20px;
}
Ejemplo
Más posicionamiento:
#parent1 {
position: static;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child1 {
position:
absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
#parent2 {
position: relative;
border: 1px solid blue;
width: 300px;
height: 100px;
}
#child2 {
position: absolute;
border: 1px solid red;
top: 70px;
right: 15px;
}
páginas relacionadas
Tutorial CSS: Posicionamiento CSS
Referencia HTML DOM: propiedad de posición