Недавно я создал макет, используя сетку CSS. Хотя это работает хорошо, меня смущает, как это работает. В частности, меня смущает строка grid-template-rows: auto auto 1fr auto;
.
В итоге произошло то, что размер верхнего и нижнего колонтитула соответствовал содержанию, что имеет смысл, поскольку они занимали ширину страницы. Размер статьи зависит от ее содержания. Но «заголовок» и «навигация» были разделены таким образом, что размер заголовка соответствовал содержанию, а навигация занимала остальное пространство.
Если бы я использовал вместо этого grid-template-rows: auto auto auto auto;
, заголовок и навигация имели бы одинаковый интервал, а это не то, что я хотел.
Как auto auto 1fr auto
интерпретировался так, что он давал мне такой размер, что title занимал минимально необходимое пространство, а nav - остальное? Как "fr" и "auto" взаимодействуют в этом сценарии?
main {
display: grid;
grid-template-columns: 10rem auto;
grid-template-rows: auto auto 1fr auto;
grid-template-areas: "header header" "title article" "nav article" "footer footer";
}
header {
grid-area: header;
background: lightblue;
}
div {
grid-area: title;
background: orange;
}
nav {
grid-area: nav;
background: pink;
}
article {
grid-area: article;
background: yellow;
}
footer {
grid-area: footer;
background: lightblue;
}
<main>
<header>This is the header</header>
<div>This is the title</div>
<nav>This is the nav</nav>
<article>
This is the article. This is the article. This is the article. This is the article.
This is the article. This is the article. This is the article. This is the article.
This is the article. This is the article. This is the article. This is the article.
This is the article. This is the article. This is the article. This is the article.
This is the article. This is the article. This is the article. This is the article.
This is the article. This is the article. This is the article. This is the article.
</article>
<footer>This is the footer</footer>
</main>
auto
. Таким образом, первая, вторая и четвертая строки размеромauto
и третья (содержащаяnav
) заняли все оставшееся пространство. Попробуйте установитьgrid-template-rows: auto 1fr 2fr auto;
, чтобы увидеть, что произойдет. - person fen1x   schedule 07.03.2018