{"id":1226,"date":"2024-08-01T16:32:41","date_gmt":"2024-08-01T14:32:41","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=1226"},"modified":"2024-08-01T16:32:42","modified_gmt":"2024-08-01T14:32:42","slug":"14-css-height-width-y-max-width","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/lenguajes\/css3\/css3-basico\/14-css-height-width-y-max-width\/","title":{"rendered":"14. CSS height, width y max-width"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Las propiedades <strong><em>height<\/em> <\/strong>y <strong><em>width<\/em> <\/strong>de CSS se utilizan para establecer el alto y el ancho de un elemento. La propiedad <strong><em>max-width<\/em><\/strong> de CSS se utiliza para establecer el ancho m\u00e1ximo de un elemento.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">CSS Configuraci\u00f3n de height y width<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Las propiedades <strong><em>height<\/em> <\/strong>y <strong><em>width<\/em> <\/strong>se utilizan para establecer el alto y el ancho de un elemento. Dichas propiedades no incluyen <strong>relleno<\/strong>, <strong>bordes<\/strong> ni <strong>m\u00e1rgenes<\/strong>. Establece el alto\/ancho del \u00e1rea dentro del relleno, el borde y el margen del elemento.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Valores de las propiedades height y width<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Los valores que se pueden dar en dichas propiedades pueden ser los siguientes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>auto<\/strong>: esto es predeterminado. El navegador calcula la altura y la anchura.<\/li>\n\n\n\n<li><strong>longitud<\/strong>: define el alto\/ancho en px, cm, etc.<\/li>\n\n\n\n<li><strong>% (porcentaje)<\/strong>: define el alto\/ancho en porcentaje del bloque contenedor<\/li>\n\n\n\n<li><strong>initial<\/strong>: establece el alto\/ancho a su valor predeterminado<\/li>\n\n\n\n<li><strong>inherit<\/strong>: el alto\/ancho se heredar\u00e1 de su valor principal<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Ejm<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">div&nbsp;{\n&nbsp;&nbsp;height:&nbsp;200px;\n&nbsp; width:&nbsp;50%;\n&nbsp; background-color:&nbsp;powderblue;\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configuraci\u00f3n max-width<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">La propiedad <strong><em>max-width<\/em><\/strong> se utiliza para establecer el ancho m\u00e1ximo de un elemento. <strong><em>max-width<\/em><\/strong> se puede especificar en valores de longitud, como px, cm, etc., o en porcentaje (%) del bloque contenedor, o establecerse en none (esto es predeterminado. Significa que no hay un ancho m\u00e1ximo).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">El problema con el <strong><em>&lt;div&gt;<\/em><\/strong> anterior ocurre cuando la ventana del navegador es m\u00e1s peque\u00f1a que el ancho del elemento (500 px). Luego, el navegador agrega una barra de desplazamiento horizontal a la p\u00e1gina.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usar <strong><em>max-width<\/em><\/strong> en su lugar, en esta situaci\u00f3n, mejorar\u00e1 el manejo de ventanas peque\u00f1as por parte del navegador.<\/p>\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>: si por alguna raz\u00f3n usas tanto la propiedad <strong><em>width<\/em><\/strong> como la propiedad <strong><em>max-width<\/em><\/strong> en el mismo elemento, y el valor de la propiedad <strong><em>width<\/em><\/strong> es mayor que la propiedad <strong><em>max-width<\/em><\/strong>; se usar\u00e1 la propiedad <strong><em>max-width<\/em><\/strong> (y se ignorar\u00e1 la propiedad <strong><em>width<\/em><\/strong>).<\/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\">div&nbsp;{\n&nbsp; max-width:&nbsp;500px;\n&nbsp; height:&nbsp;100px;\n&nbsp; background-color:&nbsp;powderblue;\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Todas las propiedades de dimensi\u00f3n de CSS<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Propiedad<\/th><th>Descripci\u00f3n<\/th><\/tr><tr><td><strong><em>height<\/em><\/strong><\/td><td>Establece la altura de un elemento.<\/td><\/tr><tr><td><strong><em>max-height<\/em><\/strong><\/td><td>Establece la altura m\u00e1xima de un elemento.<\/td><\/tr><tr><td><strong><em>max-width<\/em><\/strong><\/td><td>Establece el ancho m\u00e1ximo de un elemento.<\/td><\/tr><tr><td><strong><em>min-height<\/em><\/strong><\/td><td>Establece la altura m\u00ednima de un elemento.<\/td><\/tr><tr><td><strong><em>min-width<\/em><\/strong><\/td><td>Establece el ancho m\u00ednimo de un elemento.<\/td><\/tr><tr><td><strong><em>width<\/em><\/strong><\/td><td>Establece el ancho de un elemento.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Las propiedades height y width de CSS se utilizan para establecer el alto y el ancho de un elemento. La [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":563,"menu_order":13,"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-1226","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":"Las propiedades height y width de CSS se utilizan para establecer el alto y el ancho de un elemento. La [&hellip;]","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1226","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=1226"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1226\/revisions"}],"predecessor-version":[{"id":1228,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1226\/revisions\/1228"}],"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=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}