Question

I want to set the second level of navigator to be auto height, change to a new line when too long.

HTML:

<ul id="menu">
    <li><a href="">About Us</a>
        <ul>
            <li><a href="">Introduction</a></li>
            <li><a href="">Orgaizational Structure</a></li>
            <li><a href="">Mission&Vision</a></li>
        </ul>
    </li>
</ul>

CSS:

* {
    padding: 0;
    margin: 0;
}

#menu {
    list-style: none;
    font-size: 0.8em;
    border-radius: 5px;
    -webkit-box-shadow: 0 5px 10px 0 #cccccc;
    box-shadow: 0 2px 5px 0 #aaa;

    background: #dddddd;
    height: 40px;
    width: 800px;
    float: left;
}

#menu li {
    display: block;
    position: relative;
    float: left;
}

#menu li ul {
    display: none;
}

#menu li a {
    display: block;
    text-decoration: none;
    padding: 12px 15px;
    margin-left: 1px;
    white-space: nowrap;
}

#menu li:hover ul {
    display: block;
    position: absolute;
    background: #dddddd;
    border-radius: 5px;
    -webkit-box-shadow: 0 5px 10px 0 #cccccc;
    box-shadow: 0 2px 5px 0 #aaa;
    width: 100px;
}

Run it here: http://jsfiddle.net/U72Hm/

Was it helpful?

Solution

I'm not sure what you are asking but if you want your text to wrap to a new line, change white-space:no-wrap; to white-space:normal for menu li a{...}.

OTHER TIPS

Whilst this answer doesn't technically answer the question, there are some excellent resources for menu's here http://www.cssplay.co.uk/menus/ explaining why certain CSS decisions are made and for which browsers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top