I have a menu in HTML with submenus that are displayed when hovering over the main button, but I would like to know if it is possible to make the submenus appear when click on the button.
*Configurações Padrões*/ ul.menu,
.menu li,
.menu a {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
ul.menu ul {
position: absolute;
display: none;
}
ul.menu {
float: left;
font-family: Verdana, Geneva, sans-serif;
font-size: 15px;
padding: 0 5px;
margin: 0px -8px;
width: 100%;
position: fixed;
bottom: 0;
}
/* Configurações nivel 1*/
.menu li {
float: left;
width: auto;
position: relative;
}
.menu li a {
display: block;
padding: 0 20px;
line-height: 45px;
height: 45px;
float: left;
}
/* Configurações nivel 2*/
.menu li:hover>ul.submenu-1 {
display: block;
top: -145px;
left: 0;
padding: 5px;
width: 200px;
}
.menu ul.submenu-1 a {
width: 160px;
padding: 0 20px;
}
/* Configurações nivel 2*/
.menu li:hover>ul.submenu-2 {
display: block;
top: 0;
left: 135px;
padding: 5px;
width: 200px;
}
.menu ul.submenu-2 a {
width: 140px;
padding: 0 20px;
}
/* Configurações nivel 3*/
.menu li:hover>ul.submenu-3 {
display: block;
top: 0;
left: 195px;
padding: 5px;
width: 200px;
}
.menu ul.submenu-3 a {
width: 160px;
padding: 0 20px;
}
/*Configurações de cores*/
/*nivel 1*/
.menu {
background: #CCC;
}
.menu a {
color: #000;
}
.menu li:hover>a {
background: #999;
color: #fff;
}
/*nivel 2*/
.submenu-1 {
background: #999;
}
.submenu-1 a {
color: #fff;
}
.submenu-1 li:hover>a {
background: #666;
}
/*nivel 3*/
.submenu-2 {
background: #666;
}
.submenu-2 a {
color: #fff;
margin-top: -4px;
}
.submenu-2 li:hover>a {
background: #333;
}
/*nivel 3*/
.submenu-3 {
background: #333;
}
.submenu-3 a {
color: #fff;
}
.submenu-3 li:hover>a {
background: #000;
}
.menuul li:hover,
ul li.active {}
<ul class="menu">
<li>Iniciar
<ul class="submenu-1">
<li>Submenu 1
<ul class="submenu-3">
<li>Submenu 7</li>
<li>Submenu 8</li>
<li>Submenu 9</li>
</ul>
</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
<ul class="submenu-2">
<li>Submenu 4</li>
<li>Submenu 5</li>
<li>Submenu 6</li>
</ul>
</li>
</ul>
</li>
</ul>
I need something like the windows98 style button of this site:
http://osrollers.tumblr.com/
Add a click event to the list element.
Toggle the desired element with a CSS class via classList.toggle().
var menuLi = document.querySelector(".menu li");
var submenu1 = document.querySelector(".submenu-1");
menuLi.addEventListener("click", function() {
submenu1.classList.toggle("toggle-submenu-1");
});
*Configurações Padrões*/ ul.menu,
.menu li,
.menu a {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
ul.menu ul {
position: absolute;
display: none;
}
ul.menu {
float: left;
font-family: Verdana, Geneva, sans-serif;
font-size: 15px;
padding: 0 5px;
margin: 0px -8px;
width: 100%;
position: fixed;
bottom: 0;
}
/* Configurações nivel 1*/
.menu li {
float: left;
width: auto;
position: relative;
}
.menu li a {
display: block;
padding: 0 20px;
line-height: 45px;
height: 45px;
float: left;
}
/* Configurações nivel 2*/
.toggle-submenu-1 {
display: block !important;
top: -145px;
left: 0;
padding: 5px;
width: 200px;
}
/*.menu li:hover>ul.submenu-1 {
display: block;
top: -145px;
left: 0;
padding: 5px;
width: 200px;
}*/
.menu ul.submenu-1 a {
width: 160px;
padding: 0 20px;
}
/* Configurações nivel 2*/
.menu li:hover>ul.submenu-2 {
display: block;
top: 0;
left: 135px;
padding: 5px;
width: 200px;
}
.menu ul.submenu-2 a {
width: 140px;
padding: 0 20px;
}
/* Configurações nivel 3*/
.menu li:hover>ul.submenu-3 {
display: block;
top: 0;
left: 195px;
padding: 5px;
width: 200px;
}
.menu ul.submenu-3 a {
width: 160px;
padding: 0 20px;
}
/*Configurações de cores*/
/*nivel 1*/
.menu {
background: #CCC;
}
.menu a {
color: #000;
}
.menu li:hover>a {
background: #999;
color: #fff;
}
/*nivel 2*/
.submenu-1 {
background: #999;
}
.submenu-1 a {
color: #fff;
}
.submenu-1 li:hover>a {
background: #666;
}
/*nivel 3*/
.submenu-2 {
background: #666;
}
.submenu-2 a {
color: #fff;
margin-top: -4px;
}
.submenu-2 li:hover>a {
background: #333;
}
/*nivel 3*/
.submenu-3 {
background: #333;
}
.submenu-3 a {
color: #fff;
}
.submenu-3 li:hover>a {
background: #000;
}
.menuul li:hover,
ul li.active {}
<ul class="menu">
<li>Iniciar
<ul class="submenu-1">
<li>Submenu 1
<ul class="submenu-3">
<li>Submenu 7</li>
<li>Submenu 8</li>
<li>Submenu 9</li>
</ul>
</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
<ul class="submenu-2">
<li>Submenu 4</li>
<li>Submenu 5</li>
<li>Submenu 6</li>
</ul>
</li>
</ul>
</li>
</ul>
If you want activate the submenus on click, instead of mouse over, you have to use a small JavaScript code.
Please, see the comments in the snippet!
// collect each menu item
const links = document.querySelectorAll(".menu>li>a");
// run a loop
for (let i=0; i<links.length; i++)
{
// to bind a click event listener to each menu item
links[i].addEventListener("click", function()
{
// do stuff only if the current item has a submenu
if (this.nextSibling != null)
{
// cache the submenu of the current item
let submenu = this.nextSibling.nextSibling;
// check if the submenu is already visible
if (submenu.classList.contains("active"))
{
// if so, hide it
submenu.classList.remove("active");
}
else
{
// if not, show it
submenu.classList.add("active");
}
}
});
}
.submenu {
display: none;}
.submenu.active {
display: block;}
<ul class="menu">
<li>Main
<ul class="menu submenu">
<li>1
<ul class="menu submenu">
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
</ul>
</li>
<li>2</li>
<li>3
<ul class="menu submenu">
<li>3.1</li>
<li>3.2</li>
<li>3.3</li>
</ul>
</li>
</ul>
</li>
</ul>
Related
My issue is the Html/Css dropdown second level disappears ans I move the cursor, currently works fine on Safari on Iphone but no other browsers I have tried.
Seems to be something to do with the width in the CSS, if I set a fixed px value all seems to fuction but then it does not reize correctly for all screens.
All parameters are % based througout the site and so far that is working fine cross platform.
.third-level-menu {
position: absolute;
top: 0;
width: auto;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu>li {
height: 30px;
background: #FFF;
}
.third-level-menu>li:hover {
background: #FFF;
}
.second-level-menu {
position: absolute;
top: 30px;
left: 0;
height: auto;
width: auto;
list-style: none;
padding: 0;
margin: 0;
display: none;
z-index: 100;
}
.second-level-menu>li {
position: relative;
height: auto;
background: #FFF;
width: auto;
}
.second-level-menu>li:hover {
background: #FFF;
}
.top-level-menu {
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu>li {
position: relative;
float: left;
height: auto;
width: auto;
}
.top-level-menu>.style4 {
float: left;
height: auto;
position: relative;
width: auto;
padding-top: 0px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
.top-level-menu>li:hover {
background: #FFF;
}
.top-level-menu li:hover>ul {
/* On hover, display the next level's menu */
display: inline;
white-space: nowrap;
}
.top-level-menu a {
font: bold 14px Arial, Helvetica, sans-serif;
color: #093;
text-decoration: none;
padding: 0 0 0 10px;
display: block;
line-height: auto;
}
.top-level-menu a:hover {
color: #3F6;
white-space: nowrap
}
.top-level-menu a {
color: #093;
white-space: nowrap
}
<div id="topmenu">
<ul class="top-level-menu">
<li>Home</li>
<li class="style4">//</li>
<li>Eeeeeeeeee eeeeeeeeeee
<ul class="second-level-menu">
<li>Dddddddd</li>
<li>Dddddddddd</li>
<li>Dddddddddd</li>
</ul>
<li class="style4">//</li>
<li>AAAAAAAAAA
<ul class="second-level-menu">
<li>Two long words</li>
<li>Two very long words</li>
</ul>
<li class="style4">//</li>
<li>Two long words</li>
<li class="style4">//</li>
<li>two words
<ul class="second-level-menu">
<li>single</li>
<li>single</li>
<li class="style4">//</li>
</ul>
<li class="style4">//</li>
<li>Eeeeeee</li>
</ul>
</div>
There is a gap between your main menu and second level menu. Because of that your hover effect is no longer exist. To check try this code
.top-level-menu > li > a { border: 1px solid blue; }
.second-level-menu { border: 1px solid red; }
and to resolve this use
.top-level-menu > li > a { padding:8px 0px; }
Removing top:30px from .second-level-menu will fix the issue.
If you want some gap between the main menu and the second level menu. You can give some padding to the first menu option by adding below-given css -
.second-level-menu > li:first-child {
padding-top: 10px;
}
.third-level-menu {
position: absolute;
top: 0;
width: auto;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu>li {
height: 30px;
background: #FFF;
}
.third-level-menu>li:hover {
background: #FFF;
}
.second-level-menu {
position: absolute;
left: 0;
height: auto;
width: auto;
list-style: none;
padding: 0;
margin: 0;
display: none;
z-index: 100;
}
.second-level-menu>li {
position: relative;
height: auto;
background: #FFF;
width: auto;
}
.second-level-menu>li:hover {
background: #FFF;
}
.top-level-menu {
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu>li {
position: relative;
float: left;
height: auto;
width: auto;
}
.top-level-menu>.style4 {
float: left;
height: auto;
position: relative;
width: auto;
padding-top: 0px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
}
.top-level-menu>li:hover {
background: #FFF;
}
.top-level-menu li:hover>ul {
/* On hover, display the next level's menu */
display: inline;
white-space: nowrap;
}
.top-level-menu a {
font: bold 14px Arial, Helvetica, sans-serif;
color: #093;
text-decoration: none;
padding: 0 0 0 10px;
display: block;
line-height: auto;
}
.top-level-menu a:hover {
color: #3F6;
white-space: nowrap
}
.top-level-menu a {
color: #093;
white-space: nowrap
}
<div id="topmenu">
<ul class="top-level-menu">
<li>Home</li>
<li class="style4">//</li>
<li>Eeeeeeeeee eeeeeeeeeee
<ul class="second-level-menu">
<li>Dddddddd</li>
<li>Dddddddddd</li>
<li>Dddddddddd</li>
</ul>
<li class="style4">//</li>
<li>AAAAAAAAAA
<ul class="second-level-menu">
<li>Two long words</li>
<li>Two very long words</li>
</ul>
<li class="style4">//</li>
<li>Two long words</li>
<li class="style4">//</li>
<li>two words
<ul class="second-level-menu">
<li>single</li>
<li>single</li>
<li class="style4">//</li>
</ul>
<li class="style4">//</li>
<li>Eeeeeee</li>
</ul>
</div>
I need to display sub-sub-menu on hover of my sub-menu. So far I did code to display menu -> sub-menu on menu click, but to proceed I want a functionality to display sub-sub-menu on hover of my sub-menu. Can somebody help me to achieve the same?
var ddmenuitem = 0;
function jsddm_open() {
jsddm_close();
ddmenuitem = $(this).find('ul.submenu').css('display', 'block');
// $(this).find('div.subsubmenu').css('display','none');
}
function jsddm_close() {
if (ddmenuitem) ddmenuitem.css('display', 'none');
}
$(document).ready(function() {
$('#topnav > ul > li').bind('click', jsddm_open)
$('#topnav > ul > li > a').click(function(ev) {
if ($(this).hasClass('current')) {
ev.preventDefault();
}
if ($(this).attr('class') != 'active') {
$('#topnav ul li a').removeClass('active');
$(this).addClass('active');
}
});
});
#topnav {
float: left;
width: 600px;
height: 30px;
background: black;
margin-top: 10px;
position: relative;
font-size: 15px;
margin-left: 30px
}
#topnav ul {
list-style: none;
padding: 0px;
margin: 0px;
}
#topnav ul li {
float: left;
margin: 0;
padding: 0;
}
#topnav ul li a {
padding: 5px 15px;
color: red;
text-decoration: none;
display: block;
font-weight: bold;
}
#topnav ul li a:link {
color: red;
text-decoration: none;
}
#topnav ul li a:visited {
color: #FFF;
text-decoration: none;
}
#topnav ul li a:hover {
color: red;
text-decoration: none;
}
#topnav ul li a.active {
text-decoration: none;
color: black;
background: #e0e0e0;
}
#topnav ul li ul.submenu {
float: left;
padding: 4px 0;
position: absolute;
left: 0;
top: 30px;
display: none;
background: #e0e0e0;
color: #00537F;
width: 600px;
height: 30px;
}
#topnav ul li ul.submenu a {
display: inline;
color: #00537F;
padding: 4px 8px;
}
#topnav ul.submenu a:hover {
background-color: black;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="topnav">
<ul>sds
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
Try the following snippet without using jquery or javascript, you can get it done using only css. And have updated according to your question
#nav {
list-style: none inside;
margin: 0;
padding: 0;
text-align: center;
}
#nav li {
display: block;
position: relative;
float: left;
background: #000000;
}
#nav li a {
display: block;
padding: 0;
text-decoration: none;
width: 200px;
line-height: 35px;
color: #fff;
}
#nav li li a {
font-size: 80%;
}
#nav li:hover {
background: #ff0000;
}
#nav ul {
position: absolute;
padding: 0;
left: 0;
display: none;
}
#nav li:hover ul ul {
display: none;
}
#nav li:hover ul {
display: block;
}
#nav li li:hover ul {
display: block;
margin-left: 200px;
margin-top: -35px;
}
<div id="topnav">
<ul id="nav">
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data ⇒
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
you can try this
#menu {
background: #343434;
color: #eee;
height: 35px;
border-bottom: 4px solid #eeeded
}
#menu ul,
#menu li {
margin: 0 0;
padding: 0 0;
list-style: none
}
#menu ul {
height: 35px
}
#menu li {
float: left;
display: inline;
position: relative;
font: bold 12px Arial;
text-shadow: 0 -1px 0 #000;
border-right: 1px solid #444;
border-left: 1px solid #111;
text-transform: uppercase
}
#menu li:first-child {
border-left: none
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
color: #eee;
}
#menu li:hover > a,
#menu li a:hover {
background: #111
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 35px;
opacity: 0;
cursor: pointer
}
#menu label {
font: bold 30px Arial;
display: none;
width: 35px;
height: 36px;
line-height: 36px;
text-align: center
}
#menu label span {
font-size: 12px;
position: absolute;
left: 35px
}
#menu ul.menus {
height: auto;
width: 180px;
background: #111;
position: absolute;
z-index: 99;
display: none;
border: 0;
}
#menu ul.menus li {
display: block;
width: 100%;
font: 12px Arial;
text-transform: none;
}
#menu li:hover ul.menus {
display: block
}
#menu a.home {
background: #c00;
}
#menu a.prett {
padding: 0 27px 0 14px
}
#menu a.prett::after {
content: "";
width: 0;
height: 0;
border-width: 6px 5px;
border-style: solid;
border-color: #eee transparent transparent transparent;
position: absolute;
top: 15px;
right: 9px
}
#menu ul.menus a:hover {
background: #333;
}
#menu ul.menus .submenu {
display: none;
position: absolute;
left: 180px;
background: #111;
top: 0;
width: 180px;
}
#menu ul.menus .submenu li {
background: #111;
}
#menu ul.menus .has-submenu:hover .submenu {
display: block;
}
<nav>
<ul id='menu'>
<li><a class='home' href='/'>Home</a></li>
<li><a class='prett' href='#' title='Menu'>Menu</a>
<ul class='menus'>
<li class='has-submenu'><a class='prett' href='Dropdown 1' title='Dropdown 1'>Dropdown 1 + Sub Menu</a>
<ul class='submenu'>
<li>Sub Menu</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
</ul>
</li>
<li><a href='#' title='Dropdown 2'>Dropdown 2</a></li>
<li><a href='#' title='Dropdown 3'>Dropdown 3</a></li>
</ul>
</li>
</ul>
</nav>
How can I make it so that I can have both a horizontal and vertical navigation bar? I'm a big beginner baby at design and I'm trying to figure out what I'm doing wrong but I'm not sure how to have CSS on multiple links.
<body>
<div class="horizontallinks">
<ul>
<li> link1 </li>
<li>link 2</li>
<li>link 3</li>
<li>
<link 4</div>
<div class="verticallinks">
<ui>
<li>link a </li>
<li> link b</li>
<li> link c </li>
</div>
</ul>
</body>
css:
.horizontallinks {
position: fixed;
list-style-type: none;
margin-top: 70px;
margin-left: 300px;
padding: 0;
font-size: 18px;
overflow: hidden;
background-color: white;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.verticallinks {
position: fixed;
list-style-type: none;
padding: 0;
font-size: 18px;
margin-left: 45px;
margin-top: 165px;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li {
float: left;
}
li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.horizontallinks {
position: fixed;
list-style-type: none;
margin-top: 70px;
margin-left: 300px;
padding: 0;
font-size: 18px;
overflow: hidden;
background-color: white;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.verticallinks {
position: fixed;
list-style-type: none;
padding: 0;
font-size: 18px;
margin-left: 45px;
margin-top: 165px;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li {
float: left;
}
li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
<body>
<div class="horizontallinks">
<ul>
<li>link1</li>
<li>link 2</li>
<li>link 3</li>
<li>link 4</li>
</ul>
<div class="verticallinks">
<ul>
<li>link a</li>
<li>link b</li>
<li>link c</li>
</ul>
</div>
</div>
</body>
Try this
<body>
<h2 class="horizontallinks">
<ui class="make-inline">
<li>link1</li>
<li>link 2</li>
<li>link 3</li>
<li>link 4</li>
</ul>
</h2>
<div class="body-wrapper">
<div class="side-bar">
<ui>
<li>link a</li>
<li>link b</li>
<li>link c</li>
</ul>
</div>
<div class="body-style">
<!-- Body content -->
</div>
</div>
</body>
Would it not be better to create a horizontal menu for devices with large display and a vertical menu for devices with a smaller display?
css media classes (mdn link) can be used for this.
var close = document.getElementsByClassName("close");
var menu = document.getElementById("menu");
for (var i = 0; i < close.length; i++) {
close[i].addEventListener("click", function() {
menu.style.left = "-250px";
});
}
body {
margin: 0;
}
#menu {
display: block;
border-radius: 5px;
background-color: #496D89;
height: 50px;
}
#menu ul {
font-size: 0em;
display: block;
height: 100%;
font-size: 2rem;
margin: 0 auto;
padding: 0;
list-style: none;
}
#menu ul li {
line-height: 1.5em;
display: inline-block;
padding: 0 0.2em;
height: 100%;
}
#menu ul li:hover {
background-color: #294F6D;
border-radius: 5px;
}
#menu ul li a {
color: white;
}
#menu ul li a:visited {
color: #F9CEE7;
}
#menu .close {
display: none;
}
#media (max-width: 600px) {
#menu {
position: absolute;
display: inline-block;
width: 300px;
height: auto;
transition: left 1s;
}
#menu ul {
width: auto;
}
#menu ul li {
display: block;
}
#menu .close {
display: initial;
position: absolute;
right: 0;
top: 0;
width: 50px;
height: 50px;
font-size: 2rem;
border-radius: 5px;
border: none;
background-color: #123652;
color: white;
cursor: pointer;
text-shadow: 2px 2px black;
}
.close:active {
background-color: #042037;
text-shadow: none;
}
}
<nav id="menu" style="left:0px;">
<ul>
<li>Home
</li>
<li>Link1
</li>
<li>Link2
</li>
<li>Link3
</li>
<li>Link4
</li>
<li>Link5
</li>
</ul>
<button class="close">X</button>
</nav>
I have a drop down ul menu that is working in every browser except IE8. I have tried messing with the Z-index but haven't had much luck. When the user hovers over the first element, there is it displays the 2nd list as a drop down but then once the user tries to navigate to it, it disappears. Is there something else that I may be missing? Please help.
Here is the generated HTML:
<div id="topNav" class="topNavMenu">
<ul>
<li>Home</li>
<li><a rel="submenu1">Account Information</a></li>
<li><a rel="submenu2">Financial</a></li>
<li><a rel="submenu3">Pricing</a></li>
<li><a rel="submenu4">Operations</a></li>
<li><a rel="submenu5">Support</a></li>
<li><a rel="submenu6">Document Management</a></li>
<li><a rel="submenu7">Administration</a></li>
</ul>
<ul id="submenu1" class="ddsubmenustyle">
<li>Bill To/Ship To Search</li>
<li>Customer Account Information</li>
</ul>
<ul id="submenu2" class="ddsubmenustyle">
<li>Statement Search</li>
</ul>
<ul id="submenu3" class="ddsubmenustyle">
<li>Price Notification Summary</li>
</ul>
<ul id="submenu4" class="ddsubmenustyle">
<li>Online Environmental Compliance</li>
</ul>
<ul id="submenu5" class="ddsubmenustyle">
<li>Manage Profile</li>
<li>Administrative Interfaces</li>
</ul>
<ul id="submenu6" class="ddsubmenustyle">
<li>HES</li>
<li>Marketing Services</li>
<li>Sunoco University Classes</li>
<li>Credit Card Program Information</li>
</ul>
<ul id="submenu7" class="ddsubmenustyle">
<li>Create a New User</li>
<li>User Administration</li>
<li>Create a New Role</li>
<li>Maintain Menu Items</li>
<li>Refresh Menu</li>
</ul>
</div>
and the CSS:
/* Top navigation menu
topNavMenu = the class used on the menu div.
ddsubmenustyle = dropdown div css.
-----------------------------------------------------------*/
.topNavMenu ul
{
margin: 0;
padding: 0;
font: bold 12px Verdana;
list-style-type: none;
background: #C3C9D9; /* #153371 */
overflow: hidden;
width: 100%;
background-image:url(../images/menu_bg.png);
height:35px;
float:left;
}
.topNavMenu li
{
display: inline;
margin: 0;
z-index: 100;
}
.topNavMenu li a
{
float: left;
display: block;
text-decoration: none;
margin: 0;
padding: 0px 10px; /*padding inside each tab*/
border-right: 1px solid white; /*right divider between tabs*/
color: black;
background: #6c94b0; /* #153371 */
background-image:url(../images/menu_bg.png);
height:35px;
line-height:35px;
font-family:Verdana, Arial, Helvetica, sans-serif;
/*font-size:10px;*/
}
.topNavMenu li a:visited
{
color: black;
}
.topNavMenu li a:hover
{
background:#4D77A7; /*background of tabs for hover state */
color:White;
text-decoration:bold;
}
.topNavMenu a.selected
{
background: #4D77A7; /*background of tab with "selected" class assigned to its LI */
color:White;
}
.ddsubmenustyle, .ddsubmenustyle div
{ /*topmost and sub DIVs, respectively*/
font: normal 12px Verdana;
margin: 0;
font-weight:bold;
padding: 0;
position: absolute;
left: 0;
top: 0;
list-style-type: none;
background: white;
border-bottom-width: 0;
visibility: hidden;
z-index: 300;
}
.ddsubmenustyle ul
{
margin: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
list-style-type: none;
border: 0px none;
z-index: 300;
}
.ddsubmenustyle li a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-color: #aec6f6;
text-decoration: none;
padding: 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
line-height:24px;
z-index: 300;
}
.ddsubmenustyle li ul li a, .ddsubmenustyle li ul li:first-child a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-color: #aec6f6;
text-decoration: none;
padding: 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
line-height:24px;
background-image:none;
-moz-border-bottom-radius: none;
-webkit-border-bottom-radius: none;
-khtml-border-bottom-radius: none;
border-bottom-radius: none;
}
.ddsubmenustyle li:first-child a
{
display: block;
width: 170px; /*width of menu (not including side paddings)*/
color: white;
background-image:url(../images/arrow_first-child.png);
background-repeat:no-repeat;
background-position:top left;
background-color: #4D77A7;
text-decoration: none;
padding: 16px 5px 4px 5px;
border-bottom: 1px solid white;
background-color:#4D77A7;
}
.ddsubmenustyle li ul li:last-child a
{
-moz-border-bottom-right-radius: 0px;
-webkit-border-bottom-right-radius: 0px;
-khtml-border-bottom-right-radius: 0px;
border-bottom-right-radius: 0px;
-moz-border-bottom-left-radius: 0px;
-webkit-border-bottom-left-radius: 0px;
-khtml-border-bottom-left-radius: 0px;
border-bottom-left-radius: 0px;
border-bottom: none;
}
.ddsubmenustyle li ul li a:hover
{
background-color:#4D77A7;
color: 40638A;
line-height:24px;
}
.ddsubmenustyle li:last-child a
{
-moz-border-bottom-right-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-khtml-border-bottom-right-radius: 5px;
border-bottom-right-radius: 5px;
-moz-border-bottom-left-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-khtml-border-bottom-left-radius: 5px;
border-bottom-left-radius: 5px;
}
* html .ddsubmenustyle li
{ /*IE6 CSS hack*/
display: inline-block;
width: 170px; /*width of menu (include side paddings of LI A*/
}
.ddsubmenustyle li a:hover
{
background-color:#38587C;
color: white;
line-height:24px;
}
/* Neutral CSS */
.downarrowpointer
{ /*CSS for "down" arrow image added to top menu items*/
padding-left: 4px;
border: 0;
}
.rightarrowpointer
{ /*CSS for "right" arrow image added to drop down menu items*/
position: absolute;
padding-top: 3px;
left: 100px;
border: 0;
}
.ddiframeshim
{
position: absolute;
z-index: 500;
background: transparent;
border-width: 0;
width: 0;
height: 0;
display: block;
}
I tried to view this in Chrome but couldn't get it to work properly. Why are the sub-menus separate ul's? Perhaps you could try a nested list, like this:
<nav>
<ul class="top-nav">
<li>
Item 1
<ul class="sub-nav">
<li>Item 1a</li>
<li>Item 1b</li>
<li>Item 1c</li>
</ul>
</li>
<li>
Item 2
<ul class="sub-nav">
<li>Item 2a</li>
<li>Item 2b</li>
<li>Item 2c</li>
</ul>
</li>
</ul>
</nav>
And here's some CSS to make it work:
* {
margin: 0;
padding: 0;
list-style: none;
color: inherit;
text-decoration: none;
}
body {
font-family: sans-serif;
}
nav {
margin: 0 auto;
}
.sub-nav {
display: none;
}
.sub-nav li {
background: #333;
color: #fff;
padding: 4px 2px;
border-bottom: 1px solid #e0e0e0;
}
.top-nav {
overflow: hidden;
}
.top-nav > li {
float: left;
width: 100px;
padding: 4px 0;
background: #e0e0e0;
}
.top-nav > li:hover ul {
display: block;
}
Just tested in Chrome and IE, and worked fine.
I have this CSS dropdown menu. I want the homepage to start on the left side of the page, not on the center. Herein is the style sheet and the div tags for the dropdown navigation bar:
ul, li, html, a
{
margin:0; padding: 0;
}
body
{
text-align: center;
margin: 0 auto;
padding: 0;
font: 65% arial, sans-serif;
}
li
{
list-style-type: none;
}
a
{
text-decoration: none;
color: #034af3;
}
ul#nav
{
width: 22.5em;
height:2.5em;
margin: 2em auto 0;
font-size: 1.5em;
}
ul#nav li
{
position: relative;
float: left;
width: 5em;
height: 2em;
line-height: 2em;
background-color: #465c71;
display: block;
padding: 4px 0px;
border-right: 1px #4e667d solid;
color: #dde4ec;
}
ul#nav li.noBorder
{
border-right: none;
}
ul#nav li:hover
{
background-color: silver;
}
ul#nav li a
{
display: block;
float: left;
width: 100%;
}
ul#nav li ul
{
display: none;
}
ul#nav li:hover ul
{
display: inline;
float: left;
width: 10em;
height: auto;
margin: 0; padding: 0.27em;
font-size: 1em;
text-align: left;
}
ul#nav li:hover ul li
{
width: 100%;
height: 2em;
background-color: Yellow;
border: none;
border-bottom: 1px solid silver;
overflow: hidden;
}
ul#nav li:hover ul li a
{
display: block;
margin: 0; padding: 0 0 0 .3em;
height: 100%;
line-height:2em;
color: #465c71;
}
ul#nav li:hover ul li a:hover
{
background-color: white;
}
<div style="background:#3a4f63;">
<ul id="nav">
<li>Home</li>
<li>Abour
<ul>
<li>About 1</li>
<li>About 2</li>
<li>About 3</li>
<li class="noBorder">About 4</li>
</ul>
</li>
<li>Blog
<ul>
<li>About 1</li>
<li>About 2</li>
<li>About 3</li>
<li class="noBorder">About 4</li>
</ul>
</li>
<li class="noBorder">Contact</li>
</ul>
</div>
Try:
body { text-align: left; }
ul#nav { margin: 2em 0 0; }