Grow your CSS skills. Land your dream job.

[Solved] CSS Menu with a Horizontal Sub Menu

  • # September 11, 2009 at 4:08 pm

    Horizontal CSS Menu with a Horizontal Sub Menu

    Hello All,
    I’ve been working on this site a long time and I think I am only 1 line of code off. I am building a Horizontal CSS drop down menu with a horizontal sub menu. It works correctly in IE 6, 7 & 8, but not in Firefox or Safari. Go figure! In Firefox and Safari the drop downs end up vertical instead of horizontally lining up side by side.

    I think I am only missing a "display: inline;" somewhere in my CSS, but I can’t seem to figure out where it goes. I’m new to this.

    Here’s my CSS code:

    Code:
    @charset “UTF-8″;

    /* SpryMenuBarHorizontal.css – version 0.6 – Spry Pre-Release 1.6.1 */

    /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */

    /*******************************************************************************

    LAYOUT INFORMATION: describes box model, positioning, z-order

    *******************************************************************************/

    /* The outermost container of the Menu Bar, an auto width box with no margin or padding */
    ul.MenuBarHorizontal{
    margin: 0;
    padding: 0;
    list-style-type: none;
    font-size: 100%;
    cursor: default;
    font-family:Arial, Helvetica, sans-serif;
    }
    /* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */
    ul.MenuBarActive{
    z-index: 1000;
    }
    /* Menu item containers, position children relative to this container and are a fixed width */
    ul.MenuBarHorizontal li {
    list-style-type: none;
    width: 128px;
    position: relative;
    text-align: left;
    cursor: pointer;
    float: left;
    margin: 0;
    padding: 0;
    }
    /* Submenus should appear below their parent (top: 0) with a higher z-index, but they are initially off the left side of the screen (-1000em) */
    ul.MenuBarHorizontal ul {
    margin: 0;
    padding: 0;
    z-index: 1020;
    cursor: default;
    width: auto;
    position: absolute;
    left: -1000em;
    }
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to auto so it comes onto the screen below its parent menu item */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible {
    left: auto;
    float: left;
    }
    /* Menu item containers are same fixed width as parent */
    ul.MenuBarHorizontal ul li {
    list-style-type: none;
    display: inline;
    width: 100%;
    }
    /* Submenus should appear slightly overlapping to the right (95%) and up (-5%) */
    ul.MenuBarHorizontal ul ul {
    position: absolute;
    margin: 95% 0 0 -5%;
    width: 100%;
    }
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible ul.MenuBarSubmenuVisible{
    top: 0;
    }

    /*******************************************************************************

    DESIGN INFORMATION: describes color scheme, borders, fonts

    *******************************************************************************/

    /* Submenu containers have borders on all sides */
    ul.MenuBarHorizontal ul
    {
    border: 0px solid #CCC;
    }
    /* Menu items are a light gray block with padding and no text decoration */
    ul.MenuBarHorizontal a{
    text-align:center;
    cursor: pointer;
    display: block;
    background-color: #CCCCCC;
    padding: 0.5em 0.75em;
    font-size: 13px;
    font-weight: bold;
    color: #000000;
    text-decoration: none;
    }
    li.MenuBarHorizontal-Drop a{
    text-align:center;
    cursor: pointer;
    display: block;
    background-color: #007FC4;
    padding: 0.5em 0.75em;
    font-size: 11px;
    font-weight: bold;
    color: #000000;
    text-decoration: none;
    }

    /* Menu items that have mouse over or focus have a blue background and white text */
    ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus{
    background-color: #007FC4;
    color: #000000;
    }
    /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and white text */
    /* — Rollover state — */
    ul.MenuBarHorizontal a.MenuBarItemHover, ul.MenuBarHorizontal a.MenuBarItemSubmenuHover, ul.MenuBarHorizontal a.MenuBarSubmenuVisible{
    background-color: #007FC4;
    color: #000000;
    }

    /*******************************************************************************

    SUBMENU INDICATION: styles if there is a submenu under a given menu item

    *******************************************************************************/

    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenu{
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenu{
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a “hover” background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenuHover{
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a “hover” background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenuHoverU{
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }

    /*******************************************************************************

    BROWSER HACKS: the hacks below should not be changed unless you are an expert

    *******************************************************************************/

    /* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */
    ul.MenuBarHorizontal iframe
    {
    position: absolute;
    z-index: 1010;
    filter:alpha(opacity:0.1);
    }
    /* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */
    @media screen, projection
    {
    ul.MenuBarHorizontal li.MenuBarItemIE
    {
    display: inline;
    float: left;
    background: #FFF;
    }
    }

    Any help would be so great!

    Thanks,
    -Katie

    # September 14, 2009 at 3:52 pm

    Please let me know if there’s any other info you need. I know my code is messy next to all you pros out there.

    If I don’t figure this out soon, I’ll be "living in a van down by the river!"

    Thanks,
    -Katie

    # September 15, 2009 at 3:00 pm

    So I have updated my CSS to be cleaner. The code is working beautifully in IE…but…still no luck in Safari & Firefox.

    I added position: relative; to the ul.MenuBarHorizontal li {
    It forced me to clean my code up a bit to get IE working again.

    New Code:

    Code:
    @charset “UTF-8″;

    /* SpryMenuBarHorizontal.css – version 0.6 – Spry Pre-Release 1.6.1 */

    /* Copyright (c) 2006. Adobe Systems Incorporated. All rights reserved. */

    /*******************************************************************************

    LAYOUT INFORMATION: describes box model, positioning, z-order

    *******************************************************************************/

    /* The outermost container of the Menu Bar, an auto width box with no margin or padding */
    ul.MenuBarHorizontal {
    cursor: default;
    list-style-type: none;
    margin: 0;
    padding: 0;
    }
    /* Set the active Menu Bar with this class, currently setting z-index to accomodate IE rendering bug: http://therealcrisp.xs4all.nl/meuk/IE-zindexbug.html */
    ul.MenuBarActive {
    z-index: 1000;
    }
    /* Menu item containers, position children relative to this container */
    ul.MenuBarHorizontal li {
    cursor: pointer;
    float: left;
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: relative;
    text-align: left;
    width: 128px;
    }
    /* Submenus should appear below their parent (top: 0) with a higher z-index, but they are initially off the left side of the screen (-1000em) */
    ul.MenuBarHorizontal ul {
    cursor: default;
    float: left;
    left: -1000em;
    list-style-type: none;
    margin: 0;
    padding: 0;
    position: absolute;
    text-align: left;
    width: 800px;
    }
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to auto so it comes onto the screen below its parent menu item */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible {
    left: auto;
    float: left;
    width: 100%;
    }
    /* Size of SubMenu container */
    ul.MenuBarHorizontal ul li {
    list-style-type: none;
    width: auto;
    }
    /* Submenus should appear slightly overlapping to the right (95%) and up (-5%) */
    ul.MenuBarHorizontal ul ul {
    position: absolute;
    margin: 95% 0 0 -5%;
    width: 100%;
    }
    /* Submenu that is showing with class designation MenuBarSubmenuVisible, we set left to 0 so it comes onto the screen */
    ul.MenuBarHorizontal ul.MenuBarSubmenuVisible ul.MenuBarSubmenuVisible {
    top: 0;
    }

    /*******************************************************************************

    DESIGN INFORMATION: describes color scheme, borders, fonts

    *******************************************************************************/

    ul.MenuBarHorizontal ul
    {
    border: 0px solid #CCC;
    }
    /* Menu items are a gray block with padding and no text decoration */
    ul.MenuBarHorizontal a {
    cursor: pointer;
    display: block;
    background-color: #CCCCCC;
    padding: 0.5em 0.75em;
    font-family:Arial, Helvetica, sans-serif;
    font-size: 13px;
    font-weight: bold;
    color: #000000;
    text-decoration: none;
    text-align:center;
    }
    /* Styles for the dropdown menu text */
    li.MenuBarHorizontal-Drop a {
    text-align:center;
    cursor: pointer;
    display: block;
    background-color: #007FC4;
    padding: 0.5em 0.75em;
    font-size: 11px;
    font-weight: bold;
    color: #000000;
    text-decoration: none;
    }

    /* Menu items that have mouse over or focus have a blue background and black text */
    ul.MenuBarHorizontal a:hover, ul.MenuBarHorizontal a:focus {
    background-color: #007FC4;
    color: #000000;
    }
    /* Menu items that are open with submenus are set to MenuBarItemHover with a blue background and black text */
    /* — Rollover state — */
    ul.MenuBarHorizontal a.MenuBarItemHover, ul.MenuBarHorizontal a.MenuBarItemSubmenuHover, ul.MenuBarHorizontal a.MenuBarSubmenuVisible {
    background-color: #007FC4;
    color: #000000;
    }

    /*******************************************************************************

    SUBMENU INDICATION: styles if there is a submenu under a given menu item

    *******************************************************************************/

    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenu {
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that have a submenu have the class designation MenuBarItemSubmenu and are set to use a background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenu {
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a “hover” background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal a.MenuBarItemSubmenuHover {
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }
    /* Menu items that are open with submenus have the class designation MenuBarItemSubmenuHover and are set to use a “hover” background image positioned on the far left (95%) and centered vertically (50%) */
    ul.MenuBarHorizontal ul a.MenuBarItemSubmenuHoverU {
    background-repeat: no-repeat;
    background-position: 95% 50%;
    }

    /*******************************************************************************

    BROWSER HACKS: the hacks below should not be changed unless you are an expert

    *******************************************************************************/

    /* HACK FOR IE: to make sure the sub menus show above form controls, we underlay each submenu with an iframe */
    ul.MenuBarHorizontal iframe
    {
    position: absolute;
    z-index: 1010;
    filter: alpha(opacity:0.1);
    }
    /* HACK FOR IE: to stabilize appearance of menu items; the slash in float is to keep IE 5.0 from parsing */
    @media screen, projection
    {
    ul.MenuBarHorizontal li.MenuBarItemIE
    {
    display: inline;
    float: left;
    background: #FFF;
    }
    }

    Anyone got any ideas?
    -Katie

    # September 15, 2009 at 4:03 pm

    I had a look at this earlier and couldn’t figure it out, though I didn’t spend too much time on it.

    Generally, if it’s perfect in IE but wrong in FF and Safari, there are some big coding problems.

    # September 15, 2009 at 4:27 pm

    I’ve removed all the

    display: inline;

    from the code at this point. Perhaps someone could just tell me where in the code it’s supposed to go, and I can troubleshoot from there.

    # September 15, 2009 at 7:53 pm

    Here’s a fantastic method of doing this, it was originally made for WordPress, but can be used for anything.

    http://www.faqpal.com/toolbar/3838

    # September 16, 2009 at 12:58 pm

    I found a way to do it with CSS but I had to start over with my coding.
    I’m going to write up a tutorial at some point.

    Thanks,
    -Katie

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".