Hello, I need a simple layout that at first might seem like a good candidate for a flex container set to column, with another flex container set to horizontal in the header.
------------------------------------------------------
| <header> | |
| Logo | Navigation |
|-----------------------------------------------------
| <main> |
| Content |
| |
| |
| |
|-----------------------------------------------------
|<footer> |
| |
|----------------------------------------------------|
However, I was thinking that in the future, I might want to add a vertical sidebar to the left side of the main content or to its right side (or maybe both sides).
------------------------------------------------------
| <header> | |
| Logo | Navigation |
|-----------------------------------------------------
| <aside> | <main> |
| sidebar | Content |
| | |
| | |
| | |
|-----------------------------------------------------
|<footer> |
| |
|----------------------------------------------------|
With this in mind, wouldn’t it be better to start with a grid container? Later on, this would give me the flexibility of using grid-template-columns
to lay out things more easily, and to use flexbox only in the header. (or maybe a sub grid in the header as well?)
Browser compatibility isn’t that crucial to me. As long as it works on something from the past 5 years, it’s fine.
For now, I tried something like this, I do not need the sidebar for now. However, I’m not sure if my approach is good:
:root {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
margin: 0;
padding: 0;
background-color: lightblue;
}
.grid-container {
display: grid;
justify-content: center;
grid-template-areas:
"header"
"main"
"footer";
}
.logo {
grid-area: logo;
}
.header {
grid-area: header;
background: lightsalmon;
}
.main {
grid-area: main;
}
.footer {
grid-area: footer;
}
@media (min-width: 52em) {
.grid-container {
grid-template-columns: minmax(300px, 800px);
grid-template-areas:
"header"
"main"
"footer";
}
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>Website</title>
</head>
<body>
<div class="grid-container">
<header class="header">
<div class="logo">Logo</div>
<nav class="navigation">Navigation</nav>
</header>
<main class="main">
Main content
</main>
<footer>
Footer
</footer>
</div>
</body>
</html>
I would be grateful for any suggestions. Thank you.