{"id":1292,"date":"2024-08-01T18:33:08","date_gmt":"2024-08-01T16:33:08","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=1292"},"modified":"2024-08-01T18:33:08","modified_gmt":"2024-08-01T16:33:08","slug":"33-la-propiedad-z-index","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/css3\/css3-basico\/33-la-propiedad-z-index\/","title":{"rendered":"33. La propiedad z-index"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Cuando los elementos son posicionados, pueden superponerse con otros elementos. La propiedad <strong><em>z-index<\/em><\/strong> especifica el orden de pila de un elemento (qu\u00e9 elemento debe colocarse delante o detr\u00e1s de los dem\u00e1s). Un elemento puede tener un orden de pila positivo o negativo.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html><br>&lt;html><br>  &lt;head><br>    &lt;style><br>      img {<br>        position: absolute;<br>        left: 0px;<br>        top: 0px;<br>        z-index: -1;<br>      }<br>    &lt;\/style><br>  &lt;\/head><br>  &lt;body><br>    &lt;h1>This is a heading&lt;\/h1><br>    &lt;img src=\"img_tree.png\" \/><br>    &lt;p>Como la imagen tiene un z-index:-1; se pondr\u00e1 detr\u00e1s del texto&lt;\/p><br>  &lt;\/body><br>&lt;\/html><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Nota<\/strong>: <strong><em>z-index<\/em><\/strong> solo funciona en elementos posicionados (position: absolute, position: relative, position: fixed o position: sticky) y elementos flexibles (elementos que son hijos directos de visualizaci\u00f3n: elementos flexibles).<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html><br>&lt;html><br>  &lt;head><br>    &lt;style><br>      .container {<br>        position: relative;<br>      }<br><br>      .black-box {<br>        position: relative;<br>        z-index: 1;<br>        border: 2px solid black;<br>        height: 100px;<br>        margin: 30px;<br>      }<br><br>      .gray-box {<br>        position: absolute;<br>        z-index: 3; \/* gray box will be above both green and black box *\/<br>        background: lightgray;<br>        height: 60px;<br>        width: 70%;<br>        left: 50px;<br>        top: 50px;<br>      }<br><br>      .green-box {<br>        position: absolute;<br>        z-index: 2; \/* green box will be above black box *\/<br>        background: lightgreen;<br>        width: 35%;<br>        left: 270px;<br>        top: -15px;<br>        height: 100px;<br>      }<br>    &lt;\/style><br>  &lt;\/head><br>  &lt;body><br>    &lt;h1>Z-index Example&lt;\/h1><br><br>    &lt;p><br>      An element with greater stack order is always above an element with a<br>      lower stack order.<br>    &lt;\/p><br><br>    &lt;div class=\"container\"><br>      &lt;div class=\"black-box\">Black box (z-index: 1)&lt;\/div><br>      &lt;div class=\"gray-box\">Gray box (z-index: 3)&lt;\/div><br>      &lt;div class=\"green-box\">Green box (z-index: 2)&lt;\/div><br>    &lt;\/div><br>  &lt;\/body><br>&lt;\/html><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Sin z-index<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Si dos elementos posicionados se superponen sin especificar un <strong><em>z-index<\/em><\/strong>, el \u00faltimo elemento definido en el c\u00f3digo HTML se mostrar\u00e1 en la parte superior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cuando los elementos son posicionados, pueden superponerse con otros elementos. La propiedad z-index especifica el orden de pila de un [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":563,"menu_order":32,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-1292","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Sutil Web","author_link":"https:\/\/sutilweb.eu\/index.php\/author\/sutilweb\/"},"uagb_comment_info":0,"uagb_excerpt":"Cuando los elementos son posicionados, pueden superponerse con otros elementos. La propiedad z-index especifica el orden de pila de un [&hellip;]","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/comments?post=1292"}],"version-history":[{"count":3,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1292\/revisions"}],"predecessor-version":[{"id":1295,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1292\/revisions\/1295"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/563"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=1292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}