Hoe OM - Vaste spyskaart
Leer hoe om 'n "vaste" spyskaart met CSS te skep.
Hoe om 'n vaste spyskaart te skep
Stap 1) Voeg HTML by:
Voorbeeld
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
</div>
<div class="main">
<p>Some text some text some text some text..</p>
</div>
Stap 2) Voeg CSS by:
Om 'n vaste boonste spyskaart te skep, gebruik position:fixed
en top:0
. Let daarop dat die vaste kieslys jou ander inhoud sal bedek. Om dit reg te stel, voeg 'n margin-top
(by die inhoud) by wat gelyk is aan of groter as die hoogte van jou spyskaart.
Voorbeeld
/* The navigation bar */
.navbar {
overflow: hidden;
background-color: #333;
position: fixed; /* Set
the navbar to fixed position */
top: 0;
/* Position the navbar at the top of the page */
width:
100%; /* Full width */
}
/* Links inside the navbar */
.navbar a {
float: left;
display:
block;
color: #f2f2f2;
text-align:
center;
padding: 14px 16px;
text-decoration: none;
}
/* Change background on mouse-over */
.navbar
a:hover {
background: #ddd;
color:
black;
}
/* Main
content */
.main {
margin-top: 30px; /* Add a top
margin to avoid content overlay */
}
Hoe om 'n vaste spyskaart te skep
Om 'n vaste onderste kieslys te skep, gebruik position:fixed
en
bottom:0
:
Voorbeeld
/* The navigation bar */
.navbar {
position: fixed; /* Set the navbar to fixed position */
bottom: 0;
/* Position the navbar at the bottom of the page */
width:
100%; /* Full width */
}
/* Main
content */
.main
{
margin-bottom: 30px; /* Add a bottom margin to avoid content overlay */
}
Wenk: Gaan na ons CSS Navbar Tutoriaal om meer te wete te kom oor navigasiebalke.