Come fare per - Menu fisso
Scopri come creare un menu "fisso" con CSS.
Come creare un menu superiore fisso
Passaggio 1) Aggiungi HTML:
Esempio
<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>
Passaggio 2) Aggiungi CSS:
Per creare un menu superiore fisso, utilizzare position:fixed
e top:0
. Nota che il menu fisso si sovrapporrà agli altri tuoi contenuti. Per risolvere questo problema, aggiungi un margin-top
(al contenuto) uguale o maggiore dell'altezza del tuo menu.
Esempio
/* 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 */
}
Come creare un menu inferiore fisso
Per creare un menu a fondo fisso, utilizzare position:fixed
e
bottom:0
:
Esempio
/* 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 */
}
Suggerimento: vai al nostro tutorial CSS Navbar per saperne di più sulle barre di navigazione.