0

I set up a menu that uses buttons with links, ul's, and li's inside them. It works fine in Chrome, Android, Safari, and Opera. In Firefox, when the ul's appear the nav jumps down. In IE, the ul's don't display. In both, the links don't appear.

Edit: I chose to do this with buttons because i thought it gave me flexibility a regular ul menu wouldn't - background images, images inside them, attaching javascript events. It also of course creates a layout that is a row of buttons without any extra styling.

http://codepen.io/briligg/pen/emwXaw?editors=110

nav {       position: fixed;
            top: 0px;
            right: 0px;
            width: 70%;
            float: right;
            padding: 2%;
            height: 34px;
            max-height: 34px;
            margin: 5px 0;
            }
nav button {
            border: 1px solid #666666;
            border-radius: 10px;
            background-color: #3b4c6d;
            color: white;
            padding: 0 4px;
            height: 32px;
            font: 16px;
}

nav button ul {
            position: relative;
            display: none;
}
nav button:hover ul, nav button:focus ul {
            display: block;
            z-index: 7;
            list-style: none;
            background-color: #3b4c6d;
            border: 1px solid #666666;
            border-radius: 10px;
      margin-top: 9px;
            padding: 6px 2px;
}
nav button:hover li, nav button:focus li {
            padding: 8px 2px;
}
nav a {
        text-decoration: none;
        color: white;
}
nav a:hover, nav a:focus {
            color: #52cbff;
}

Then in the html, the ul's are nested in the buttons, with links, like this:

<button tabindex="4"><a href="beingthere.html">Being There</a>
<ul tabindex="5">
        <li><a href="beingthere.html#domination">World Domination</a></li>
        <li><a href="beingthere.html#chickens">Chickens</a></li>
        <li><a href="beingthere.html#gravity">Down with Gravity</a></li>
        <li><a href="beingthere.html#moonstar">The Moonstar</a></li>
        </ul>
</button>

In even creating this thing i was already at the limits of my knowledge. I don't know how to go about finding work-arounds, or if that is even possible in this case. Help with even knowing where to go to figure this out would be appreciated, never mind an actual solution to the problem. I've been looking for information and haven't found any.

kim holder
  • 1,744
  • 3
  • 16
  • 25
  • IE 10. I presume that means earlier versions won't work either. – kim holder Apr 13 '15 at 23:07
  • @sdcr - am doing so. The big revelation was really the link-in-button question you linked to. I was doing a no-no, messing with the pretty semantics. I'll take your recommendation and cut out the buttons. Drama? Oh, not at all. I appreciate the help. – kim holder Apr 14 '15 at 18:42

2 Answers2

1

IE has button {overflow:hidden;} style by default, You can rest that as follows.

nav button {
    overflow: visible;
}

Edit: In order to get the links working we'll have to redo the markup, I also adjusted the CSS for the HTML changes. see the following code snippet.

nav {
  position: fixed;
  top: 0px;
  right: 0px;
  width: 70%;
  float: right;
  padding: 2%;
  height: 34px;
  max-height: 34px;
  margin: 5px 0;
  white-space: nowrap;
}
nav > ul > li {
  display: inline-block;
  position: relative;
  font-size: 16px;
  height: 32px;
  line-height: 32px;
  border: 1px solid #666666;
  border-radius: 10px;
  background-color: #3b4c6d;
  color: white;
  padding: 0 4px;
}
nav > ul > li > ul {
  display: none;
  list-style: none;
  background-color: #3b4c6d;
  border: 1px solid #666666;
  border-radius: 10px;
  padding: 6px;
  position: absolute;
  z-index: 7;
  top: 32px;
  left: 0;
}
nav > ul > li:hover > ul {
  display: block;
}
nav a {
  text-decoration: none;
  color: white;
}
nav a:hover {
  color: #52cbff;
}
<nav>
    <ul>
        <li tabindex="1"><a href="futuremoon.html#begin">Purpose</a></li>
        <li tabindex="2">
            <a href="moonvsmars.html">Moon vs Mars</a>
            <ul tabindex="3">
                <li><a href="moonvsmars.html#ambiance">Ambiance</a></li>
                <li><a href="moonvsmars.html#communication">Communication</a></li>
                <li><a href="thereandback.html">There and Back</a></li>
            </ul>
        </li>
        <li tabindex="4">
            <a href="beingthere.html">Being There</a>
            <ul tabindex="5">
                <li><a href="beingthere.html#domination">World Domination</a></li>
                <li><a href="beingthere.html#chickens">Chickens</a></li>
                <li><a href="beingthere.html#gravity">Down with Gravity</a></li>
                <li><a href="beingthere.html#moonstar">The Moonstar</a></li>
            </ul>
        </li>
    </ul>
</nav>

The problem must be caused by this Link inside a button not working in Firefox (and IE).

Full Demo: http://codepen.io/anon/pen/KwOqKv

Community
  • 1
  • 1
Stickers
  • 75,527
  • 23
  • 147
  • 186
  • I can add "a:focus" to the a:hover tag, right? Because that is partly how i got into this, i was trying to make the menu easy to interact with on a touchscreen. – kim holder Apr 14 '15 at 19:01
  • @briligg I guess so, you can try it, but I can't be sure, we normally use :focus on form elements, such as button, input etc. If that didn't work also try :active. – Stickers Apr 14 '15 at 19:04
  • yeah... it won't work to make the nested ul visible, and li tags don't support :focus. So i'm back to javascript. – kim holder Apr 14 '15 at 19:24
1

Instead of putting <a> in <button>, put all <a> inside <li>. Also, as you had, put the secondary links inside another <ul> in the <li>.

<ul class='primary-links'>
    <li class='primary'><a href='#'>Primary link</a></li>
    <li class='primary'>
        <a href='#'>Another primary link</a>
        <ul class='secondary-links'>
            <li class='secondary'><a href='#'>Secondary Link</a></li>
            <li class='secondary'><a href='#'>Another secondary link</a></li>
        </ul>
    </li>
</ul>

The primary links are display:inline-block in order for them to display horizontally while the secondary links are display:none to initially hide them. The secondary links become visible when the primary links are hovered over. position:absolute removes the secondary links from the document flow preventing the primary links from jumping down when the secondary links become visible.

.primary {
    display: inline-block;
}

.secondary-links {
    display: none;
    position: absolute;
}

.primary:hover > .secondary-links {
    display: block;
}

body {
     font: 1em/1.5 sans-serif;
}

a:link,
a:visited {
    color: #08f;
    text-decoration: none;
}

a:hover,
a:active,
a:focus{
    color: #f80;
}

ul {
    list-style: none;
    margin: 0;
  
    padding: .25em;
    border-radius: .25em;
    background: #fff;
    border: thin solid #ccc;
    box-shadow: 0 0 .25em #ccc;
}

li {
    margin: .5em;
}

nav > ul > li {
    display: inline-block;
}


li > ul {
    display: none;
    position: absolute;
}

li:hover > ul {
    display: block;
}
<nav>
    <ul>
        <li><a href='#'>One</a></li>
        <li>
            <a href='#'>Two</a>
            <ul>
                <li><a href='#'>Two One</a></li>
                <li><a href='#'>Two Two</a></li>
                <li><a href='#'>Two Three</a></li>
            </ul>
        </li>
        <li>
            <a href='#'>Three</a>
            <ul>
                <li><a href='#'>Three One</a></li>
                <li><a href='#'>Three Two</a></li>
                <li><a href='#'>Three Three</a></li>
                <li><a href='#'>Three Four</a></li>
            </ul>
        </li>
    </ul>
</nav>
David
  • 383
  • 10
  • 18
  • This is how it is usually done, i've built menus like this. It doesn't have the button style layout i'd wanted. And i wanted to take advantage, later, of the ability to give buttons background images, put images inside them, and attach events to them. This is a good, clear guide to how to build a dropdown menu, but i'm not sure i can get it to do what i want. – kim holder Apr 14 '15 at 18:16
  • Update: sdcr made me aware that what i wanted to do is frowned upon because it tangles different interactive tags together. So i'll do the list up properly. – kim holder Apr 14 '15 at 18:45