html.de - CSS-Menü
by SpiceLab
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<div id="main">
<nav role="navigation" id="nav">
<input class="trigger" type="checkbox" id="mainNavButton">
<label for="mainNavButton" onclick>Menu</label>
<ul>
<li><a href="#"><span>Link 1</span></a></li>
<li><a href="#"><span>Link 2</span></a>
<li><a href="#"><span>Link 3</span></a></li>
<li><a href="#"><span>Link 4</span></a></li>
</ul>
</nav>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestiae, dignissimos, distinctio
consequatur eos optio recusandae maiores quidem possimus tempora esse reiciendis velit ut
consequuntur architecto hic soluta deleniti fugit explicabo.</p>
</div>
CSS
body {
margin: 25px;
-webkit-animation: bugfix infinite 1s;
/* needed for checkbox hack */
background: #021320;
}
@-webkit-keyframes bugfix {
from {
padding: 0;
}
to {
padding: 0;
}
}
/* needed for checkbox hack */
h1, p {
color: white;
}
#main {
width:80%;
margin: 0;
}
#nav {
position: relative;
}
#nav ul {
display: none;
width: 100%;
list-style: none;
margin: 0px;
padding: 0px;
}
#nav ul li a {
display: flex; /* wie in MrMurphys Beispiel - anstatt display: block */
justify-content: center; /* Ergänzung, damit flexible Elemente mittig angeordnet werden */
padding: 0.2em;
margin: 0.2em;
background: #0F9962;
color: white;
text-decoration: none;
border-right: 1px solid #0a6b44;
font-weight: bold;
transform: skew(-45deg);
position: relative; /* absolute top-/left-Startpositionen von ::before u. ::after beziehen sich auf <a> */
}
#nav ul li:first-child a::before,
#nav ul li:last-child a::after {
content: "";
background-color: rgba(255, 255, 0, .5); /* nur zu Demozwecken; wieder auf #0F9962 zurücksetzen */
position: absolute;
z-index: 10; /* nur zu Demozwecken; wieder auf -1 zurücksetzen */
transform: skew(45deg);
width: 2em;
height: 100%;
top: 0;
left: -.8em;
}
#nav ul li:last-child a::after {
left: calc(100% - 1.2em);
}
#nav ul li a span {
transform: skew(45deg);
}
#nav ul li a:hover {
background: #0d8253;
}
#nav ul li:last-of-type a {
border-right: 0px;
}
#nav input.trigger {
position: absolute;
top: -9999px;
left: -9999px;
transform: skew(45deg);
}
#nav input.trigger:checked ~ ul {
display: block !important;
}
@media (min-width: 50em) {
#nav input.trigger:checked ~ ul {
/* older flexbox */
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
/* newer flexbox */
display: flex;
flex-direction:...