0

I have a horizontal navigation that I want to have a horizonyal sub nav come off of. The issue is where I am having the sub nav display inline while it has an absolute position. I know there are issues with using an inline display when you have an absolute position. It works how I want it to with a fixed display, but I do not want it to be fixed... Does anyone know an alternative to this? Also I can't just have a set width on the sub nav because each of the sub menu's are going to be different width's.

<style>
     ul li {
        float: left;
        position: relative;
    }

    #primary-nav ul li ul {
        position: relative;
        top: 42px;
        display: none;
        width:100%;

    }
    #primary-nav ul li ul li {
        list-style:none outside none;
        margin-left:20px;
        float:left;
        z-index: 1000;
    }
    #primary-nav ul li:hover ul {
        display:inline;
        position:absolute;
    }
</style>


<ul class="menu">
    <li>menu Item</li>
    <li>drop down</li>
        <ul class="submenu">
            <li>dropdown Item</li>
            <li>dropdown Item</li>
        </ul>
 </ul>
0

1 Answer 1

3

Here's a tinkerbin with the solution -> http://tinkerbin.com/NlqcJcL7

By applying white-space: nowrap to the absolutely positioned .submenu, you ensure it's children inline blocks don't collapse to the next line.

3
  • Makes sense in theory, but for some reason it did not work for me. maybe take a look at the issue live? test.kyrusmobile.com Commented Jul 3, 2012 at 16:39
  • 1
    The problem is that you floating the .menu-items in the .submenu. When you do that, they are treated as block level elements, so white-space: nowrap can't do what it's there to do. The fix is easy, obviously. Remove the float style (if you can't, override it with float: none). Then, also, remove the width:100% on the parent ul.submenu - you need it to be auto. That's it!
    – Paulo R.
    Commented Jul 3, 2012 at 19:18
  • I guess you actually don't need to remove the float from the .menu-items. The only thing messing the layout was the set width on .submenu. But then again, you don't need the float for nothing, so you'd be better by removing it.
    – Paulo R.
    Commented Jul 3, 2012 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.