{"id":143,"date":"2024-05-21T08:57:45","date_gmt":"2024-05-21T06:57:45","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=143"},"modified":"2024-05-21T08:57:45","modified_gmt":"2024-05-21T06:57:45","slug":"21-el-elemento-picture","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/html5\/html5-manual\/21-el-elemento-picture\/","title":{"rendered":"21. El elemento picture"},"content":{"rendered":"\n<p>El elemento <strong>HTML <em>&lt;picture&gt;<\/em><\/strong> permite mostrar diferentes im\u00e1genes para diferentes dispositivos o tama\u00f1os de pantalla. El elemento HTML <strong><em>&lt;picture&gt;<\/em><\/strong> brinda a los desarrolladores web m\u00e1s flexibilidad para especificar recursos de im\u00e1genes.<\/p>\n\n\n\n<p>El elemento <strong><em>&lt;picture&gt;<\/em><\/strong> contiene uno o m\u00e1s elementos <strong><em>&lt;source&gt;<\/em><\/strong>, cada uno de los cuales se refiere a diferentes im\u00e1genes a trav\u00e9s del atributo <strong><em>srcset<\/em><\/strong>. De esta manera, el navegador puede elegir la imagen que mejor se adapte a la vista y\/o dispositivo actual.<\/p>\n\n\n\n<p>Cada elemento <strong><em>&lt;source&gt;<\/em><\/strong> tiene un atributo <strong><em>media<\/em><\/strong> que define cu\u00e1ndo la imagen es la m\u00e1s adecuada.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<p>Muestra diferentes im\u00e1genes para diferentes pantallas<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;picture&gt;\n&nbsp;&nbsp;&lt;source&nbsp;media=\"(min-width: 650px)\"&nbsp;srcset=\"img_food.jpg\"&gt;\n&nbsp;&nbsp;&lt;source&nbsp;media=\"(min-width: 465px)\"&nbsp;srcset=\"img_car.jpg\"&gt;\n&nbsp;&nbsp;&lt;img&nbsp;src=\"img_girl.jpg\"&gt;\n&lt;\/picture&gt;<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Nota<\/strong>: Siempre especifica un elemento <strong><em>&lt;img&gt;<\/em><\/strong> como el \u00faltimo elemento secundario del elemento <strong><em>&lt;picture&gt;<\/em><\/strong>. El elemento <strong><em>&lt;img&gt;<\/em><\/strong> lo utilizan los navegadores que no admiten el elemento <strong><em>&lt;picture&gt;<\/em><\/strong>, o si ninguna de las etiquetas <strong><em>&lt;source&gt;<\/em><\/strong> coincide.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Cuando se usa el elemento &lt;picture&gt;<\/h2>\n\n\n\n<p>Hay dos prop\u00f3sitos principales para el elemento <strong><em>&lt;picture&gt;<\/em><\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Si tienes una pantalla o dispositivo peque\u00f1o, no es necesario cargar un archivo de imagen grande. El navegador utilizar\u00e1 el primer elemento <strong><em>&lt;source><\/em><\/strong> con valores de atributo coincidentes e ignorar\u00e1 cualquiera de los siguientes elementos.<\/li>\n\n\n\n<li>Es posible que algunos navegadores o dispositivos no admitan todos los formatos de imagen. Al usar el elemento <strong><em>&lt;picture><\/em><\/strong>, puedes agregar im\u00e1genes de todos los formatos, y el navegador usar\u00e1 el primer formato que reconozca e ignorar\u00e1 cualquiera de los siguientes elementos.<\/li>\n<\/ul>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;picture&gt;\n&nbsp;&nbsp;&lt;source&nbsp;srcset=\"img_avatar.png\"&gt;\n&nbsp;&nbsp;&lt;source&nbsp;srcset=\"img_girl.jpg\"&gt;\n&nbsp;&nbsp;&lt;img&nbsp;src=\"img_beatles.gif\"&nbsp;alt=\"Beatles\"&nbsp;style=\"width:auto;\"&gt;\n&lt;\/picture&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>El elemento HTML &lt;picture&gt; permite mostrar diferentes im\u00e1genes para diferentes dispositivos o tama\u00f1os de pantalla. El elemento HTML &lt;picture&gt; brinda [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":41,"menu_order":20,"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-143","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":"El elemento HTML &lt;picture&gt; permite mostrar diferentes im\u00e1genes para diferentes dispositivos o tama\u00f1os de pantalla. El elemento HTML &lt;picture&gt; brinda [&hellip;]","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/143","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=143"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/143\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/143\/revisions\/145"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/41"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}