{"id":140,"date":"2024-05-21T08:55:56","date_gmt":"2024-05-21T06:55:56","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=140"},"modified":"2024-05-21T08:55:56","modified_gmt":"2024-05-21T06:55:56","slug":"20-imagenes-de-fondo","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/html5\/html5-manual\/20-imagenes-de-fondo\/","title":{"rendered":"20. Im\u00e1genes de fondo"},"content":{"rendered":"\n<p>Se puede especificar una imagen de fondo para casi cualquier elemento <strong>HTML<\/strong>. Para agregar una imagen de fondo en un elemento <strong>HTML<\/strong>, usa el atributo <strong>HTML <em>style<\/em><\/strong> y la propiedad de <strong><em>background-image<\/em><\/strong> de <strong>CSS<\/strong>.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;p&nbsp;style=\"background-image: url('img_girl.jpg');\"&gt;<\/pre>\n\n\n\n<p>Tambi\u00e9n puedes especificar la imagen de fondo en el elemento <strong><em>&lt;style&gt;<\/em><\/strong>, en la secci\u00f3n <strong><em>&lt;head&gt;<\/em><\/strong>.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;style&gt;\np&nbsp;{\n&nbsp; background-image:&nbsp;url('img_girl.jpg');\n}\n&lt;\/style&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Imagen de fondo en una p\u00e1gina<\/h2>\n\n\n\n<p>Si deseas que toda la p\u00e1gina tenga una imagen de fondo, debes especificar la imagen de fondo en el elemento <strong><em>&lt;body&gt;<\/em><\/strong>.<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;style&gt;\nbody&nbsp;{\n&nbsp; background-image:&nbsp;url('img_girl.jpg');\n}\n&lt;\/style&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Background repeat<\/h2>\n\n\n\n<p>Si la imagen de fondo es m\u00e1s peque\u00f1a que el elemento, la imagen se repetir\u00e1, horizontal y verticalmente, hasta llegar al final del elemento:<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;style&gt;\nbody&nbsp;{\n&nbsp; background-image:&nbsp;url('example_img_girl.jpg');\n&nbsp; background-repeat:&nbsp;no-repeat;\n}\n&lt;\/style&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Portada de fondo<\/h2>\n\n\n\n<p>Si deseas que la imagen de fondo cubra todo el elemento, puedes configurar la propiedad <strong><em>background-size<\/em><\/strong> para que cubra. Adem\u00e1s, para asegurarte de que todo el elemento est\u00e9 siempre cubierto, establece la propiedad <strong><em>background-attachment<\/em><\/strong> en <strong><em>fixed<\/em><\/strong>. De esta forma, la imagen de fondo cubrir\u00e1 todo el elemento, sin estirarse (la imagen mantendr\u00e1 sus proporciones originales).<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;style&gt;\nbody&nbsp;{\n&nbsp; background-image:&nbsp;url('img_girl.jpg');\n&nbsp; background-repeat:&nbsp;no-repeat;\n&nbsp; background-attachment:&nbsp;fixed;\n&nbsp; background-size:&nbsp;cover;\n}\n&lt;\/style&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Background stretch (estiramiento de fondo)<\/h2>\n\n\n\n<p>Si deseas que la imagen de fondo se estire para adaptarse a todo el elemento, puedes establecer la propiedad <strong><em>background-size<\/em><\/strong> en 100 % 100 %:<\/p>\n\n\n\n<p><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;style&gt;\nbody&nbsp;{\n&nbsp; background-image:&nbsp;url('img_girl.jpg');\n&nbsp; background-repeat:&nbsp;no-repeat;\n&nbsp; background-attachment:&nbsp;fixed;\n&nbsp; background-size:&nbsp;100% 100%;\n}\n&lt;\/style&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Se puede especificar una imagen de fondo para casi cualquier elemento HTML. Para agregar una imagen de fondo en un [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":41,"menu_order":19,"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-140","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":"Se puede especificar una imagen de fondo para casi cualquier elemento HTML. Para agregar una imagen de fondo en un [&hellip;]","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/140","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=140"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/140\/revisions"}],"predecessor-version":[{"id":142,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/140\/revisions\/142"}],"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=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}