What is the difference between
div { width: fit-content; }
and
div { width: 100%; }
2
The best to understand is to try it …
<style> .parent { background-color: red; width: 500px; } .child-fit { background-color: blue; width: fit-content; } .child-100 { background-color: yellow; width: 100%; } </style>
<div class="parent"> <div class="child-fit"> <p>FIT CONTENT</p> </div> <div class="child-100"> <p>100%</p> </div> </div>
width 100% will stretch to the whole width of the parent
fit-content will make it as wide as it’s children
https://css-tricks.com/almanac/properties/w/width/
Click here to cancel reply.
2
Answers
The best to understand is to try it …
width 100% will stretch to the whole width of the parent
fit-content will make it as wide as it’s children
https://css-tricks.com/almanac/properties/w/width/