August 21, 200917 yr Having difficulties deciding the best way to make the horizontal navigation bar expand to any size window. What would be the simplest method ?
August 21, 200917 yr Here is code for a complete page with a flexible width navbar. All the widths are in % adding to 100%. It will work until the window width is so narrow that the link texts won't fit, then a link will drop to a lower line (you could add min-width to solve this). <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Flexible width navbar</title> <style type="text/css"> body { margin: 0; } #menu { width: 100%; margin: 0; padding: 0; } #menu li { float: left; width: 20%; padding: 5px 4% 5px 0; background-color: skyblue; list-style-type: none; text-align: center; } #menu li.first { padding-left: 4%; } </style> </head> <body> <ul id="menu"> <li class="first"><a href="link1.html">Link 1</a></li> <li><a href="link2.html">Link 2</a></li> <li><a href="link3.html">Link 3</a></li> <li><a href="link4.html">Link 4</a></li> </ul> </body> </html> Each li tag has padding to the right only of 4% and the first li tag has a class for left padding 4% so that all spaces between li tags and at the sides are 4%. An alternative is to make the navbar a fixed width to suit your links and then center the navbar in any window width:- http://www.wickham43.net/dropdownmenus.php See item 4 where the menu is centered in a container in any window width.
August 21, 200917 yr Author Thanks for the comprehensive reply. Will give these methods a shot. Dan Here is code for a complete page with a flexible width navbar. All the widths are in % adding to 100%. It will work until the window width is so narrow that the link texts won't fit, then a link will drop to a lower line (you could add min-width to solve this). <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Flexible width navbar</title> <style type="text/css"> body { margin: 0; } ul { width: 100%; margin: 0; padding: 0; } #menu li { float: left; width: 20%; padding: 5px 4% 5px 0; background-color: skyblue; list-style-type: none; text-align: center; } #menu li.first { padding-left: 4%; } </style> </head> <body> <ul id="menu"> <li class="first"><a href="link1.html">Link 1</a></li> <li><a href="link2.html">Link 2</a></li> <li><a href="link3.html">Link 3</a></li> <li><a href="link4.html">Link 4</a></li> </ul> </body> </html> Each li tag has padding to the right only of 4% and the first li tag has a class for left padding 4% so that all spaces between li tags and at the sides are 4%. An alternative is to make the navbar a fixed width to suit your links and then center the navbar in any window width:- http://www.wickham43.net/dropdownmenus.php See item 4 where the menu is centered in a container in any window width.
Create an account or sign in to comment