0

I like minimalistic markup. And I'd like to learn a new thing or two :) hope you can help me!

I want a simple dropdown menu, only with CSS.

I have following structure:

<div>
<a>
<ul>

<a> should open the dropdown.

Can this be done?

I made a little fiddle for you.

http://jsfiddle.net/ZxbGq/

2 Answers2

0

It is posible. I like this method:

HTML

<ul>
    <li>
        <a href="">drop</a>
        <ul>
            <li>
                <a href="">inside drop</a>
            </li>
        </ul>
   </li>
</ul>

CSS

ul {
    list-style-type:none;
}
ul > li > ul{
    position:absolute;
    display:none;
}
ul > li > a{
    /*your top anchor properties*/
}
ul > li:hover > ul{
    display:block;
}

I've used the anchor's parent list object to declare the display of the inner unordered list as block. But if you'd prefer to use the anchor. use: ul > li > a:hover ul > li > ul{}.

The above selector should work, if not stick to the one I've provided. Good luck with the menu.

bashleigh
  • 8,813
  • 5
  • 29
  • 49
  • Yes, I've used this method all the time. But my question is different, can I do it with div -> ul? –  Nov 30 '12 at 15:51
  • I'm a little confused. But I'm guessing yes `div > ul` would work. I'd suggest using an ID for the div. – bashleigh Nov 30 '12 at 15:54
  • I understand now you want an element that is not in the current element to display on mouseover? A CSS version is only possible when the element you want to display is a child of the selector. You can use a javascript method or create a div surrounding the link and the loginboard. That will work – bashleigh Nov 30 '12 at 16:05
0

CSS Method:

<style>
    #showMe:hover > #loginboard{
        display:block;
    }
</style>
        <div id="showMe">
            <a id="logindd" onMouseover="sho()" href="#">Login</a>

            <ul id="loginboard">
                <li>
                    <form method="post" action="/wp-login.php" name="loginform">    
                        <input type="text" name="log" id="username">
                        <input type="text" name="pwd" id="password">
                        <label for="rememberme"><input type="checkbox" value="forever" id="rememberme" name="rememberme">Keep me signed in!</label>
                        <input type="submit" value="Sign in">
                    </form>
                    <span id="forgotpassword"><a href="#">Forgot Password?</a></span>
                    <span id="createaccountbtn"><a href="#">Create an account!</a></span>
                </li>
            </ul>
        </div>

JavaScript Method:

<script>
    function sho(){
        document.getElementById('loginboard').style.display = 'block';
    }
</script>

Both methods work but I'd prefer the CSS version. All you have to do is add the showMe div to your code and all should work.

bashleigh
  • 8,813
  • 5
  • 29
  • 49