Modèle de base
Base d'une page de site 100% responsive avec un header, nav, main (flex 1 pour l'espace restant) et footer.
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Modèle de base avec un header, nav, main et footer</title>
<style>
/* * {
border: 1px solid grey;
} */
:root {
--sectionWidth: 960px;
--headerHeight: 20vh;
--navHeight: 3vh;
--footerHeight: 5vh;
--header: rgb(115, 105, 145);
--headerSection: rgb(65, 65, 105);
--nav: rgb(40, 35, 55);
--navSection: rgb(15, 15, 35);
--navActive: #b5bfce;
--navLink: #c2dafc;
--main: rgb(135, 135, 135);
--mainSection: rgb(180, 180, 195);
--footer: rgb(45, 40, 50);
--footerSection: rgb(35, 35, 45);
--white: white;
}
html, body {
height: 100vh;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
display: flex;
flex-direction: column;
}
body > * > section {
max-width: var(--sectionWidth);
margin: 0 auto;
}
body > header {
background-color: var(--header);
}
body > header > section {
min-height: var(--headerHeight);
background-color: var(--headerSection);
}
body > nav {
background-color: var(--nav);
position: sticky;
top: 0; /* Indispensable pour fixer la barre en haut au scroll */
z-index: 100; /* Indispensable pour rester au-dessus du reste du contenu */
}
body > nav > section {
min-height: var(--navHeight);
background-color: var(--navSection);
}
/* Styles pour la liste ul */
body > nav > section > ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
justify-content: flex-end;
}
/* Styles pour les liens de navigation */
body > nav > section ul a {
display: block;
color: var(--white);
text-align: center;
padding: 8px 16px;
text-decoration: none;
font-size: 1.2em;
}
body > nav > section ul a:hover {
background-color: var(--navLink);
color: black;
}
body > nav > section ul a.active {
background-color: var(--navActive);
color: rgb(63, 63, 63);
pointer-events: none;
}
body > main {
background-color: var(--main);
display: flex;
flex: 1;
}
body > main > section {
background-color: var(--mainSection);
flex: 1;
}
body > footer {
background-color: var(--footer);
}
body > footer > section {
min-height: var(--footerHeight);
background-color: var(--footerSection);
color: var(--white);
}
p {
margin: 0;
padding: 2%;
}
</style>
</head>
<body>
<header>
<section>Header</section>
</header>
<nav>
<section>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#news">News</a></li>
</ul>
</section>
</nav>
<main>
<section>
<p>Modèle de base avec un header, nav, main (flex 1) et footer.</p>
</section>
</main>
<footer>
<section>Footer</section>
</footer>
</body>
</html>