Dropdown menu to vertical stack for mobile (responsive)

I am having trouble with making my dropdown menu responsive so it goes from a horizontal menu on the desktop / tablet to a stacked vertical dropdown menu for the iphone / android.
The menu is at bankruptcycanada.com/menu4.html and the markup is

<div id='cssmenu'>
  <ul>
   <li><a href='/'>Home</a></li>
   <li><a href='#'>Contact a Trustee</a>
   </li>
   <li class='has-sub'><a href='#'>FAQ</a>
      <ul>
         <li><a href='/question1.htm'>Frequently Asked Questions</a></li>
         <li><a href='/Credit-Counsellors.htm'>Credit Counsellors</a></li>
         <li><a href='/how-bankruptcy-works.htm'>How Bankruptcy Works</a></li>
         <li><a href='/BankruptcySteps.ppt.mht.html'>Steps in a Bankruptcy</a></li>
         <li><a href='/personal1.htm'>Personal Bankruptcy</a></li>
         <li><a href='/business1.htm'>Business Bankruptcy</a></li>
         <li><a href='/conduct-before-filing-bankruptcy.htm'>Conduct Before Going Bankrupt</a></li>
         <li><a href='/meeting-the-trustee.htm'>Meeting the Trustee</a></li>
         <li><a href='/Bankruptcy-Myths.htm'>Bankruptcy Myths</a></li>
         <li class='last'><a href='/blog.htm'>Blog</a></li>
      </ul>
   </li>
   <li><a href='/BankruptcyTermPredictor.php'>Bankruptcy Cost</a></li>
   <li><a href='/ask-a-trustee/'>Ask a Trustee</a></li>
   <li class='has-sub'><a href='#'>Proposals</a>
      <ul>
         <li><a href='/consumer-proposals.htm'>Consumer Proposals - Avoid Bankruptcy</a></li>
         <li><a href='/Bankruptcy-vs-Consumer-Proposals.htm'>Bankruptcy vs. Consumer Proposal</a></li>
         <li class='last'><a href='/ConsumerProposalSteps.html'>Steps in a Consumer Proposal</a></li>
      </ul>
   </li>
      <li class='has-sub'><a href='#'>Exemptions</a>
      <ul>
         <li class='last'><a href='/bankruptcyexemptions.htm'>Find Out What You KEEP</a></li>
      </ul>
   <li class='has-sub'><a href='#'>After Bankruptcy</a>
      <ul>
         <li class='last'><a href='/rebuildcredit1.htm'>Credit After Bankruptcy</a></li>
         <li class='last'><a href='/After-Bankruptcy-Lenders.htm'>After Bankruptcy Lenders</a></li>
      </ul>
   </li>
   <li><a href='/francais.htm'>Francais</a></li>
</ul>
</div>

I have separate stylesheets desktop.css / tablet.css / iphone.css / phone.css.
The styles I wrote for the desktop is:

#cssmenu
#cssmenu,
#cssmenu ul,
#cssmenu li,
#cssmenu a {
  border: none;
  margin: 0;
  padding: 0;

}
#cssmenu {
  height: 37px;
  display: block;
  padding: 0;
  margin: 2px 0;
  border: 1px solid;
  border-radius: 5px;
  width: auto;
}
#cssmenu > ul {
  list-style: inside none;
  padding: 0;
  margin: 0;
}
#cssmenu > ul > li {
  list-style: inside none;
  padding: 0;
  margin: 0;
  float: left;
  display: block;
  position: relative;
}
#cssmenu > ul > li > a {
  outline: none;
  display: block;
  position: relative;
  padding: 8px 16px;
  text-align: center;
  text-decoration: none;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
  font-weight: bold;
  font-size: 13px;
  font-family: Arial, Helvetica, sans-serif;
}
#cssmenu > ul > li:first-child > a {
  border-radius: 5px 0 0 5px;
}
#cssmenu > ul > li > a:after {
  content: '';
  position: absolute;
  border-right: 1px solid;
  top: -1px;
  bottom: -1px;
  right: -2px;
  z-index: 99;
}
#cssmenu ul li.has-sub:hover > a:after {
  top: 0;
  bottom: 0;
}
#cssmenu > ul > li.has-sub > a:before {
  content: '';
  position: absolute;
  top: 18px;
  right: 4px;
  border: 5px solid transparent;
  border-top: 5px solid #FFF;
}
#cssmenu > ul > li.has-sub:hover > a:before {
  top: 19px;
}
#cssmenu ul li.has-sub:hover > a {
  background: #c00404;
  border-color: #c00404;
  padding-bottom: 13px;
  z-index: 999;
}
#cssmenu ul li.has-sub:hover > ul,
#cssmenu ul li.has-sub:hover > div {
  display: block;
}
#cssmenu ul li.has-sub > a:hover {
  background: #c00404;
  border-color: #c00404;
}
#cssmenu ul li > ul,
#cssmenu ul li > div {
  display: none;
  width: auto;
  position: absolute;
  top: 38px;
  padding: 10px 0;
  background: #9C2125;
  border-radius: 0 0 5px 5px;
  z-index: 999;
}
#cssmenu ul li > ul {
  width: 160px;
}
#cssmenu ul li > ul li {
  display: block;
  list-style: inside none;
  padding: 0;
  margin: 0;
  position: relative;
}
#cssmenu ul li > ul li a {
  outline: none;
  display: block;
  position: relative;
  margin: 0;
  padding: 8px 20px;
  font: 10pt Arial, Helvetica, sans-serif;
  color: #ffffff;
  text-decoration: none;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}
#cssmenu,
#cssmenu > ul > li > ul > li a:hover {
  background: #003d4a;
  background: -moz-linear-gradient(top, #003d4a 0%, #013273 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #003d4a), color-stop(100%, #013273));
  background: -webkit-linear-gradient(top, #003d4a 0%, #013273 100%);
  background: -o-linear-gradient(top, #003d4a 0%, #013273 100%);
  background: -ms-linear-gradient(top, #003d4a 0%, #013273 100%);
  background: linear-gradient(top, #003d4a 0%, #013273 100%);
}
#cssmenu {
  border-color: #c00404;
}
#cssmenu > ul > li > a {
  border-right: 1px solid #c00404;
  color: #FFF;
}
#cssmenu > ul > li > a:after {
  border-color: #fb2f2f;
}
#cssmenu > ul > li > a:hover {
  background: #c00404;
  color: #ffffff;
}
#cssmenu ul ul a:hover {
  color: #deb40d;
  font-weight:bold;
}
#cssmenu > ul > li.has-sub > a:hover:before {
  border-top: 5px solid #ffffff;
}

I have two issues:

  1. The menu on the desktop doesn’t stretch to fit across the full width of the screen; the last two items drop down a line when there is still space for them to fit. How can I fix this?
  2. What changes do I need to make to the css to make it respond as mobile for the iphone.css and phone.css? Do I need to add jquery, if so what script and where?
    Please help!! I would really appreciate some help with this. Thanks a lot.

Hi,

You can’t really make a nav fit full width equally by using padding and content. You either need to use specific widths to make it fit or use the display:table-cell approach so that its automatic. However the display:table-cell approach won;t work well for ddopdown menus because position:relative doesn’t apply to table-cells. You will just have to make sure that your menu has space to the right as browsers vary on how wide text content will be and differences can be up to 20px over a whole line of text.

The other problem with a dropdown menu is that some devices won’t do anything on hover as they only have touch not hover although modern devices do allow a first touch to activate a drop down menu where there are links involved. The problem is then that the menu won’t go away until you click somewhere else so its not very intuitive. Therefore these days I usually make dropdown menus only work on click (with js) which means that they are also usable on mobile devices.

Usually you would hide the menu in smaller screens and show the hamburger menu only which will reveal the whole menu when clicked. It’s a nicer way and more unobtrusive way to make a menu.

Regarding your original menu then the following will work (on the iphone at least) using hover and a close menu element appears at the top to allow the drop part of the nav to be closed when clicked.


<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<!-- must have viewport meta tag for mobile support -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
<style>
#cssmenu #cssmenu, #cssmenu ul, #cssmenu li, #cssmenu a {
	border: none;
	margin: 0;
	padding: 0;
}
#cssmenu {
	height: 37px;
	display: block;
	padding: 0;
	margin: 2px 0;
	border: 1px solid;
	border-radius: 5px;
	width: auto;
}
#cssmenu > ul {
	list-style: inside none;
	padding: 0;
	margin: 0;
}
#cssmenu > ul > li {
	list-style: none;
	padding: 0;
	margin: 0;
	float:left;
	position: relative;
}
#cssmenu > ul > li > a {
	outline: none;
	display: block;
	position: relative;
	padding:0 15px;
	line-height:37px;
	height:37px;
	text-align: center;
	text-decoration: none;
	text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
	font-weight: bold;
	font-size: 13px;
	font-family: Arial, Helvetica, sans-serif;
}
#cssmenu > ul > li:first-child > a { border-radius: 5px 0 0 5px; }
#cssmenu > ul > li > a:after {
	content: '';
	position: absolute;
	border-right: 1px solid;
	top: -1px;
	bottom: -1px;
	right: -2px;
	z-index: 99;
}
#cssmenu ul li.has-sub:hover > a:after {
	top: 0;
	bottom: 0;
}
#cssmenu > ul > li.has-sub > a:before {
	content: '';
	position: absolute;
	top: 18px;
	right: 4px;
	border: 5px solid transparent;
	border-top: 5px solid #FFF;
}
#cssmenu > ul > li.has-sub:hover > a:before { top: 19px; }
#cssmenu ul li.has-sub:hover > a {
	background: #c00404;
	border-color: #c00404;
	padding-bottom: 13px;
	z-index: 999;
}
#cssmenu ul li.has-sub:hover > ul, #cssmenu ul li.has-sub:hover > div { display: block; }
#cssmenu ul li.has-sub > a:hover {
	background: #c00404;
	border-color: #c00404;
}
#cssmenu ul li > ul, #cssmenu ul li > div {
	display: none;
	width: auto;
	position: absolute;
	top: 100%;
	padding: 10px 0;
	background: #9C2125;
	border-radius: 0 0 5px 5px;
	z-index: 999;
}
#cssmenu ul li > ul { width: 160px; }
#cssmenu ul li > ul li {
	display: block;
	list-style: inside none;
	padding: 0;
	margin: 0;
	position: relative;
}
#cssmenu ul li > ul li a {
	outline: none;
	display: block;
	position: relative;
	margin: 0;
	padding: 8px 20px;
	font: 10pt Arial, Helvetica, sans-serif;
	color: #ffffff;
	text-decoration: none;
	text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}
#cssmenu, #cssmenu > ul > li > ul > li a:hover {
	background: #003d4a;
	background: -moz-linear-gradient(top, #003d4a 0%, #013273 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #003d4a), color-stop(100%, #013273));
	background: -webkit-linear-gradient(top, #003d4a 0%, #013273 100%);
	background: -o-linear-gradient(top, #003d4a 0%, #013273 100%);
	background: -ms-linear-gradient(top, #003d4a 0%, #013273 100%);
	background: linear-gradient(top, #003d4a 0%, #013273 100%);
}
#cssmenu { border-color: #c00404; }
#cssmenu > ul > li > a {
	border-right: 1px solid #c00404;
	color: #FFF;
}
#cssmenu > ul > li > a:after { border-color: #fb2f2f; }
#cssmenu > ul > li > a:hover {
	background: #c00404;
	color: #ffffff;
}
#cssmenu ul ul a:hover {
	color: #deb40d;
	font-weight:bold;
}
#cssmenu > ul > li.has-sub > a:hover:before { border-top: 5px solid #ffffff; }
.mobile-menu {
	padding:15px 0;
	background:#f00;
	color:#fff;
	text-align:center;
	font-size:140%;
	font-weight:bold;
	border-radius:5px;
	margin:0 0 10px;
	display:none;
}
.mobile-menu a, .mobile-menu a:visited {
	color:#fff;
	text-decoration:none;
}
@media screen and (max-width:980px) {
#cssmenu > ul > li > a { padding:0 10px; }
}
@media screen and (max-width:860px) {
.mobile-menu { display:block }
#cssmenu ul li > ul {
	width:100%;
	text-align:center;
}
#cssmenu > ul li { float:none }
#cssmenu { height:auto; }
#cssmenu ul li.has-sub:hover > a { padding-bottom:0 }
}
</style>
</head>

<body>
<div class="mobile-menu"><a href="#">Close menu</a></div>
<div id='cssmenu'>
		<ul>
				<li><a href='/'>Home</a></li>
				<li><a href='#'>Contact a Trustee</a> </li>
				<li class='has-sub'><a href='#'>FAQ</a>
						<ul>
								<li><a href='/question1.htm'>Frequently Asked Questions</a></li>
								<li><a href='/Credit-Counsellors.htm'>Credit Counsellors</a></li>
								<li><a href='/how-bankruptcy-works.htm'>How Bankruptcy Works</a></li>
								<li><a href='/BankruptcySteps.ppt.mht.html'>Steps in a Bankruptcy</a></li>
								<li><a href='/personal1.htm'>Personal Bankruptcy</a></li>
								<li><a href='/business1.htm'>Business Bankruptcy</a></li>
								<li><a href='/conduct-before-filing-bankruptcy.htm'>Conduct Before Going Bankrupt</a></li>
								<li><a href='/meeting-the-trustee.htm'>Meeting the Trustee</a></li>
								<li><a href='/Bankruptcy-Myths.htm'>Bankruptcy Myths</a></li>
								<li class='last'><a href='/blog.htm'>Blog</a></li>
						</ul>
				</li>
				<li><a href='/BankruptcyTermPredictor.php'>Bankruptcy Cost</a></li>
				<li><a href='/ask-a-trustee/'>Ask a Trustee</a></li>
				<li class='has-sub'><a href='#'>Proposals</a>
						<ul>
								<li><a href='/consumer-proposals.htm'>Consumer Proposals - Avoid Bankruptcy</a></li>
								<li><a href='/Bankruptcy-vs-Consumer-Proposals.htm'>Bankruptcy vs. Consumer Proposal</a></li>
								<li class='last'><a href='/ConsumerProposalSteps.html'>Steps in a Consumer Proposal</a></li>
						</ul>
				</li>
				<li class='has-sub'><a href='#'>Exemptions</a>
						<ul>
								<li class='last'><a href='/bankruptcyexemptions.htm'>Find Out What You KEEP</a></li>
						</ul>
				<li class='has-sub'><a href='#'>After Bankruptcy</a>
						<ul>
								<li class='last'><a href='/rebuildcredit1.htm'>Credit After Bankruptcy</a></li>
								<li class='last'><a href='/After-Bankruptcy-Lenders.htm'>After Bankruptcy Lenders</a></li>
						</ul>
				</li>
				<li><a href='/francais.htm'>Francais</a></li>
		</ul>
</div>
</body>
</html>


However, I would look at implementing a click dropdown for mobile instead though as its much more usable.

Thank you Paul very much for your detailed response!