Home >Web Front-end >CSS Tutorial >CSS Grid: Percentage vs. `fr` Units: What's the Difference?

CSS Grid: Percentage vs. `fr` Units: What's the Difference?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-28 09:41:09749browse

CSS Grid: Percentage vs. `fr` Units: What's the Difference?

The Difference Between Percentage and fr Units in CSS Grid Layout

When using fr units, the free space in the container is distributed equally among the columns. The grid-column-gap property is not a factor.

However, when using %, the container is divided into a number of columns, each having a width determined by the percentage. Both the column lengths and grid gaps are factored into the width.

This can lead to overflow if the total width of the columns and gaps exceeds the width of the container.

To avoid overflow, you can use the calc() function to subtract the width of the grid gaps from the width of each column.

The above is the detailed content of CSS Grid: Percentage vs. `fr` Units: What's the Difference?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn