CSS Menu Slider
Objective: To create a CSS-only layout including a scrollable menu that slides out from the left. Meant for mobile versions of sites. Live Demo: https://github.com/NicholasRBowers/CSS-Menu-Slider Additional Information: -CSS-only -Meant for mobile devices -Meant to be used in conjunction with Responsive Design -Want to design as semantic as possible -Akin to Facebook's Mobile and App layout -Completely breaks in IE -Collaboration welcome! Operation Logic: -Uses the checkbox-hack to store state information (http://css-tricks.com/the-checkbox-hack/) =When unchecked, menu is closed, when checked menu is open. -Input checkbox exists at the base level of the HTML (under <body>) with an absolutely positioned <div> tag afterwards that encapsulates the page. -<div> tag holds the rest of the page, including fixed absolutely positioned elements. -Header and Navigation toggle are fixed at top, scrollable <div> under, and fixed/scrollable menu to the left. -An extra invisible label allows a click anywhere on the right to toggle states and collapse the menu. Comments: -Completely broken in IE, but as this is meant for mobile only, I'm not sure that's a problem. -Zooming out on a mobile device sometimes causes rendering problems. -Had to put the rest of the page in a <div> that was a sibling to the <input> element, because the default Android browser only supports the adjacent sibling combinator (+) when used in tandem with a pseudo-class (:checked). NOTE: It does support the sibling combinator (~), but it only picks up the adjacent element. Twitter: @NicholasRBowers
by sandesh2302
HTML
<html>
<head>
<title>
CSS Menu Slider
</title>
<meta content='True' name='HandheldFriendly' />
<meta content='width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' />
<meta name="viewport" content="width=device-width" />
<link href="style.css" rel="stylesheet" />
</head>
<body>
<input type="checkbox" name="nav" id="nav" />
<div id="page">
<!-- Anything in the header tag show in a fixed position at the top of the screen -->
<header>
<h1>Header</h1>
</header>
<!-- navbuttontop is the navigation button, while contentsideoverlay is the transparent label used to let the user return to the content menu from the nav menu by clicking anywhere out of the navigational menu -->
<label id="navbuttontop" for="nav">
<img src="http://cdn1.iconfinder.com/data/icons/fatcow/32x32/restaurant_menu.png" />
</label>
<label id="contentsideoverlay" for="nav"></label>
<!-- Anything in the nav tag shows up in the side navigational bar -->
<nav>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</nav>
<!-- Area for page content -->
<div id="content">
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
This is a scrollable div.
</div>
</div>
</body>
</html>
CSS
/* This is a very rough stylesheet, it will be built on the HTML5 Boilerplate eventually, but I wanted to keep it simple in order to get it working first */
/*==|== General =============================================== */
body, div {
padding: 0;
margin: 0; }
input {
display: none !important;
visibility: hidden; }
label {
cursor: pointer; }
/*==|== Layout ================================================ */
#page {
width: 100%;
height: 100%;
position: relative;
left: 0;
top: 0; }
header {
width: 100%;
height: 55px;
position: fixed;
left: 0;
top: 0; }
header h1 {
position: absolute;
left: 8em;
margin: auto 0; }
/* Toggle button */
label#navbuttontop {
padding: 0;
margin: 11px;
position: fixed;
left: 0;
top: 0;
}
/* An invisible label that allows the user to return to the page by clicking anywhere outside of the navigational menu */
label#contentsideoverlay {
position: fixed;
left: 60%;
top: 0;
width: 40%;
height: 100%; }
nav {
position: fixed;
left: -60%;
top: 0;
width: 60%;
margin: 0;
padding: 0;
height: 100%; }
nav ul, nav li {
display: block;
float: left;
width: 100%;
margin: 0;
padding: 0; }
nav a {
display: block;
float: left;
margin: 0;
width: 95%;
padding: 2.5%; }
/*
/* Content area */
#content {
float: left;
padding-top: 55px;
height: 2000px;
/* here to test scrollability */
width: 100%;
z-index: -1; }
/*==|== Appearance ============================================ */
header {
background: -webkit-linear-gradient(#f41010 0%, #f83333 100%);
background: -moz-linear-gradient(#f41010 0%, #f83333 100%);
background: -o-linear-gradient(#f41010 0%, #f83333 100%);
background: -ms-linear-gradient(#f41010 0%, #f83333 100%);
background: linear-gradient(#f41010 0%, #f83333 100%);
background: #e5e5e5;
-webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 2px 0 rgba(250, 250, 250, 0.3) inset;
-moz-box-shadow:...