I recently started learning html and CSS. I made a very simple CSS grid layout, but it produces a horizontal bar instead of the intended square layout. What am I doing wrong?
.header {
grid-area: "h";
}
.sideMenu {
grid-area: "s";
}
.content {
grid-area: "c";
}
.footer {
grid-area: "f";
}
.grid-body {
display: grid;
grid-template-areas:
". h h h ."
"s . . . ."
"s . c c ."
". . c c ."
". f f . .";
}
<div class="grid-body">
<div class="header">Header</div>
<div class="sideMenu">Side Menu</div>
<div class="content">Content</div>
<div class="footer">Footer</div>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
As has been pointed out in a comment, the value of grid-area should not be in quotes.
A good tip is to use your browser's dev tools inspect facility and look at the CSS attached to each element. In your case with your snippet I saw a a yellow warning triangle next to grid-area which when hovered on warned me that the property value was invalid.
.header {
grid-area: h;
}
.sideMenu {
grid-area: s;
}
.content {
grid-area: c;
}
.footer {
grid-area: f;
}
.grid-body {
display: grid;
grid-template-areas:
". h h h ."
"s . . . ."
"s . c c ."
". . c c ."
". f f . .";
}
<div class="grid-body">
<div class="header">Header</div>
<div class="sideMenu">Side Menu</div>
<div class="content">Content</div>
<div class="footer">Footer</div>
</div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
.header {
grid-area:h;
}
.sideMenu {
grid-area:s;
}
.content {
grid-area:c;
}
.footer {
grid-area:f;
}
.grid-body {
display:grid;
grid-template-areas:
". h h h ."
"s . . . ."
"s . c c ."
". . c c ."
". f f . .";
}
<html>
<head>
<title>Grid Experiment :: Home</title>
<link rel="stylesheet" href="grid_style.css"/>
</head>
<body>
<div class="grid-body">
<div class="header">Header</div>
<div class="sideMenu">Side Menu</div>
<div class="content">Content</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>