From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- files/es/web/css/_colon_first-child/index.html | 133 +++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 files/es/web/css/_colon_first-child/index.html (limited to 'files/es/web/css/_colon_first-child/index.html') diff --git a/files/es/web/css/_colon_first-child/index.html b/files/es/web/css/_colon_first-child/index.html new file mode 100644 index 0000000000..225aa2ffa5 --- /dev/null +++ b/files/es/web/css/_colon_first-child/index.html @@ -0,0 +1,133 @@ +--- +title: ':first-child' +slug: 'Web/CSS/:first-child' +tags: + - CSS + - Diseño + - Pseudo-clase + - Referencia + - Web +translation_of: 'Web/CSS/:first-child' +--- +
{{CSSRef}}
+ +

La pseudo-clase :first-child de CSS representa el primer elemento entre un grupo de elementos hermanos.

+ +
/* Selecciona cualquier <p> que sea el primer
+   elemento entre sus hermanos */
+p:first-child {
+  color: lime;
+}
+ +
+

Nota: Como se definió originalmente, el elemento seleccionado tenía que tener un padre. Comenzando con el Nivel 4 de Selectores, esto ya no es necesario.

+
+ +

Sintaxis

+ +
{{csssyntax}}
+
+ +

Ejemplos

+ +

Ejemplo básico

+ +

HTML

+ +
<div>
+  <p>¡Este texto está seleccionado!</p>
+  <p>Este texto no está seleccionado.</p>
+</div>
+
+<div>
+  <h2>Este texto no está seleccionado: no es un `p`.</h2>
+  <p>Este texto no está seleccionado.</p>
+</div>
+
+ +

CSS

+ +
p:first-child {
+  color: lime;
+  background-color: black;
+  padding: 5px;
+}
+
+ +

Resultado

+ +

{{EmbedLiveSample('Ejemplo_básico', 500, 200)}}

+ +

Diseñando una lista

+ +

HTML

+ +
<ul>
+  <li>Objeto 1</li>
+  <li>Objeto 2</li>
+  <li>Objeto 3
+    <ul>
+      <li>Objeto 3.1</li>
+      <li>Objeto 3.2</li>
+      <li>Objeto 3.3</li>
+    </ul>
+  </li>
+</ul>
+ +

CSS

+ +
ul li {
+  color: blue;
+}
+
+ul li:first-child {
+  color: red;
+  font-weight: bold;
+}
+ +

Resultado

+ +

{{EmbedLiveSample('Diseñando_una_lista')}}

+ +

Especificaciones

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
EspecificaciónEstadoComentarios
{{SpecName('CSS4 Selectors', '#first-child-pseudo', ':first-child')}}{{Spec2('CSS4 Selectors')}}Los elementos coincidentes no requieren tener un padre.
{{SpecName('CSS3 Selectors', '#first-child-pseudo', ':first-child')}}{{Spec2('CSS3 Selectors')}}Ningún cambio.
{{SpecName('CSS2.1', 'selector.html#first-child', ':first-child')}}{{Spec2('CSS2.1')}}Definición Inicial.
+ +

Compatibilidad con navegadores

+ +
+ + +

{{Compat("css.selectors.first-child")}}

+
+ +

Ver también

+ + -- cgit v1.2.3-54-g00ecf