fit-content - CSS: Cascading Style Sheets 编辑
The fit-content
behaves as fit-content(stretch)
. In practice this means that the box will use the available space, but never more than max-content
.
When used as laid out box size for width
, height
, min-width
, min-height
, max-width
and max-height
the maximum and minimum sizes refer to the content size.
The CSS Sizing specification also defines the fit-content()
function. This page details the keyword.
Syntax
width: fit-content
block-size: fit-content
Examples
Using fit-content for box sizing
HTML
<div class="container">
<div class="item">Item</div>
<div class="item">Item with more text in it.</div>
<div class="item">Item with more text in it, hopefully we have added enough text so the text will start to wrap.</div>
</div>
CSS
.container {
border: 2px solid #ccc;
padding: 10px;
width: 20em;
}
.item {
width: -moz-fit-content;
width: fit-content;
background-color: #8ca0ff;
padding: 5px;
margin-bottom: 1em;
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Box Sizing Module Level 4 The definition of 'fit-content' in that specification. | Editor's Draft | Defines the value as laid out box size for width , height , min-width , min-height , max-width and max-height . |
Browser compatibility
Supported for width (and other sizing properties)
BCD tables only load in the browser
See also
- Related sizing keywords:
min-content
,max-content
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论