Specifies the width of the content area of an element. The content area of the element width does not include the padding, border, and margin of the element.
Overview tableauto
/css/cssom/properties/width
width: auto
width: available
width: border-box
width: content-box
width: fit-content
width: intrinsic
width: length
width: max-content
width: min-content
width: percentage
div { width: 100% }
h1 { width: 20em }
section { width: auto }
img { width: 100px }
Example using new values that are part of the CSS Basic Box Model that is currently in working draft.
<style>
div {
box-sizing: border-box;
border: 1px solid #444;
width: 350px;
margin: 5px;
}
p {
background: #000;
color: #fff;
padding: 5px;
font-family: Arial, sans-serif;
}
p.mincontent {
width: -webkit-min-content;
}
p.maxcontent {
width: -webkit-max-content;
}
p.fitcontent {
width: -webkit-fit-content;
}
</style>
<div>
<p>This is the content inside of the parent div.</p>
</div>
<div>
<p class="mincontent">This is the content inside of the parent div.</p>
<p class="mincontent">Min-content matches the widest single word like "Antidisestablishmentarianism".</p>
</div>
<div>
<p class="maxcontent">This is the content inside of the parent div. Max-content expands to fit the content.</p>
</div>
<div>
<p class="fitcontent">This fits the content inside of the parent div.</p>
</div>
Usage
===Newer Values===
In the CSS Basic Box Model Working Draft, the values max-content, min-content, available, fit-content, border-box, and content-box were added. It would be a best practice to add the vendor prefix to these until the values are standardized.
Related specificationsConceptual
Measuring Element Dimension and Location with CSSOM in Internet Explorer 9
Other Resources
CSS Enhancements in Internet Explorer 6
Mozilla Developer Network : Article
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4