February 19, 201412 yr I've been turning my attention to responsive design a lot lately and studying the trend of the hamburger menu. I'm trying to develop one at the moment, which seems to render just fine on the desktop http://www.jonniegrieve.co.uk/tmp/ham/ham1.html but turn it to a mobile device or a mobile emulator something strange happens. In all cases the menu works exactly as it should but when you scroll the right, it's like the background colour runs out. In actual fact the need to scroll left/right is something I want to get rid of anyway but I'd like to get my head round why that occurs if possible. <!doctype html> <html> <head> <title>Mobile Menu Hamburger</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <!--Using the hamburger menu display code--> <script src="hamburger.js"></script> <!--Using Media Queries, if the viewport is smaller than 700px use another stylesheet--> <link rel="stylesheet" type="text/css" media="all" href="hamburger.css" /> <head> <body> <div id="container"> <header> <div id = "hamburger"> <div><a href = "#"></a></div> <div><a href = "#"></a></div> <div><a href = "#"></a></div> </div> <span class = "title">Jonnie Grieve Digital Media</span> </header> <nav class="mobileNav"> <ul> <li><a href="#"> </li> <li><a href="#">Hire Me!</a></li> <li><a href="#">Portfolio</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Connect</a></li> </ul></nav> <div id = "contentLayer"></div> <div id = "content">Inside content <span id = "mainContainer">inside mainContainer <br /> Jonnie Grieve Digital Media <a href = "http://www.jonniegrieve.co.uk"><img src = "http://www.jonniegrieve.co.uk/images/quotes.png" /></a> </span> </div> </div> </body> CSS header { position: fixed; width: 100%; z-index: 1; } #hamburger div { background-color: #ffffff; border: 1px solid #eeeeee; border-radius: 2px 2px 2px 2px; height: 2px; margin-top: 3px; width: 90%; } nav { left: 0px; top: 0px; position: fixed; z-index: 0%; width: 70% } /**/ body { margin: 0; padding: 0; overflow-x:hidden; font-family: Arial; font-size: 18px; } /* Header is relative so z-index: 1 guarantees always displayed on top */ header { background-color: #3b5998; padding: 10px; text-decoration: none; position: fixed; width: 100%; z-index: 1; box-shadow: 0px 3px 7px 0px rgba(0, 256, 0, 0.4); -webkit-box-shadow: 0px 3px 7px 0px rgba(0, 256, 0, 0.4);/**/ } .title { position: absolute; top: 10px; left: 40%; color: white; font-weight: 800; line-height: 16px; } /* using background color is important to cover the menu position absolute is set to cover the whole viewport */ #content { margin: 0 auto; background-color: #D9C46A; padding: 52px 10px 10px 10px; position: absolute; width: 100%; min-height: 1000px; -webkit-box-shadow: -10px 0px 9px 0px rgba(0, 0, 0, 0.4); box-shadow: -10px 0px 9px 0px rgba(0, 0, 0, 0.4); } /* the hamburger button with a little gradient effekt*/ #hamburger { border: 1px solid #374C77; border-radius: 3px 3px 3px 3px; cursor: pointer; display: block; height: 24px; padding: 3px 4px 3px; position: relative; width: 25px; background: #565656; background: -moz-linear-gradient(top, #565656 0%, #4062a5 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4569b2), color-stop(100%,#4062a5)); background: -webkit-linear-gradient(top, #4569b2 0%,#4062a5 100%); background: -o-linear-gradient(top, #4569b2 0%,#4062a5 100%); background: -ms-linear-gradient(top, #4569b2 0%,#4062a5 100%); background: linear-gradient(to bottom, #4569b2 0%,#4062a5 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4569b2', endColorstr='#4062a5',GradientType=0 );/**/ } /* The white stripes in the hamburger button*/ #hamburger div { background-color: #fff; border: 1px solid #eee; border-radius: 2px 2px 2px 2px; height: 2px; margin-top: 3px; width: 90%;/**/ } /* The navigation container in the background*/ nav { left: 0px; top: 0px; position: fixed; z-index: 0; width: 70%; height: 100%; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; overflow-x:hidden; overflow-y:auto ; background: #3e3c3d; background: -moz-linear-gradient(top, #3e3c3d 0%, #2d2c2d 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3e3c3d), color-stop(100%,#2d2c2d)); background: -webkit-linear-gradient(top, #3e3c3d 0%,#2d2c2d 100%); background: -o-linear-gradient(top, #3e3c3d 0%,#2d2c2d 100%); background: -ms-linear-gradient(top, #3e3c3d 0%,#2d2c2d 100%); background: linear-gradient(to bottom, #3e3c3d 0%,#2d2c2d 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3e3c3d', endColorstr='#2d2c2d',GradientType=0 );/**/ } /*Style the navigation menu*/ nav ul { list-style: none; margin: 0; width: 100%; padding: 0; } nav li { position: relative; font-size: 1em; font-weight: bold; border-bottom: 1px solid #222222; border-top: 1px solid #444444; padding: 15px; } nav li a { color: #fff; text-decoration: none; }/**/ /* The Layer that will be layed over the content so that the content is unclickable while menu is shown*/ #contentLayer { display: none; height: 100%; overflow-x: hidden; overflow-y: auto; position: absolute; right: 0; top: 0; width: 30%; z-index: 5; min-height: 1062px; } /*span*/ span { position: relative; top: 20px; left: 50%; } #mainContainer { margin: 0 auto; text-align: center; background-color: #D9C46A; width: 100%; } Any thoughts. I use a Sony Experia E nowaydays btw.
February 20, 201412 yr Author Fixed! For now! :-) There still seems to be a scrolling problem when I scroll right when the menu is closed but I can fix that, I looked into the jquery and set the width of the content div ID to 100% rather than auto. Thanks. :-)
Create an account or sign in to comment