
How do I have a shared CSS menu system?I love CSS. I would like to use CSS menus. I have seen several versions on the netover the last 12months (I currently use a javascript menu system). My biggest problem with these CSS menus is that you have to put the menu code into each HTML page as far as I can see). This means a menu change for a site must be updated in every page. This seems to go against the idea that CSS can be used to change the look and feel of an entire web site by just chnaging the external style sheet. Do you know of a way of putting CSS menus information in an external file that can be linked or imported into the HTML? Sure, this is actually pretty darn easy! Just look at the <link> tag. Or work by example: use View Source in your Web browser to view the HTML source to this very page and you'll see the following on about line six or so: <link rel="stylesheet"
href="http://www.askdavetaylor.com/styles-site.css" type="text/css" />
By adding that to all my HTML pages I have a single shared CSS file that can be as complex as I need, without any issues of having to edit multiple pages to make a stylistic or presentation tweak. If you need to include HTML and/or JavaScript too, you might instead look into server-side includes. I use those extensively throughout my Web sites too: <!--#include file="javascript-menu.html"-->
These let me have CSS, JavaScript, HTML, whatever else I need, neatly compartmentalized and easily edited. The best feature? That it's just a single include line you add to each page of my site. Finally, I spend a lot of time in my book Creating Cool Web Sites talking about JavaScript and CSS-based menu systems. It turns out that compatibility across a wide range of web browsers is darn hard and if you choose to build your own, you might well be setting yourself up for a never-ending litany of complaints from visitors whose browsers don't quite work properly. Instead, I've actually moved to simpler, less fancy site layouts in the interest of being compatible with the widest possible range of visitor applications, whether cell phones, wireless PDAs, Sony PSP users, or, now and then, an actual computer user. :-) Hope this helps you out!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
HTML and CSS
(Article 4186)
Tagged: Previous: Using my PC's CDROM drive freezes up Windows XP? Next: How do I create a new screen name in AOL (America Online) 9.0? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Have you tried PHP includes? The question was: "Do you know of a way of putting CSS menus information in an external file that can be linked or imported into the HTML." The answer you provided, while good information about linking to the CSS style sheet, doesn't address the question. Rephrased, the writer wanted to know if he could write CSS Menu code in a separate file, and then link that menu (NOT the stylesheet) into the html code for his other pages. Posted by: Ed Newbold at September 14, 2005 12:06 PMEd, using the PHP include as suggested by another commenter, or using the SSI include allows you to have arbitrarily complex material -- including a complete CSS menu solution -- neatly packaged into a separate file. Posted by: Dave Taylor at September 14, 2005 1:18 PMHi, Is there any way to INCLUDE a menu file into HTML. I have no experience with PHP. Something akin to: {.div class="Center_Box"} So I only have to maintain one file for all my pages. I could find no references to anything like that in Cool Web Sites. Thanks, Swede Posted by: Gösta H. Lovgren at October 10, 2005 3:04 AMYou certainly can, Gosta. Go back to my book and read up on Server Side Includes (or Google the phrase, for that matter). Posted by: Dave Taylor at October 11, 2005 7:08 AMGreat info about css stylesheets Dave. But, I'm still unanswered about how to put a menu into a stylesheet. I tried it and tried the javascript menu. I wish you'd write more on this topic. Posted by: Sara at May 31, 2006 12:17 PMI'm having the same problem I beleive. I want to include one menu on multiple pages that are in multiple directories, but when I open the page, and click on the menu it follows a path to the original directory that the menu was created in. Posted by: Jeff at February 27, 2008 4:42 PMWill this question ever be answered as I am also looking for the way to have my menu's in the CSS sheet and laoded into HTML so that I can change the CSS style sheet and it changes the menu on all the htmlpages at once. Cheers Posted by: spikey at September 8, 2009 7:44 AMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Book Links
|