”;
The CSS min-content is a value that can be used for sizing properties to specify the minimum size of a box or element based on its content.
It specifically suggests that text content will make use of soft-wrapping opportunities, which enable the material to resize to the length of its longest word. The min-content value is calculated based on the intrinsic minimum size required by the content inside the box.
Syntax
/* Used as a length */ width: min-content; inline-size: min-content; height: min-content; block-size: min-content; /* Used in grid tracks */ grid-template-columns: 100px 2fr min-content;
CSS min-content – Box Sizing
The following example demonstrates the use of min-content keyword for box sizing.
<html> <head> <style> body { background-color: #b9cded; font-family: ''Helvetica Neue'', Arial, sans-serif; margin: 0; padding: 20px; } .container { width: 100%; display: flex; flex-direction: column; align-items: flex-start; } .item { width: min-content; background-color: #ffffff; padding: 5px; margin-bottom: 20px; border: 1px solid #e0e0e0; box-shadow: 0 3px 6px rgba(0, 0, 0, 1); color: #444444; border-radius: 8px; } </style> </head> <body> <div class="container"> <div class="item">Min-Content Example.</div> <div class="item">Well-Crafted Min-Content Example.</div> <div class="item">Thoughtfully Presented Min-Content Example.</div> </div> </body> </html>
CSS min-content – Sizing Grid Columns
The following example demonstrates the use of min-content keyword for sizing grid columns.
<html> <head> <style> body { margin: 0; font-family: ''Arial'', sans-serif; background-color: #f9f9f9; } #container { display: grid; grid-template-columns: 1fr min-content min-content; grid-gap: 15px; box-sizing: border-box; max-width: 800px; margin: 20px auto; padding: 20px; background-color: #f2f2f2; border: 1px solid #82807f; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5); border-radius: 8px; } .item { background-color: #5f9ea0; color: #141414; padding: 15px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); } </style> </head> <body> <div id="container"> <div class="item">Flexible Content Area</div> <div class="item">Min-Content 1 Content Area</div> <div class="item">Min-Content 2 Content Area</div> <div class="item">Dynamic Content Area</div> <div class="item">Min-Content 3 Content Area</div> <div class="item">Min-Content 4 Content Area</div> </div> </body> </html>
Advertisements
”;