Grid columns and rows failing to align properly

醉酒当歌 提交于 2019-12-24 19:31:45

问题


I'm new to CSS and i have been trying to construct a quite simple layout with CSS grid .

I drew a sketch:

So after reading the Great explanation in css-tricks, i started writing the code but for some reason the rows aren't laid correctly as i would expect (my code on codepen).

grid-template-rows: 5em 50vh 100vh 30vh;
grid-template-columns: 0.15% 0.3% 0.4 0.15%;

grid-template-areas: "logo search-bar menu . "
                        "description description description nav-bar"
                        "main main main . "
                        "footer footer footer footer";

Can someone please explain and assist me how to do it correctly?

Thank you all in advance, for the help.


回答1:


First, you're missing a percentage unit in a column value:

grid-template-columns: 0.15% 0.3% 0.4 0.15%

That invalidates the entire rule.

Second, grid-area property values don't use quotes.

This is invalid: grid-area: "logo".

It's just grid-area: logo.

Third, your navigation links are out of place because you have an HTML-CSS mismatch:

<nav class="navigation-icon-links">navigation-links</nav>

.navigation-links {
    grid-area: nav-bar;
    background:orange;
}

revised codepen



来源:https://stackoverflow.com/questions/54896160/grid-columns-and-rows-failing-to-align-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!