I have a really simple menu that I'd like to add a drop-down. What do I need to do to add a drop down in here to one of the items?
http://www.cozinhatur.com/teste1/
HTML
<div class="menu">
<div class="search">
<form id="form1" name="form1" method="post" action="">
<label><span>
<input name="q" type="text" class="keywords" id="textfield" maxlength="50" value="Pesquisar..." />
</span>
<input name="b" type="image" src="images/search.gif" class="button" />
</label>
</form>
</div>
<ul>
<li>HOME</li>
<li>QUEM SOMOS</li>
<li>COZINHAS</li>
<li>DIVERSOS</li>
<li>PRODUTOS</li>
<li>CONTACTOS</li>
</ul>
<div class="clr"></div>
</div>
CSS
.menu
{
background:#5d5d5d;
margin:0 auto;
padding:0;
width:942px;
}
.menu ul
{
border:0;
float:left;
list-style:none;
margin:0;
padding:0;
text-align:left;
}
.menu ul li
{
border:0;
float:left;
margin:0;
padding:0 5px 0 0;
}
.menu ul li a
{
color:#fff;
float:left;
font-family:Verdana, Helvetica, Arial, sans-serif;
font-size:11px;
margin:0;
padding:15px;
text-decoration:none;
}
.menu ul li a:hover
{
background:#b57800;
}
.menu ul li a.active
{
background:#1caedd;
}
.menu ul li ul,.menu ul li ul a
{
font-family:Verdana, Helvetica, Arial, sans-serif;
font-size:11px;
}
Have made a simple CSS drop down from your menu. See jsFiddle Demo. Hover over the second and third menu items to see the drop down.
Hoping this will help you to further build to suit your needs.
The code changes....
HTML
<div class="menu">
<ul>
<li>HOME</li>
<li>QUEM SOMOS
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>COZINHAS
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</li>
<li>DIVERSOS</li>
<li>PRODUTOS</li>
<li>CONTACTOS</li>
</ul>
</div>
CSS
.menu {
background:#5d5d5d;
margin:0 auto;
padding:0;
width:942px;
}
ul {
border:0;
float:left;
list-style:none;
margin:0;
padding:0;
text-align:left;
}
ul li {
display: block;
position: relative;
float: left;
border:0;
float:left;
margin:0;
padding:0 5px 0 0;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #5d5d5d;
margin: 0px;
white-space: nowrap;
}
ul li a.active
{
background:#1caedd;
}
ul li a:hover {
background: #b57800;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a {
background: #5d5d5d;
}
li:hover li a:hover {
background: #b57800;
}
There is a good example here. The main point is when hovered show the sub menu.
http://www.red-team-design.com/css3-dropdown-menu
see this is pure css based dropdown menu:-
HTML
<ul id="menu">
<li>Home</li>
<li>About Us
<ul>
<li>The Team</li>
<li>History</li>
<li>Vision</li>
</ul>
</li>
<li>Products
<ul>
<li>Cozy Couch</li>
<li>Great Table</li>
<li>Small Chair</li>
<li>Shiny Shelf</li>
<li>Invisible Nothing</li>
</ul>
</li>
<li>Contact
<ul>
<li>Online</li>
<li>Right Here</li>
<li>Somewhere Else</li>
</ul>
</li>
</ul>
CSS
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #617F8A;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a {
background: #617F8A;
}
li:hover li a:hover {
background: #95A9B1;
}
see the demo:- http://jsfiddle.net/XPE3w/140/
Related
I have a menu bar which has 8 to 9 menus horizontally of different character length.
Also, each and every menu has sub menus of different character length.
All I want is -
1. all the menus should be across the page (should fill the html body width that i have decided)
2. all the sub menus should be drop down and will be of same width like as the parent menu width.
All i can do is, i have stretched menu bar so that it can fill the html body width and they took symmetrical width. but i cannot make the sub menus to be drop down one after another.
I have also attched examplary pictures of what i want
HTML
<div id="header_menu">
<ul >
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>File Upload</li>
</ul>
</li>
<li>Inventory Inspection
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>Reprint</li>
<li>Inventory Report</li>
</ul>
</li>
<li>Reports
<ul>
<li>Insert</li>
<li>Search & Edit</li>
</ul>
</li>
</ul>
</div>
CSS
body
{
width: 80%;
margin-left: auto;
margin-right: auto;
text-align:center;
}
HTML is already provided. i'm providing the working CSS for me. hope
it else somebody else.
#header_menu {
height: 10%;
margin-bottom: 2px;
width: 100%;
}
#header_menu ul li ul {
position: absolute;
float: left;
}
#header_menu ul {
margin: 0px;
padding: 0px;
list-style-type: none;
display: table;
width: 100%;
height: 10%;
position: relative;
z-index: 597;
}
#header_menu ul li ul li a {
visibility: hidden;
height: 0px;
width: 100%;
}
#header_menu ul li:hover ul li a {
height: 10%;
visibility: visible;
width: 100%;
}
#header_menu ul li {
position: relative;
display: table-cell;
list-style-type: none;
}
#header_menu ul li a {
display: block;
color: #FFF;
text-decoration: none;
background-color: #333;
font-family: Meiryo, "Meiryo UI", "Microsoft Sans Serif", "MS Outlook";
font-weight: lighter;
font-size: 12px;
border-right-width: thin;
border-bottom-width: thin;
border-right-style: inset;
border-bottom-style: inset;
border-right-color: #999;
border-bottom-color: #999;
}
#header_menu ul li ul li {
width: 100%;
float: left;
}
#header_menu ul li a:hover {
font-family: Meiryo, "Meiryo UI", "Microsoft Sans Serif", "MS Outlook";
font-size: 12px;
font-weight: lighter;
background-color: #000;
}
There is jsfiddle example toked from CSS Menu Maker site
I made some little changes to simplify example.
Little update, nothing special
Update (fiddle too):
<div id='cssmenu'>
<ul>
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>File Upload</li>
</ul>
</li>
<li>Inventory Inspection
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>Reprint</li>
<li>Inventory Report</li>
</ul>
</li>
<li>Reports
<ul>
<li>Insert</li>
<li>Search & Edit</li>
</ul>
</li>
</ul>
</div>
and css :
#cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle; border:solid 1px blue; width:150px;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default; background-color:yellow;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 150px;}
#cssmenu ul ul li {float: none; margin-left:-1px; width:150px; border:solid 1px red;}
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; /*line-height: 1em;*/ text-decoration: none; }
It's not pretty but You can see the point.
Update (code changed):
#cssmenu
{
padding:0;
margin:0;
display:block;
}
a {text-decoration:none; color:black; width:100%; box-sizing:border-box; display:block;}
#cssmenu ul
{
position:relative;
margin:0;
padding:0;
cursor:default;
display:table;
width:100%;
border:solid 1px gray;
}
#cssmenu ul li, #cssmenu ul li:last-child
{
list-style-type:none;
display:table-cell;
text-align:center;
vertical-align:middle;
padding-top:3px;
padding-bottom:3px;
border-right:solid 1px gray;
margin:0;
position:relative;
}
#cssmenu ul li:last-child {border:none;}
#cssmenu ul li:hover {background-color:yellow;}
#cssmenu ul li:hover > a {color: red;}
#cssmenu ul ul
{
visibility:hidden;
position:absolute;
top:100%;
margin:0;
margin-left:-1px;
z-index:101;
display:block;
}
#cssmenu ul ul li, #cssmenu ul ul li:last-child
{
display:block;
width:100%;
box-sizing:border-box;
border:none;
border-bottom:solid 1px gray;
}
#cssmenu ul ul li:last-child {border:none;}
#cssmenu ul ul li:hover
{
background-color:navy;
}
#cssmenu ul li li:hover > a {color:white;}
#cssmenu ul li:hover > ul {visibility:visible;}
<div id='cssmenu'>
<ul>
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>File Upload</li>
</ul>
</li>
<li>Inventory Inspection
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>Reprint</li>
<li>Inventory Report</li>
</ul>
</li>
<li>Reports
<ul>
<li>Insert</li>
<li>Search & Edit</li>
</ul>
</li>
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>File Upload</li>
</ul>
</li>
<li>Inventory Inspection
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>Reprint</li>
<li>Inventory Report</li>
</ul>
</li>
<li>Reports
<ul>
<li>Insert</li>
<li>Search & Edit</li>
</ul>
</li>
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>File Upload</li>
</ul>
</li>
<li>Inventory Inspection
<ul>
<li>Insert</li>
<li>Search & Edit</li>
<li>Reprint</li>
<li>Inventory Report</li>
</ul>
</li>
<li>Product Repository
<ul>
<li>Insert</li>
<li>Search & Edit</li>
</ul>
</li>
</ul>
</div>
Try this solution, but when You Run code snippet switch it to Full Page. I hope so this is what You want. But, always but, if Your window is too small, You can't avoid item values in two rows.
I'm new to this - sorry if this is a silly problem. When I hover over the dropdown menu options, the submenu appears, but the background of the submenu has a width of 100%, like the main menu. How can I alter it so that the submenu has a width only of, say, the tab it originates from?
Also, apologies for messy coding. I was playing around with jquery so there are some unnecessary tags in there...
Here is the CSS code:
#menu {
float:left;
width:100%;
background-color:#f23918;
overflow:hidden;
position:relative;
}
#menu ul {
clear:left;
float:left;
list-style:none;
margin:0;
padding:0;
position:relative;
left:50%;
text-align:center;
}
ul li {
display:block;
float:left;
list-style:none;
margin:0;
padding:0;
position:relative;
right:50%;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
font-weight: bold;
color: #ffffff;
white-space: nowrap;
background-color: #f23918;
text-align: center;
padding: 10px;
text-transform: uppercase;
}
ul li a:hover {
background: #f29c18;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li { /*Controls dropdowns*/
float: none;
font-size: 11px;
}
li:hover a { background: #f23918;
}
li:hover li a:hover
{
background: #f29c18;
}
and Here is the HTML code:
<div id="menu">
<ul id="navbar">
<li class="active"><span>Home</span></li>
<li class="has-sub"><span>Alpaca Wool Products</span>
<ul class="submenu">
<li><span>Fur Hats</span></li>
<li><span>Capes</span></li>
<li><span>Ponchos</span></li>
<li><span>Shawls</span></li>
<li class="last"><span>Scarves</span></li>
</ul>
</li>
<li class="has-sub"><span>Home Décor</span>
<ul class="submenu">
<li><span>Rugs</span></li>
<li><span>Tapestries</span></li>
<li><span>Throws</span></li>
<li><span>Upholstery</span></li>
<li class="last"><span>Teddy Bears</span></li>
</ul>
</li>
<li><span>About Us</span></li>
<li class="last"><span>Artisans</span></li>
</ul>
</div>
Ok. Here a workout. There might better solution exists.
First you need to give a fixed height to div#menu. Also I dont think you need a float there. Remove overflow hidden and position relative.
#menu {
width:100%;
background-color:#f23918;
height: 38px;
}
Then for submenu add following
li ul {
display: none;
min-width: 100%;
white-space: nowrap;
}
Last solution actually credited to https://stackoverflow.com/a/13775531/2120162
Here you can find how it looks. https://jsfiddle.net/theprog/3h8wpx97/1/
Update: Fixed moving part. Thanks #dowomenfart
li ul {
display: none;
min-width: 100%;
white-space: nowrap;
position:absolute !important;
z-index: 100;
}
Rather than tweaking your code I rewrote a simplified version based on what you need.
$(document).ready(function () {
$("#navbar > li").mouseover(function () {
if (!$(this).hasClass("active")) {
$(this).addClass("active");
$(this).mouseout(function () {
$(this).removeClass("active");
});
}
});
});
#navbar {
background: #f23918;
padding: 0;
margin: 0;
font-size: 0; /*fix inline block gap*/
}
#navbar > li {
font-size: 16px;
list-style: none;
position: relative;
display: inline-block;
padding: 0;
margin: 0;
}
#navbar > li > a {
text-transform: uppercase;
text-decoration: none;
font-size: 16px;
font-weight: bold;
padding: 10px;
display: block;
color: #fff;
}
#navbar > li > a:hover,
#navbar > li.active > a,
#navbar > li > ul {
background: #f29c18;
}
#navbar > li > ul {
display: none;
white-space: nowrap;
padding: 0 0 5px;
margin: 0;
position: absolute;
left: 0;
top: 36px;
}
#navbar > li > ul > li {
display: block;
margin: 10px 20px;
padding: 0;
}
#navbar > li > ul > li > a {
color: #fff;
}
#navbar > li:hover > ul {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul id="navbar">
<li>
Item A
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
</ul>
</li>
<li>
Item B
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
</ul>
</li>
<li class="active">
Item C
<ul>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<li>Sub Item 3</li>
</ul>
</li>
<li>
Item D NoSub
</li>
</ul>
I am new in coding css, tried suggested answers related to my problem but nothing works, any help will be appreciated; I want to place my menu at the center of the page while retaining the container background covered the entire available width...
here is my html code:
<div id="nav">
<li>Home</li>
<li>About
<ul>
<li>History</li>
<li>Mission</li>
<li>Board of Directors</li>
<li>Location</li>
</ul>
<li>Facilities & Services
<ul>
<li>Services >>
<ul>
<li>Internal Medicine</li>
<li>OB-Gyne</li>
<li>Pediatrics</li>
<li>Surgery</li>
<li>Dental Care</li>
<li>Rehabilitation Medicine</li>
<li>Otorhinolaryngology(ENT)</li>
</ul>
<li>Facilities >>
<ul>
<li>Laboratory-Tertiary Level</li>
<li>Intensive & Critical Care</li>
<li>Nursery & Neonatal Care</li>
<li>Pediatric Intensive Care</li>
<li>Pulmonary Care</li>
<li>Ear Care Center</li>
<li>Hemodialysis Unit</li>
<li>Cardiac Diagnostics</li>
<li>Radiology Diagnostics</li>
<li>OB-Gyne Diagnostics</li>
</ul>
</ul>
</li>
<li>Healthcare Plans
<ul>
<li>Accredited HMOs</li>
<li>Executive Checkup</li>
<li>Credit Cards</li>
</ul>
</li>
<li>Doctors
<ul>
<li>""</li>
</ul>
</li>
<li>Careers</li>
<li>Archive</li>
<li>FAQ</li>
<li>Contact Us</li>
</ul>
</li>
</ul>
</div>
and my css code:
#nav {
Z-INDEX: 10;
text-align:center;
width: 100%;
height: 20px;
background: green;
position: relative;
padding:3px;
font-size: 13px;
list-style-type:none;
list-style-position:outside;
display:inline-block;
font-weight: bold;
line-height:1.5em;
float: none;
}
#nav-wrapper {
text-align: center;
}
#nav ul{
Z-INDEX: 10;
text-align:center;
position:relative;
width: 1000px;
display:inline-block;
margin:0;
padding:0;
background: none;
list-style-type:none;
list-style-position:outside;
line-height: 1.7em;
font-size: 13px;
float: none;
}
#nav li li{
Z-INDEX: 10;
text-align:left;
display:inline-block;
margin:0;
padding:0;
font-weight: normal;
list-style-position:outside;
border-bottom: 0.1em solid white;
color: #fff;
}
#nav a:link, #nav a:visited{
display:block;
padding:0px 5px;
color:#fff;
text-decoration:none;
background: green;
}
#nav ul a:hover{
Z-INDEX: 999;
background: light-green;
color: yellow;
position: relative;
}
#nav li ul a:hover{
Z-INDEX: 999;
background: green;
color: yellow;
position: relative;
}
#nav li li a:hover{
Z-INDEX: 999;
background: light-green;
color: yellow;
font-weight: bold;
position: relative;
}
#nav li a:hover{
background: light-green;
color: yellow;
Z-INDEX: 999;
position: relative;
}
#nav a:active{
color: yellow;
font-weight: bold;
}
#nav li{
float:left;
position:relative;
}
#nav ul {
position:absolute;
width:14em;
top:1.3em;
display:none;
}
#nav li ul a{
width:14.65em;
float:left;
}
#nav ul ul{
top:auto;
}
#nav li ul ul {
left:14.65em;
margin:0px 0 0 10px;
}
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul{
display:none;
}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul{
display:block;
}
You could wrap the #nav with another div.
<div id="wrap">
<div id="nav"></div>
</div>
Remove the width from #nav, and apply the following CSS:
#wrap {
background: green;
text-align: center;
}
jsFiddle here - it works.
is it possible to keep the position of the 2nd level billboard fixed to the top as opposed to moving down the page on hover?
Code
HTML
<ul id="nav">
<li>STUFF
<ul>
<li>STUFF
<ul>
<li>
<div>LINK LINK ></div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>LINK LINK ></div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>LINK LINK ></div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>LINK LINK ></div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>asdasdasd</div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>asdasdasd</div>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>
<div>asdasdasd</div>
</li>
</ul>
</li>
</ul>
</li>
<li>STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li>STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li>STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li>STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li>STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li class="navblue">STUFF
<ul>
<li>STUFF</li>
<li>STUFF</li>
</ul>
</li>
<li class="navorange">STUFF</li>
</ul>
CSS
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
}
#nav, #nav ul {
list-style-type: none;
list-style-position: outside;
position: relative;
line-height: 30px;
margin: 0;
padding: 0;
}
#nav li > a {
font-weight: bold;
display: block;
margin-top: -1px;
color: #fff;
text-decoration: none;
background-color: #008000;
padding: 0 10px;
width: 99px;
border-bottom: 1px solid #FFFFFF;
}
#nav li > a:hover {
background-color: #99CC00;
color: #000;
}
#nav li {
float: left;
position: relative;
margin-right: 1px;
}
#nav ul {
position: absolute;
display: none;
width: 12em;
top: 2.5em;
}
#nav li ul a {
width: 160px;
height: auto;
float: left;
line-height: 30px;
font-size: 12px;
font-weight: normal;
}
#nav ul ul {
top: auto;
}
#nav ul ul {
height: 299px;
width: 652px;
margin: 0;
padding: 0;
background-color: #999999;
}
#nav ul ul li {
padding: 20px;
}
#nav li.navblue a {
background-color: #3398CC;
}
#nav li.navorange a {
background-color: #FF9A02;
color: #FEFF00;
}
#nav li ul ul {
left: 14.9em;
margin-left: -2px;
}
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul {
display: none
}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul {
display: block
}
JavaScript/jQuery
window.addEvent('load', function () {
function mainmenu() {
$("#nav ul").css({display:"none"}); // Opera Fix
$("#nav li").hover(function () {
$(this).find('ul:first').css({visibility:"visible", display:"none"}).show(0);
}, function () {
$(this).find('ul:first').css({visibility:"hidden"});
});
}
$(document).ready(function () {
mainmenu();
});
})
Live Example
replace your current css with this:
<style type='text/css'>
body {font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#000000;}
#nav,#nav ul{list-style-type:none;list-style-position:outside;position:relative;line-height:30px;margin:0;padding:0;}
#nav li > a{font-weight:bold;display:block;margin-top:-1px;color:#fff;text-decoration:none;background-color:#008000;padding:0 10px;width:99px;border-bottom:1px solid #FFFFFF;}
#nav li > a:hover{background-color:#99CC00;color:#000;}
#nav li{float:left;margin-right:1px;}
#nav ul{position:absolute;display:none;width:12em;top:2.5em;}
#nav li ul a{width:160px;height:auto;float:left;line-height:30px;font-size:12px;font-weight:normal;}
#nav ul ul{top:0;}
#nav ul ul {height:299px;width:652px;margin:0;padding:0;background-color:#999999;}
#nav ul ul li {padding:20px;}
#nav li.navblue a{background-color:#3398CC;}
#nav li.navorange a{background-color:#FF9A02;color:#FEFF00;}
#nav li ul ul{left:14.9em;margin-left:-2px;}
#nav li:hover ul ul,#nav li:hover ul ul ul,#nav li:hover ul ul ul ul{display:none}
#nav li:hover ul,#nav li li:hover ul,#nav li li li:hover ul,#nav li li li li:hover ul{display:block}
</style>
Changes: remove relative position from #nav li and position #nav ul ul top:0
I'm trying to create a page with a navigation bar that has dropdown submenus. Unfortunately, something keeps going wrong: hovering over an option makes the submenu show up over the bar and list the submenu options horizontally.
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<title>Toy CSS</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<style>
/* -------------------------MAIN-MENU----------------------- */
#topmenu ul {
margin-left: 0; /* clears default margins */
padding-left: 0; /* clears default padding */
background-color: #036;
color: white;
float: left;
width: 100%; /* creates complete bar */
font-family: arial, helvetica, sans-serif;
}
#topmenu li {
display: inline;
}
/* ----------------------MAIN-MENU-LINKS-------------------- */
#topmenu a {
padding: 3px 10px;
}
#topmenu a:link, #topmenu a:visited {
padding: 0.2em 1em;
background-color: #036;
color: white;
float: left;
border-right: 1px solid #fff;
text-decoration: none; /* removes link underlining */
}
#topmenu a:hover {
color: #fff;
background-color: #369;
}
/* --------------------------SUBMENU------------------------ */
#topmenu li ul {
display: none;
background-color: #69f;
}
#topmenu li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0;
}
#topmenu li:hover li {
float: none;
}
#topmenu li:hover li a {
background-color: #69f;
border-bottom: 1px solid #fff;
color: #000;
}
#topmenu li li a:hover {
background-color: #8db3ff;
}
/* -------------------------------------------------------------------------------- */
.mainbox {
border: 2px solid black;
float: left;
margin: 10px 0px 0px 0px;
min-height: 500px;
padding: 20px;
width: 600px;
}
.mainbox ul li {
width: 500px;
}
.mainbox {
display: none;
}
</style>
</head>
<script>
$(function() {
$('#topmenu li a').click(function(e) {
e.preventDefault();
var tabContent = this.hash;
$(tabContent).show().siblings('.mainbox').hide()
});
});
</script>
<body>
<!-----------–-–-–-–--------TOP-MENU-------------------------->
<div id="topmenu">
<ul>
<li>
Option A
<ul>
<li>A1</li>
<li>A2</li>
<li>A3</li>
<li>A4</li>
<li>A5</li>
</ul>
</li>
<li>
Option B
<ul>
<li>B1</li>
<li>B2</li>
<li>B3</li>
<li>B4</li>
</ul>
</li>
<li>
Option C
</li>
</ul>
</div>
<!-----------–-–-–-–---------OPTIONS-------------------------->
<div id="optiona" class="mainbox">
<h2>Option A</h2>
<p>You've selected Option A. Here is a list.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
<div id="optionb" class="mainbox">
<h2>Option B</h2>
<p>You've selected Option B. Here is a list.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
<div id="optionc" class="mainbox">
<h2>Option C</h2>
<p>You've selected Option C. Here is a list.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</body>
</html>
Thanks so much for your help!
#topmenu ul li {
display: list-item;;
}
#topmenu ul li ul {
margin-top:25px !important;
}
Should do the trick...
See it in action
that root of the problem is that
#topmenu li {
display: inline;
}
is cascading, so that the submenu <li/>s are also inline. you should correct it with something like
#topmenu li li {
display: block;
}
and go from there :)