Movatterモバイル変換


[0]ホーム

URL:


  1. Tecnologia Web para desenvolvedores
  2. CSS
  3. Referência de CSS
  4. Properties
  5. max-width

Esta página foi traduzida do inglês pela comunidade.Saiba mais e junte-se à comunidade MDN Web Docs.

View in EnglishAlways switch to English

max-width

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.

* Some parts of this feature may have varying levels of support.

A propriedademax-width doCSS estabelece a largura máxima de um elemento. Ele evita que ovalor usado da propriedadewidth se torne maior que o valor especificado pormax-width.

Experimente

max-width: 150px;
max-width: 20em;
max-width: 75%;
max-width: 20ch;
<section>  <div>    Change the maximum width.  </div></section>
#example-element {  display: flex;  flex-direction: column;  background-color: #5b6dcd;  height: 80%;  justify-content: center;  color: #ffffff;}

max-width substituiwidth, masmin-width substituimax-width.

Sintaxe

css
/* <length> valor */max-width: 3.5em;/* <porcentagem> valor */max-width: 75%;/* Valores de keyword */max-width: none;max-width: max-content;max-width: min-content;max-width: fit-content(20em);/* Valores Globais */max-width: inherit;max-width: initial;max-width: revert;max-width: revert-layer;max-width: unset;

Valores

<length>

Define amax-width como um valor absoluto.

<percentage>

Define amax-width como uma porcentagem da largura do bloco que o contém.

none

A largura não possui valor máximo. (padrão)

max-contentExperimental

Amax-width intrínseca preferida.

min-contentExperimental

O mínimomax-width intrínseco.

fit-content(<length-percentage>)

Use a fórmulafit-content com o espaço disponível substituído pelo argumento especificado, i.e.min(max-content, max(min-content, argumento)).

Preocupações de Acessibilidade

Certifique-se que os elementos definidos commax-width não sejam truncados e/ou não obscureçam outros conteúdos quando a página for ampliada para aumentar o tamanho do texto.

Definição formal

Initial valuenone
Aplica-se aall elements but non-replaced inline elements, table rows, and row groups
Inheritednão
Percentagesrefer to the width of the containing block
Computed valuethe percentage as specified or the absolute length ornone
Animation typealength,percentage or calc();

Sintaxe formal

max-width =
none|
<length-percentage [0,∞]>|
min-content|
max-content|
fit-content(<length-percentage [0,∞]>)|
<calc-size()>|
<anchor-size()>|
stretch|
fit-content|
contain

<length-percentage> =
<length>|
<percentage>

<calc-size()> =
calc-size(<calc-size-basis> ,<calc-sum>)

<anchor-size()> =
anchor-size([<anchor-name>||<anchor-size>]? ,<length-percentage>?)

<calc-size-basis> =
<size-keyword>|
<calc-size()>|
any|
<calc-sum>

<calc-sum> =
<calc-product>[[ '+'| '-']<calc-product>]*

<anchor-name> =
<dashed-ident>

<anchor-size> =
width|
height|
block|
inline|
self-block|
self-inline

<calc-product> =
<calc-value>[[ '*'| /]<calc-value>]*

<calc-value> =
<number>|
<dimension>|
<percentage>|
<calc-keyword>|
(<calc-sum>)

<calc-keyword> =
e|
pi|
infinity|
-infinity|
NaN

Exemplos

Definindo a largura máxima em pixels

Neste exemplo, o "child" terá 150 pixels de largura ou a largura do "parent", o que for menor:

HTML

html
<div>  <div>    Fusce pulvinar vestibulum eros, sed luctus ex lobortis quis.  </div></div>

CSS

css
#parent {  background: lightblue;  width: 300px;}#child {  background: gold;  width: 100%;  max-width: 150px;}

Resultado

Especificações

Specification
CSS Box Sizing Module Level 4
# sizing-values

Compatibilidade com navegadores

Veja também

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp