Assumed you have a web site for years. It has a traditional layout with a header, a menu sidebar, and a content area. The menu sidebar and also the header do not fit very well on a smartphone screen.We need a scrolling friendly vertical design. It should appear automatically whenever the screen width is the size of a smartphone. We need an overlay menu instead of the menu sidebar.
And we need it quickly without a complete redesign.
This is what I just did for my old web site http://www.galactic-developments.de
(Because it went so smooth and easy, I'll report what I did. Maybe it helps someone. Paying back to the Web.)
Starting with a typical nice static, not responsive, not smartphone compatible design:
We will turn it into a responsive design with popup menu:
...in 10 minutes.
The Basic Principle:
// here will be CSS
The above CSS means, that the styles will be applied to screens (not when printed) and which are smaller than 700 pixels.
Things to do:
1. Remove Header, Footer, and Frame
2. Menu
I decided, that the menu button should be in the top right corner of the screen and the menu will appear on the right side. Reason: the button in the top right corner will cover less of the text. There is free space at the top right while the top left always has text. I move the menu from the left side, which is also left of the text, to right side and above the text. My menu <div> has the ID "menu":
position:fixed; right:0px; top:0px;
background-color:#ffffff; padding:4px;
}
3. Menu Button
I insert the button <div> into the HTML (I put it just before the header <div>):
Add CSS for the menu button:
#menubutton {
display: block; position:fixed;
right:4px; top:4px; width:24px; height: 24px;
background:url(img/menubutton.png);
}
Shift the the menu down to make room for the menu button:
#menu { margin-top:28px; }
Add a small JavaScript section to the HTML to toggle the visibility of the menu, when the menu button is pressed (jquery would be overkill, could use jquery for fade/slide animations, though):
<script>
document.getElementById('menubutton').onclick = function()
{
var m = document.getElementById('menu');
m.style.display = (m.style.display == 'block' ? 'none' : 'block');
};
</script>
4. Device Scaling:
<meta name="viewport"
content="width=device-width,initial-scale=1,user-scalable=no"
/>
That's basically it:
5. Additional Tweaks:
In other words: a style which is only used by a single page is configured globally by the media query CSS section. No problem. Since the link is inside a <div class="link">:
A small shadow for the menu is no mistake:
#menu {
-webkit-box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
}
Result:
Summary:
The complete CSS:@media screen and (max-width:700px) {
#bgtop { display: none; }
#bgcenter { background:none; }
#bgbottom { display: none; }
#menu { margin-left: 0px; }
#menu {
position:fixed; right:0px; top:0px;
background-color:#ffffff; padding:4px;
}
display: block; position:fixed;
right:4px; top:4px; width:24px; height: 24px;
background:url(img/menubutton.png);
}
#menu { display: none; }
* { font-size:14px; }
#menuWallpapers { display: none; }
#bgcenter, #main { width: auto; }
.link { display: none; }
#menu {
-webkit-box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 1);
}
}
A bit HTML and JavaScript for the menu button:
{
var m = document.getElementById('menu');
m.style.display = (m.style.display == 'block' ? 'none' : 'block');
};
</script>
<meta name="viewport"
content="width=device-width,initial-scale=1,user-scalable=no"
/>
_happy_scaling();
Of course, there are other ways to make a responsive web site. You could use a mobile friendly CSS package, like bootstrap. But that probably means, that you will redesign your site, which won't be done in an hour.
Of course, there are more modern ways to program the menu button. You could use jquery and this JavaScript:
$('#menubutton').click(function() { $('#menu').fadeToggle(); });
But you have to include 100 kB jquery library:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>




