Responsive Webseiten gestalten

Seite 5: Exkurs: Responsive Navigation

Inhaltsverzeichnis

Die hinterlegte Datei zeigt eine Beispielanwendung mit responsiver Navigation. Das Navigationselement ist wie folgt aufgebaut:

<header id="header">
<h1>Responsive Nav</h1>
<a class="nav-btn" id="nav-open-btn" href="#nav"></a>
</header>
<nav id="nav">
<a class="close-btn" id="nav-close-btn" href="#top"></a>
<ul>

<li>Willkommen</li>
<li>Über mich</li>
<li>Kontakt</li>

</ul>
</nav>

Mit den entsprechenden Anweisungen im CSS stellt sich Flexibilität ein:

body 
{
margin: 0;
padding: 0;
color: White;
font-family: Verdana;
}

#header
{
background-color: #343434;
padding: 20px;
text-align: center;
}

#nav
{
width: 100%;
background-color: #343434;
border-bottom: 3px solid black;
}

#nav-open-btn,
#nav-close-btn
{
position: absolute;
right: 10px;
top: 10px;
background-image: url(nav-icon.png);
display: block;
width: 20px;
height: 20px;
display: none;
}

#nav ul
{
list-style: none;
padding: 10px;
margin: 0;
text-align: center;
}

#nav ul li
{
display: inline-block;
padding: 5px;
}

#nav ul li:hover, .selected
{
background-color: #26a5e0;
}

@media (max-width: 480px)
{
#nav {
position: absolute;
top: 0px;
}

#nav ul {
margin-top: 25px;
}

#nav ul li
{
display: block;
}

/* Der Link zum öffnen/schließen des Menüs ändern den Anker #nav */
#nav:not(:target)
{
display: none;
}

#nav-open-btn, #nav-close-btn
{
display: block;
}
} (jul)