Home  >  Article  >  Web Front-end  >  CSS3 adaptive layout technology flexible size

CSS3 adaptive layout technology flexible size

零到壹度
零到壹度Original
2018-03-24 11:03:242164browse

Grid layout supports flexible size (flex-size), which is a good adaptive layout technology.

Flexible dimensions use fr size units, which come from the first two letters of the word "fraction" or "fractional unit" and represent a portion of the overall space.

For example, the following CSS rule:

grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);

means there are 4 columns, the first column is 100px fixed size, the third column max-content means the size that just contains the elements without overflowing or wrapping, and the rest The 2 columns are both flexible sizes.

According to the calculation rules of elastic size, the two will divide the remaining available space equally (the elastic coefficients of these two columns are equal, both are 1).

CSS3 demonstration code:

#grid {
    display: grid;
    width: 100%;
    grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);
}
#title {
    background-color: lime;
}
#score {
    background-color: yellow;
}
#stats {
    background-color: lime;
}
#message {
    background-color: orange;
}
p {
    height: 80px;
    line-height: 80px;
    text-align: center;
}


HTML code:

<p id="grid">
    <p id="title">Site Logo</p>
    <p id="score">Slogan</p>
    <p id="stats">User Zone</p>
    <p id="message">Message</p>
</p>

Related recommendations:

Detailed explanation of elastic layout

Flexible Layout

css3 Flexible Layout

The above is the detailed content of CSS3 adaptive layout technology flexible size. 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
Previous article:CSS layout grid areaNext article:CSS layout grid area