Наскоро създадох оформление с помощта на CSS мрежа. Въпреки че това работи добре, аз съм объркан от това как работи. По-конкретно, объркан съм за реда grid-template-rows: auto auto 1fr auto;
.
Това, което в крайна сметка се случи тук, е, че горният и долният колонтитул са оразмерени според съдържанието, което има смисъл, тъй като те обхващат ширината на страницата. Самата статия е оразмерена според нейното съдържание. Но „заглавие“ и „навигация“ бяха разделени така, че заглавието, оразмерено според съдържанието и навигацията, заемаше останалото пространство.
Ако бях използвал grid-template-rows: auto auto auto auto;
вместо това, заглавието и навигацията щяха да споделят еднакво разстояние, което не беше това, което исках.
Как беше интерпретирано auto auto 1fr auto
, така че да ми даде оразмеряване, така че заглавието да заема минимално необходимото място, а 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