Support » Fixing WordPress » How to implement navigational menu code?

  • Resolved lutetia


    Hi all,

    I’ve created a working html/css horizontal navigation menu using a text editor. In the file, I have the CSS styling at the top and the html for my menu at the bottom.

    It works the way it’s supposed to when I do a web preview in TextMate.

    Now I’d like to add it to my site, but I’m not sure what the best way to do this is.

    Should I add the relevant CSS code in my theme’s style sheet and then paste the html code in my header file?

    Or should I upload the working menu as a single file to my theme files and “call” that from the header? If so, do I create a php file for this purpose, or should it be an html file? How would I call the menu?

    Any advice would be much appreciated.

Viewing 15 replies - 1 through 15 (of 19 total)
  • You should consider using WordPress to manage your navigational links. I have used this technique (with small modifications) on my own site, and it works well. There is an article here that explains how to do it:

    Easy navigation menus in WordPress

    If you don’t want to go that route, then yes, simply pasting the HTML code into your header.php should work, since you want the navigation to appear consistently on every page.

    Thank you Ambrosite.

    That article looks interesting, though it says that drop down menus aren’t easy using that method….

    I have a horizontal menu of 10 items, with 6 of them having drop downs of 1 to 5 items each. I made the menu the exact width of my page (980 px).

    I looked at the Codex and it says short menus are OK in WordPress but that longer ones can run into problems with layout.

    I added the CSS to my style sheet and tried pasting the html part of the code into the bottom of the header, but the menu doesn’t display as nicely as it did in TextMate web preview, i.e. the font size appears much smaller, despite the CSS styling.

    Also tried pasting it in the Main Index Template, after the call for the header, then within the wrapper, but could not get it to work (did not display at all).

    Shane, thanks for those links. Maybe I should find a plugin…

    My site is a “static site”. I had previously looked at the PixoPoint Dropdown Menu plugin but couldn’t find a way to create side-by-side dropdowns for different groups of pages. And after scouring their forums it seems lacking in user documentation and support.

    So I just spent the last 24 hours struggling to create my navbar from scratch… Finally got it to work, but it looks like I won’t be able to use it on my site after all 🙁

    If the font size appears much smaller, it is probably because of nested relative font sizes. That is, if you nest the menu inside a web page where the font-size on the body has been set to 62.5% (a common technique in WordPress themes), then your menu fonts will be 62.5% of the size you expect them to be. You can counteract that by setting the font-size on your menu to something like 160% (play around with different percentages to find the right value).

    OK, thanks for that tip. I’ll give it a try.

    Just looking at those plugins, and they seem too complicated for me. I’d rather find a way to get my own menu to work if at all possible.

    Tried changing the font-size to 140% then 160% but this made no difference to the small text size, though what you say makes sense (in my theme the text is set to 62.5%…)

    I have other problems too, i.e. with the super small text, there seems to be a lot of extra space showing up above and below lines of text in the menu items, causing it to overflow beyond the bottom border of the menu…

    For example, some of my menu items had text on two lines within a menu bar height of 37px. When I paste my code into my header as is, the text shrinks, yet the second line appears below the bottom of the actual menu bar (seems like extra padding). So when I hover one one item, the dropdown of that item runs into the overflow of the second item….

    Hmm, I guess it’s back to the drawing board…

    Are you sure you’re targeting the menu correctly with your CSS selector? Changing the font-size should definitely have had some visible effect, unless the change is being overridden by some other selector with higher specificity elsewhere in the CSS file. What if you change some other attribute like color? Does that have any effect?

    This is literally my first attempt at composing CSS and I’m not sure what you mean by “targeting the menu correctly”….

    I followed this online tutorial ( and watched the entire 20-minute video at least 5 or 6 times, writing my code in real-time according to the instructions, then checked and verified everything several times until I got it right.

    It’s actually working perfectly in TextMate.

    I have a feeling it’s just a small thing that’s keeping it from display properly in my site, but not sure how to troubleshoot it.

    I’ve pasted the CSS code for my list here if anyone would care to have a glance.

    This is the CSS I added to my theme’s stylesheet (after the footer stuff).

    I’m willing to look at this, however I need to see the entire CSS file for your theme, as well as the HTML. Is this site online somewhere I can get to it?

    Thank you! My site is here

    The CSS file is here

    I haven’t got the menu html posted in there at the moment, since it looks so bad.
    Should I post it in the header or in some other theme file?

    Yes, please post the menu HTML somewhere. I need to see how it is marked up. Actually, if you wouldn’t mind, please put it back in the header where you had it before, so I can see how it is being nested.

    OK, I’ve put it back in the header (at the bottom).

    I should probably add more space before the content.

    I see the problem. You have two selectors that are both targeting the “nav” id. The second selector is around line 290 in your CSS file, and it has an absolute font-size of 10px which is overriding the percentage font-size you set on your menu. The duplicate id is probably causing all of the other formatting problems as well.

    My suggested solution is to rename the “nav” id in your menu to “navmain”. You must then rename all the “#nav” selectors in your CSS to “#navmain”. That should solve the problem.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘How to implement navigational menu code?’ is closed to new replies.