- max-width
- Try it
- Syntax
- Values
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Установка максимальной ширины в пикселях
- HTML
- CSS
- Result
- Specifications
- max-width
- Синтаксис
- Значения
- Объектная модель
- Браузеры
- max-width
- Try it
- Syntax
- Values
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Setting max width in pixels
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
max-width
Свойство CSS max-width устанавливает максимальную ширину элемента. Это предотвращает используется значение от width собственности становиться больше , чем значение , указанное в max-width .
Try it
max-width переопределяет width , но min-width переопределяет max-width .
Syntax
/ * значение * / max-width: 3.5em; / * значение * / max-width: 75%; / * Значения ключевых слов * / max-width: none; max-width: max-content; max-width: min-content; max-width: fit-content(20em); / * Глобальные значения * / max-width: inherit; max-width: initial; max-width: revert; max-width: revert-layer; max-width: unset;
Values
Определяет max-width как абсолютное значение.
Определяет max-width в процентах от ширины содержащего блока.
Размер коробки не ограничен.
Внутренняя предпочтительная max-width .
Внутренняя минимальная max-width .
Использует формулу fit-content в которой доступное пространство заменяется указанным аргументом, например min(max-content, max(min-content, argument)) .
Accessibility concerns
Убедитесь, что элементы с max-width не обрезаются и / или не затеняют другой контент, когда страница масштабируется для увеличения размера текста.
Formal definition
Initial value | none |
---|---|
Applies to | все элементы,кроме неперемещенных встроенных элементов,строк таблицы и групп строк. |
Inherited | no |
Percentages | относиться к ширине содержащего блока |
Computed value | в процентах, как указано или абсолютная длина или none |
Animation type | длина , процент или calc (); |
Formal syntax
max-width = none | length-percentage [0,∞]> | min-content | max-content | fit-content( length-percentage [0,∞]> ) length-percentage> = length> | percentage>
Examples
Установка максимальной ширины в пикселях
В данном примере ширина «дочернего» элемента будет равна либо 150 пикселям,либо ширине «родительского» элемента,в зависимости от того,что меньше.
HTML
id="parent">id="child"> Fusce pulvinar vestibulum eros, sed luctus ex lobortis quis.
CSS
#parent < background: lightblue; width: 300px; > #child < background: gold; width: 100%; max-width: 150px; >
Result
Specifications
max-width
Устанавливает максимальную ширину элемента. Значение ширины элемента будет вычисляться в зависимости от значений установленных свойств width , max-width и min-width . В табл. 1 показано, чем руководствуется браузер при совместном использовании указанных стилевых свойств.
Значения свойств | Ширина | ||||
---|---|---|---|---|---|
min-width | width | max-width | width | ||
width | max-width | width | |||
width | > | max-width | max-width | ||
min-width | > | width | > | max-width | min-width |
min-width | > | width | max-width | min-width |
Данные из таблицы следует понимать следующим образом. Если значение ширины ( width ) больше значения max-width , то ширина элемента принимается равной значению max-width .
Синтаксис
max-width: значение | проценты | none | inherit
Значения
В качестве значений принимаются пикселы (px), проценты (%) и другие единицы измерения, принятые в CSS. Отрицательные значения не допускаются.
none Отменяет действие этого свойства. inherit Наследует значение родителя.
HTML5 CSS2.1 IE Cr Op Sa Fx
Текст заголовка
Текст примера
В данном примере ширина страницы ограничена размером 320 пикселов для всех наладонных устройств. К ним относятся КПК, смартфоны и другие устройства, способные отображать HTML-документы.
Объектная модель
[window.]document.getElementById(» elementID «).style.maxWidthБраузеры
Internet Explorer до версии 7.0 включительно не поддерживает значение inherit .
max-width
The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width .
Try it
max-width overrides width , but min-width overrides max-width .
Syntax
/* value */ max-width: 3.5em; /* value */ max-width: 75%; /* Keyword values */ max-width: none; max-width: max-content; max-width: min-content; max-width: fit-content(20em); /* Global values */ max-width: inherit; max-width: initial; max-width: revert; max-width: revert-layer; max-width: unset;
Values
Defines the max-width as an absolute value.
Defines the max-width as a percentage of the containing block’s width.
No limit on the size of the box.
The intrinsic preferred max-width .
The intrinsic minimum max-width .
Uses the fit-content formula with the available space replaced by the specified argument, i.e. min(max-content, max(min-content, argument)) .
Accessibility concerns
Ensure that elements set with a max-width are not truncated and/or do not obscure other content when the page is zoomed to increase text size.
Formal definition
Initial value | none |
---|---|
Applies to | all elements but non-replaced inline elements, table rows, and row groups |
Inherited | no |
Percentages | refer to the width of the containing block |
Computed value | the percentage as specified or the absolute length or none |
Animation type | a length, percentage or calc(); |
Formal syntax
max-width =
none |
|
min-content |
max-content |
fit-content( )
=
|
Examples
Setting max width in pixels
In this example, the «child» will be either 150 pixels wide or the width of the «parent,» whichever is smaller.
HTML
div id="parent"> div id="child"> Fusce pulvinar vestibulum eros, sed luctus ex lobortis quis. div> div>
CSS
#parent background: lightblue; width: 300px; > #child background: gold; width: 100%; max-width: 150px; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 18, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.