Results 1 to 3 of 3

Thread: [RESOLVED] Dropdown Menu - Styling Sub Menu

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Resolved [RESOLVED] Dropdown Menu - Styling Sub Menu

    I'm trying my hardest to create a dropdown menu but I'm running into some issues styling the dropdown menu. Currently this is my code with a JSFiddle:
    Code:
    /* Remove the bullets and margins/padding from the list */
    .menubar, .submenubar {
    	list-style-type: none;
    	display: inline;
    	margin: 0;
    	padding: 0;
    }
    
    /* Display the top items horizontally */
    .menubar li {
    	display: inline-block;
    }
    
    /* Set the width of the text in the list items and set their display to block */
    .menubar li a, .menubar li a {
    	display: block;
    	width: 5em;
    }
    
    /* Hide any drop down menus */
    .submenubar {
    	display: none;
    	left: 0;
    	position: absolute;
    	top: 48px;
    	visibility: hidden;
    }
    
    /* Display the sub items vertically */
    .submenubar li {
    	display: block;
    	float: left;
    }
    
    /* Display the drop down menus on hover */
    .menubar li:hover .submenubar {
    	display: block;
    	visibility: visible;
    }
    Code:
    <ul class="menubar">		
    	<li><a href="#">Top Menu1</a></li>
    	<li><a href="#">Top Menu2</a>
    		<ul class="submenubar">
    			<li><a href="#">Sub Menu1</a></li>
    			<li><a href="#">Sub Menu2</a></li>
    			<li><a href="#">Sub Menu3</a></li>
    		</ul>
    	</li>
    	<li><a href="#">Top Menu3</a></li>		
    </ul>
    What I would like to do is have the sub menu be vertical, but for whatever reason it's horizontal like the top menu is. I thought that displaying it as a block element and floating it to the left would do the trick.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Dropdown Menu - Styling Sub Menu

    For starters, you can remove the "visibility" properties; the show/hide is already handled by "display". Also remove the "float", as you want it to be a regular vertical <ul> for the dropdown.

    https://jsfiddle.net/o3wz20vz/2/

    A quick google found this example, which might help you see where to go from there: http://cssdeck.com/labs/another-simp...-dropdown-menu
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,753

    Re: Dropdown Menu - Styling Sub Menu

    Thanks for that! I also changed the Top and Left properties for my submenubar class to where both are now auto so that it drops down below it's top menu.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width