Home >Web Front-end >CSS Tutorial >How to Resize Font Size Dynamically Based on Div Size?
Resize Font-Size According to Div Size
In a scenario where a div is composed of nine boxes with text contained within the middle box, it is desirable to adjust the font size dynamically to maintain a consistent ratio with the overall page dimensions.
Resizing Text Within the Div
To achieve this, incorporate the following CSS3 properties within the
tag:body { font-size: calc(1.25vmin + 1.25vmax); }
Cross-Resolution Compatibility
Instead of utilizing multiple CSS media queries to accommodate different resolutions, consider using the following CSS3 styles, which automatically adjust font size based on the screen width:
@media (min-width: 50px) { body { font-size: 0.1em; } } @media (min-width: 100px) { body { font-size: 0.2em; } } // ...and so on, with incrementing width thresholds... @media (min-width: 1700px) { body { font-size: 3.6em; } }
Explanation
The above is the detailed content of How to Resize Font Size Dynamically Based on Div Size?. For more information, please follow other related articles on the PHP Chinese website!