I have to code the button below when its clicked it will display a dropdown menu.
How would I approach this as I have never come across this before.
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Geneva, sans-serif;
font-size: 100%;
color: #666;
}
body {
background-color: #fff;
margin-left: 20px;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 20px;
}
a, a:hover, a:active, a:focus {
outline:0;
direction:ltr;
}
.wrapper {
position:relative; height:25px;
}
.mainmenu {
position:absolute;
z-index:100;
font-family:Verdana, Geneva, sans-serif;
font-weight:normal;
font-size:90%;
line-height:25px;
left:50%;
margin-left:-303px;
width:606px;
}
ul.menu {
padding:0;
margin:0;
list-style:none;
width:100px;
overflow:hidden;
float:left;
margin-right:1px;
}
ul.menu a {
text-decoration:none;
color:#fff;
padding-left:5px;
}
ul.menu li.list {
float:left;
width:250px;
margin:-32767px -125px 0px 0px;
background:url(images/top1.png) no-repeat left bottom;
}
ul.menu li.list a.category {
position:relative;
z-index:50;
display:block;
float:left;
width:120px;
margin-top:32767px;
background:transparent;
}
ul.menu li.list a.category:hover,
ul.menu li.list a.category:focus,
ul.menu li.list a.category:active {
margin-right:1px;
background-image:url(images/tophover1.png);
background-repeat:no-repeat;
background-position:left top;
}
ul.submenu {
float:left;
padding:25px 0px 0px 0px;
margin:0;
list-style:none;
background-image:url(images/tophover1.png);
background-repeat:no-repeat;
background-position:left top;
margin:-25px 0px 0px 0px;
}
ul.submenu li a {
float:left;
width:120px;
background:#369;
clear:left;
}
ul.submenu li a.endlist {
background:url(images/bottom1.png);
}
ul.submenu li a.endlist:hover,
ul.submenu li a.endlist:focus,
ul.submenu li a.endlist:active {
background:url(images/bottomhover1.png);
}
ul.submenu a:hover,
ul.submenu a:focus,
ul.submenu a:active {
background:#900;
margin-right:1px;
}
-->
</style>
<div class="wrapper">
<div class="mainmenu">
<ul class="menu">
<li class="list">
<a class="category" href="#Home">Home</a>
</li>
</ul>
<ul class="menu">
<li class="list">
<a class="category" href="#about">About Us »</a>
<ul class="submenu">
<li>About link 1</li>
<li>About link 2</li>
<li>About link 3</li>
<li>About link 4</li>
<li><a class="endlist" href="#about5">About link 5</a></li>
</ul>
</li>
</ul>
<ul class="menu">
<li class="list">
<a class="category" href="#articles">Articles »</a>
<ul class="submenu">
<li>Articles link 1</li>
<li>Articles link 2</li>
<li>Articles link 3</li>
<li><a class="endlist" href="#articles4">Articles link 4</a></li>
</ul>
</li>
</ul>
<ul class="menu">
<li class="list">
<a class="category" href="#news">News »</a>
<ul class="submenu">
<li>News link 1</li>
<li>News link 2</li>
<li><a class="endlist" href="#news3">News link 3</a></li>
</ul>
</li>
</ul>
<ul class="menu">
<li class="list">
<a class="category" href="#donate">Donate</a>
</li>
</ul>
<ul class="menu">
<li class="list">
<a class="category" href="#contact">Contact</a>
</li>
</ul>
<!-- end mainmenu --></div>
<!-- end wrapper --></div>
or try this link
http://www.texaswebdevelopers.com/blog/template_permalink.asp?id=129
or
http://www.1stwebdesigner.com/css/38-jquery-and-css-drop-down-multi-level-menu-solutions/
I agree with Jerome C.
The only seggestion I can give you, is that usually there are many sites whose title is "the best NNN dropdownmenus" or substitute dropdownmenus with whatever.
Thery are usually helpful.
In such case:
http://www.hongkiat.com/blog/drop-down-menu-30-free-scripts-to-enhance-header-navigation/
Related
I am learning HTML5 and CSS. So my question is probably very basic and very naive. My apology for that.
To practice I am developing a header menu with drop down sub menu. I primarily hide the drop down menu by setting its display property to none, after hovering on the parent I set the display to block. But it seems like hover can't change the display value. Also it is worth mentioning that my html page is using flex box in order to have grid layout.
here is the html file:
<div class="menue">
<nav>
<ul>
<li>Home</li>
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
<li>Woman</li>
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
<li>Men</li>
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
<li>Kids</li>
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
<li>Flyers</li>
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
<li>Contact Us</li>
</ul>
</nav>
</div>
and here is the css file:
.menue {
background: #fc575e;
}
nav{
height:40px;
width: 960px;
display: block;
margin: 0,auto;
text-align: center;
text-transform: uppercase;
}
nav a{
display: block;
text-decoration: none;
font-size: 13px;
color: #112233;
}
nav ul{
list-style: none;
}
nav ul li{
float:left;
width:140px;
height:40px;
line-height: 40px;
background: #fc575e;
}
nav ul ul li{
position: relative;
display: none;
}
nav ul li:hover ul li{
display: block;
}
nav ul li:hover{
background-color: #223433;
color:#f0f1f5;
}
It seems like my hover action does not doing its job to change the display value of sub-menu to block.
I was wondering if some one could give me a hint?
It is really appreciated.
your css seems to be working fine. what you want to do is wrap both the <a> and <ul> tag inside an <li>
<li>
Home
<ul>
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
#Davi has it right, but you could also change
nav ul li:hover ul li{
display: block;
}
for
nav ul li:hover + ul li {
display: block;
}
Heres a jfiddle of it working
By the way, when you hover over a menu button, whenever the submenu wants to show up, it will displace all other elements in the original menu
Also, here is a nice tutorial on what you want to do specifically
I know #JSelser has already provided a working answer. Yet, I felt mine could be helpful to another person. I went through this tutorial http://inspirationalpixels.com/tutorials/creating-a-dropdown-menu-with-html-css and adjusted to satisfy your menu.
<!DOCTYPE html>
<html>
<head>
<style>
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width:1000px;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
font-family:'Ek Mukta';
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a{
text-decoration:none;
color:#ffffff;
background:#696969;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a{
background:#2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
text-decoration: none;
}
.menu-title{
text-decoration: none;
background-color: #fc575e;
color: #000000;
}
a.menu-title{
color: #000000;
}
</style>
</head>
<body>
<div class="menu_wrap">
<nav class="menu">
<ul class="clearfix">
<li><a class="menu-title" href="#">Home <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
<li><a class="menu-title" href="#">Woman <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
<li><a class="menu-title" href="#">Men <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
<li><a class="menu-title" href="#">Kids <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
<li><a class="menu-title" href="#">Flyers <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li>All</li>
<li>New Arrival</li>
<li>Casual</li>
<li>Gown</li>
<li>Bridesmade</li>
</ul>
</li>
<li><a class="menu-title" href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</body>
</html>
I'm currently using a nested navigation list for my website.
<header>
<nav>
<h1><a href="index.php"><img src="mommyinfologo.png"/></h1>
<ul class="navMenu">
<a href="index.php">
<li class="parentMenu">Home
<ul class="sub-menu">
<a href="mommymadness.php">
<li>This Mommy's Madness</li>
</a>
<a href="about.php">
<li>About Mommy Info</li>
</a>
<a href="contact.php">
<li>Contact Mommy Info</li>
</a>
</ul>
</li>
</a>
<a href="pregnancysplash.php">
<li class="parentMenu">Pregnancy
<ul class="sub-menu">
<a href="ttc.php">
<li>Trying To Conceive</li>
</a>
<a href="fetaldev.php">
<li>Fetal Development</li>
</a>
<a href="genderpredictions.php">
<li>Gender Predictions</li>
</a>
<a href="labordelivery.php">
<li>Labor and Delivery</li>
</a>
</ul>
</li>
</a>
<a href="aabsplash.php">
<li class="parentMenu">All About Baby
<ul class="sub-menu">
<a href="advice.php">
<li>Advice</li>
</a>
<a href="guidelines.php">
<li>Guidelines</li>
</a>
<a href="milestones.php">
<li>Milestones</li>
</a>
<a href="learndev.php">
<li>Learning Development</li>
</a>
</ul>
</li>
</a>
<a href="healthsplash.php">
<li class="parentMenu">Health
<ul class="sub-menu">
<a href="pregnutrition.php">
<li>Pregnancy Nutrition</li>
</a>
<a href="breastfeeding.php">
<li>Breastfeeding</li>
</a>
<a href="formula.php">
<li>Formula Feeding</li>
</a>
<a href="toddlers.php">
<li>Toddlers</li>
</a>
<a href="preexercise.php">
<li>Prenatal Exercise</li>
</a>
<a href="postexercise.php">
<li>Postpartum Exercise</li>
</a>
<a href="organic.php">
<li>Organic DIY Health</li>
</a>
</ul>
</li></a>
<a href="partymommasplash.php">
<li class="parentMenu">Party Momma
<ul class="sub-menu">
<a href="pregann.php">
<li>Pregnancy Announcement</li>
</a>
<a href="genderreveal.php">
<li>Gender Reveal</li>
</a>
<li>Baby Shower</li>
<li>Birth Announcement</li>
<li>Birthdays</li>
</ul>
</li></a>
<a href="stationssplash.php"><li class="parentMenu">Stations
<ul class="sub-menu">
<li>Hospital Bag</li>
<li>Diaper Bag</li>
<li>Changing Station</li>
<li>Baby Gear</li>
</ul>
</li></a>
<a href="memorymarkerssplash.php"><li class="parentMenu">Memory Markers
<ul class="sub-menu">
<li>Do It Yourself</li>
<li>Buy It</li>
</ul>
</li></a>
<a href="reviewsplash.php"><li class="parentMenu">Reviews
<ul class="sub-menu">
<li>Games</li>
<li>Gear</li>
<li>Learning</li>
</ul>
</li></a>
<a href="mommymadness.php"><li class="parentMenu">Blog
</li></a>
</ul>
<?php include_once ("header2.php"); ?>
</nav>
</header>
I'm creating header2.php for the responsive website navigation.
<div id="handle">☰Menu
<ul id="navSmall">
<li class="parentMenuSmall">Home
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Pregnancy
<ul class="sub-menu-small">
<li>Pregnancy</li>
<li>Trying to Conceive</li>
<li>Fetal Development</li>
<li>Gender Predictions</li>
<li>Labor and Delivery</li>
</ul>
</li>
<li class="parentMenuSmall">All About Baby
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Health
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Party Momma
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Stations
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Memory Markers
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Reviews
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
<li class="parentMenuSmall">Blog
<ul class="sub-menu-small">
<li>Home</li>
<li>About</li>
<li>Contact</li>
<li>Mommy Madness</li>
</ul>
</li>
</ul>
</div>
My current CSS:
body {
color:#ADD8E6;
background-image:url(backgroundarrows.png);
font-family:"Monotype Corsiva", sans-serif;
margin:0;
padding:0;
}
/* Global */
ul{
list-style-type: none;
margin: 0;
padding: 0;
}
a{
text-decoration: none;
color:#737597;
;
}
.section {
background-color:#fafbff;
border:thin solid #D3D3D3;
border-radius:10px;
box-shadow:lightgray;
color:#696969;
display:inline;
float:left;
width:63%;
margin:0 1% 1%;
padding:5px 8px;
}
.section h2 {
border-bottom:solid medium #90cdd0;
color:#90cdd0;
text-align:center;
}
#about {
color:dimgrey;
float:right;
font-size:medium;
margin:1% 1% 0;
text-align:center;
width:30%;
}
.nav li {
text-align:left;
font-size:large;
padding:1%;
}
.nav a {
text-decoration:none;
color:darkgrey;
}
#home {
margin:1% 0 1% 1%;
}
#home div {
font-size:20px;
line-height:30px;
padding:1% 3%;
text-align:center;
}
#home div p{
font-family:"Times New Roman", serif;
font-size:20px;
line-height: 30px;
text-align:left;
}
.hide {
display: none;
}
/* Header */
header {
background-color:#cff1ff;
height:60px;
padding:5px 0;
}
header h1 {
color:#809dc6;
display:inline;
font-family:"Monotype Corsiva", sans-serif;
font-size:45px;
height:50px;
padding:5px 15px;
}
/*Website Navigation */
.navMenu {
display:inline;
font-size:20px;
}
.navMenu .parentMenu {
background-color:#cff1ff;
display:inline-block;
padding:5px 10px;
position:relative;
z-index:100000;
}
.navMenu .parentMenu:hover{
background-color:#bfd3ee;
}
.navMenu .parentMenu a{
color:#737597;
}
.navMenu .parentMenu:hover a:hover{
color:#87a2be;
}
.navMenu .parentMenu .sub-menu{
display:none;
left:0;
padding:0;
position:absolute;
top:33px;
width:180px;
z-index:10000;
}
.navMenu .parentMenu:hover .sub-menu{
display:block;
white-space:nowrap;
}
.navMenu .parentMenu:hover .sub-menu li{
background-color:#bfd3ee;
font-size:17px;
padding:10px;
text-align:left;
white-space:nowrap;
width:100%;
z-index:10000;
}
.navMenu .parentMenu .sub-menu li:hover{
background-color:#9ac9ed;
}
#handle{
font-size: 20px;
display: none;
color: #87a2be;
float: left;
width: 100%;
text-align: left;
}
#navSmall {
display: none;
text-align: center;
background-color: #cff1ff;
z-index: 10000000;
height: 25px;
}
#handle:hover #navSmall {
display: inline;
}
.sub-menu-small{
display: none;
background-color: #9ac9ed;
}
.sub-menu-small li {
border-bottom: solid thin #809dc6;
padding:1px 3px;
}
#navSmall .parentMenuSmall {
background-color: inherit;
text-align: left;
padding: 15px;
border-bottom: solid thin #809dc6;
font-size: 18px;
}
#navSmall .parentMenuSmall:hover .sub-menu-small {
display: inline-block;
margin-left: 25px;
}
#construct {
width: 100%;
height: 100%;
margin-top: 100px;
border-radius: 20%;
}
/* Media Queries */
/*tablet*/
/*remove floats */
#media(max-width: 768px) {
body{
width: 100%;
}
header {
float: none;
text-align: center;
width: 100%;
height: 90px;
}
.section{
width: 95%;
}
#about{
display: none;
}
#handle{
display: block;
}
.navMenu {
display: none;
}
}
I want my .sub-menu-small to show to the left outside of my .parentMenuSmall items. Right now it's inside the .parentMenuSmall list items and it pushes all of the other .parentMenuSmall items down. Do I need to pull it out of the list items, if so how do I make it work like it does?
Im really worried , why you do not use a responsive framework like getbootstrap
It's one minute job to create responsive navigation as same as your site behavior
you may need to include bootstrap css and js to your site and add navigation
http://getbootstrap.com/components/#nav as you like that's all
I am working on the menu/navigation bar for my website, but when I added the code for the information sub menu it failed to work. When I tested it I can click info, and hover over it, but it won't display the sub menu at all.
HTML Code:
<!doctype html>
<!--Opening brackets-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="home.css">
<meta charset="utf-8">
<title>Staff List- Krian Society</title>
</head>
<body>
<!--Header-->
<div id="header">
<table class="header">
<tr>
<td class="left">
Text here
</td>
<td class="right">
<div id=social>
<img src="images/facebook.png" width="32" height="32" alt="Facebook"/>
<img src="images/steam.png" width="32" height="32" alt="Steam"/>
<img src="images/youtube.png" width="32" height="32" alt="Youtube"/>
</div>
</td>
</tr>
</table>
</div>
<!--Banner-->
<div id="banner">
<img src="images/banner.jpg" width="43%" alt="TKS Banner"/>
</div>
<!--Nav Bar-->
<div id="menu">
<hr />
<ul>
<li><a href=index.html>Home</a></li>
<li>Donate</li>
<li>Vote</li>
<li>Info</li>
<ul class="sub-menu">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
<li>Live Map</li>
<li>Forums</li>
<li>Wiki</li>
</ul>
<hr />
</div>
<!--Footer-->
<div id="footerstar">
<img src="images/star.png" width="100px" height="100px" />
</div>
<div id="footerlegal">
© The Krian Society 2016 | All Rights Reserved.
</div>
<!--Closing brackets-->
</body>
</html>
CSS Code:
#charset "utf-8";
/*Misc CSS*/
Body {
margin: 0px;
background-color: #272727;
}
hr {
border-color: #7b8e19
}
#font-face {
font-family: optimusPrinceps;
src: url('fonts/OptimusPrinceps.ttf');
}
/*Header*/
#header {
background-color: #7b8e19;
color: #ffffff;
text-align: center;
padding: 5px;
}
#header table {
margin-left: 5%;
margin-right: 5%;
}
#social img{
margin-left: 0.5%;
margin-right: 0.5%;
}
table.header {
width: 90%;
}
td.left {
text-align: left;
padding-top: 1%;
}
td.right {
text-align: right;
}
/*Banner*/
#banner {
padding-top: 1%;
text-align: center;
}
/*Nav Bar*/
#menu {
width: 100%;
}
#menu ul {
text-align: center;
color: #ffffff;
font-size: 20px;
}
#menu ul li {
display: inline;
margin-left: 1.5%;
margin-right: 1.5%;
font-family: optimusPrinceps
}
#menu ul li a{
text-decoration: none;
color: #ffffff;
}
/*Footer*/
#footerstar {
width: 100%;
background-color:#7b8e19;
text-align: center;
font-weight: bold;
padding-top: 10px;
padding-bottom: 10px;
}
#footerlegal {
width: 100%;
text-align: center;
background-color:#171717;
color: #FFFFFF;
padding-bottom: 5px;
padding-top: 5px;
font-family: optimusPrinceps
}
/* sub menu */
#menu li:hover .sub-menu {
/*z-index:1;*/
opacity:1;
}
.sub-menu {
width:100%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
}
Please try this:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="menu.css" />
<title>CSS Simple Drop Down Menu</title>
</head>
<body>
<div class="drop">
<ul class="drop_menu">
<li><a href='#'>Link 1</a>
<ul>
<li><a href='#'>Sub Link 1</a></li>
<li><a href='#'>Sub Link 2</a></li>
</ul>
</li>
<li><a href='#'>Link 2</a>
<ul>
<li><a href='#'>Sub Link 1</a></li>
<li><a href='#'>Sub Link 2</a></li>
<li><a href='#'>Sub Link 3</a></li>
<li><a href='#'>Sub Link 4</a></li>
</ul>
</li>
<li><a href='#'>Link 3</a>
<ul>
<li><a href='#'>Sub Link 1</a></li>
<li><a href='#'>Sub Link 2</a></li>
<li><a href='#'>Sub Link 3</a></li>
<li><a href='#'>Sub Link 4</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
CSS:
.drop_menu {
background:#005555;
padding:0;
margin:0;
list-style-type:none;
height:30px;
}
.drop_menu li { float:left; }
.drop_menu li a {
padding:9px 20px;
display:block;
color:#fff;
text-decoration:none;
font:12px arial, verdana, sans-serif;
}
/* Submenu */
.drop_menu ul {
position:absolute;
left:-9999px;
top:-9999px;
list-style-type:none;
}
.drop_menu li:hover { position:relative; background:#5FD367; }
.drop_menu li:hover ul {
left:0px;
top:30px;
background:#5FD367;
padding:0px;
}
.drop_menu li:hover ul li a {
padding:5px;
display:block;
width:168px;
text-indent:15px;
background-color:#5FD367;
}
.drop_menu li:hover ul li a:hover { background:#005555; }
You have to keep the sub menu within the li tags. Your code should be:
<li>Info
<ul class="sub-menu">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</li>
Use the following code to display the submenu::
CSS: Just replace your .sub-menu class by
.sub-menu {
padding: 10px;
position: absolute;
transition: opacity linear 0.15s;
box-shadow: 0px 2px 3px rgba(0,0,0,0.2);
background: #2e2728;
display: none;
left: 46%;
}
HTML: Move your full submenu ul within the "info" li and set class "info" to that li
<li class="info">Info
<ul class="sub-menu">
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</li>
Jquery: Use the following jquery to display the submenu on hover "Info" link
<script type="text/javascript">
$('.info').mouseover(function(){
$('.sub-menu').show();
});
$('.info').mouseout(function(){
$('.sub-menu').hide();
});
</script>
I wrote code for you to solve this bug
Here is your codes . NO 1 is html part and NO 2 is css part
<!doctype html><!--Opening brackets--><html><head><link rel="stylesheet" type="text/css" href="home.css"><meta charset="utf-8"><title>Staff List- Krian Society</title></head><body><!--Header--><div id="header"><table class="header"><tr><td class="left">Text here</td><td class="right"><div id=social><img src="images/facebook.png" width="32" height="32" alt="Facebook"/><img src="images/steam.png" width="32" height="32" alt="Steam"/><img src="images/youtube.png" width="32" height="32" alt="Youtube"/></div></td></tr></table></div><!--Banner--><div id="banner"><img src="images/banner.jpg" width="43%" alt="TKS Banner"/></div><!--Nav Bar--><div id="menu"><hr /><ul><li>Donate</li><li>Vote</li><li class="sub-menu-hover">Info<ul class="sub-menu"><li>Test 1</li><li>Test 2</li><li>Test 3</li><li>Test 4</li></ul></li><li>Live Map</li><li>Forums</li><li>Wiki</li></ul><hr /></div<!--Footer--><div id="footerstar"><img src="images/star.png" width="100px" height="100px" /></div><div id="footerlegal">© The Krian Society 2016 | All Rights Reserved.</div><!--Closing brackets--></body></html>
#charset "utf-8";/*Misc CSS*/body {margin: 0px;background-color: #272727;}hr {border-color: #7b8e19}#font-face {font-family: optimusPrinceps;src: url('fonts/OptimusPrinceps.ttf');}/*Header*/#header {background-color: #7b8e19;color: #ffffff;text-align: center;padding: 5px;}#header table {margin-left: 5%;margin-right: 5%;}#social img{margin-left:0.5%;margin-right: 0.5%;}table.header {width: 90%;}td.left {text-align: left;padding-top: 1%;}td.right {text-align: right;}/*Banner*/#banner {padding-top: 1%;text-align: center;}/*Nav Bar*/#menu {width: 100%;}#menu ul {text-align: center;color: #ffffff;font-size: 20px;}#menu ul li {display: inline; margin-left: 1.5%;margin-right: 1.5%;font-family:optimusPrinceps;}#menu ul li a{text-decoration: none;color:#ffffff;}/*Footer*/#footerstar {width: 100%;background-color:#7b8e19;text-align:center;font-weight: bold;padding-top:10px;padding-bottom: 10px;}#footerlegal {width: 100%;text-align: center;background-color:#171717;color: #FFFFFF;padding-bottom: 5px;padding-top: 5px;font-family: optimusPrinceps}/* sub menu */#menu li:hover .sub-menu {/*z-index:1;*/opacity:1;}.sub-menu{width:20%;background:#2e2728;display:none;position:absolute;float:left;top:140px;left:420px;}.sub-menu li {display:block;font-size:16px;}.sub-menu li a {padding:10px 30px;display:block;}.sub-menu-hover{background:#808080;}.sub-menu{background:#808080;}.sub-menu-hover:hover.sub-menu{color:#F00;display:block;opacity:9;}.sub-menu li a:hover, .sub-menu.current-item a {background:#3e3436;}
The following coding gives an output of a list in a vertical manner. How do I adjust this to make it in horizantal list? For example like this: http://www.nol.com.sg/wps/portal/nol
<body>
<ul id="mainmenu">
<li><a class="menu" href="">Menu</a>
<ul>
<li>Home</li>
<li>About</li>
</ul>
</li>
<li><a class="menu" href="">Company</a>
<ul>
<li>History</li>
<li>News</li>
</ul>
<li><a class="menu" href="">Contact Us</a></li>
</ul>
</body>
DEMO
HTML
<ul id="mainmenu">
<li><a class="menu" href="">Menu</a>
<ul>
<li>Home
</li>
<li>About
</li>
</ul>
</li>
<li><a class="menu" href="">Company</a>
<ul>
<li>History
</li>
<li>News
</li>
</ul>
<li><a class="menu" href="">Contact Us</a>
</li></li>
</ul>
CSS
#mainmenu li {
float:left;
list-style-type:none;
margin-right:1px;
width:80px;
text-align:center;
}
#mainmenu li li {
float:none;
padding:0;
}
#mainmenu li ul {
display:none;
padding:0;
}
#mainmenu li:hover ul {
display: block;
}
In css use the following code:
#mainmenu li{
display:inline;
}
http://css.maxdesign.com.au/listutorial/horizontal_master.htm
CSS
#navcontainer ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
}
#navcontainer ul li { display: inline; }
#navcontainer ul li a
{
text-decoration: none;
padding: .2em 1em;
color: #fff;
background-color: #036;
}
#navcontainer ul li a:hover
{
color: #fff;
background-color: #369;
}
HTML
<div id="navcontainer">
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Cheese</li>
<li>Vegetables</li>
<li>Fruit</li>
</ul>
</div>
To affect this only on li that are childs of #mainmenu
#mainmenu > li {
float:left
}
DEMO
HTML
<ul id="mainmenu">
<li><a class="menu" href="">Menu</a>
<ul>
<li>Home
</li>
<li>About
</li>
</ul>
</li>
<li><a class="menu" href="">Company</a>
<ul>
<li>History
</li>
<li>News
</li>
</ul>
<li><a class="menu" href="">Contact Us</a>
</li></li>
</ul>
CSS
#mainmenu li {
float:left;
list-style-type:none;
margin-right:1px;
width:80px;
text-align:center;
}
#mainmenu li li {
float:none;
padding:0;
}
#mainmenu li ul {
padding:0;
}
#mainmenu li:hover ul {
display: block;
}
We were following this tutorial (http://www.script-tutorials.com/click-action-multilevel-css3-dropdown-menu/). The goal was to create a multilevel dropdown click menu with css/html and no js. The code works fine in firefox and even works in the demo shown in the tutorial in chrome, but downloading the code and using it separately doesn't work in chrome. Anyone have any ideas why? The code for the menu is:
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<div class="example">
<ul id="nav">
<li>Home</li>
<li><a class="fly" href="#">Tutorials</a>
<ul class="dd">
<li>HTML / CSS</li>
<li><a class="fly" href="#">JS / jQuery</a>
<ul>
<li>jQuery</li>
<li>JS</li>
</ul>
</li>
<li>PHP</li>
<li>MySQL</li>
<li>XSLT</li>
<li>Ajax</li>
</ul>
</li>
<li><a class="fly" href="#">Resources</a>
<ul class="dd">
<li><a class="fly" href="#">By category</a>
<ul>
<li>PHP</li>
<li>MySQL</li>
<li><a class="fly" href="#">Menu1</a>
<ul>
<li>Menu1</li>
<li>Menu2</li>
<li><a class="fly" href="#">Menu3</a>
<ul>
<li>Menu31</li>
<li>Menu32</li>
<li>Menu33</li>
<li>Menu34</li>
</ul>
</li>
<li>Menu4</li>
</ul>
</li>
<li>Ajax</li>
</ul>
</li>
<li><a class="fly" href="#">By tag name</a>
<ul>
<li>captcha</li>
<li>gallery</li>
<li>animation</li>
</ul>
</li>
</ul>
</li>
<li>About</li>
<li>Go Back To The Tutorial</li>
</ul>
</div>
/* demo page styles */
body {
background:#eee;
margin:0;
padding:0;
}
.example {
background:#fff url(../images/tech.jpg);
width:770px;
height:570px;
border:1px #000 solid;
margin:20px auto;
padding:15px;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
/* main menu styles */
#nav,#nav ul {
background-image:url(../images/tr75.png);
list-style:none;
margin:0;
padding:0;
}
#nav {
height:41px;
padding-left:5px;
padding-top:5px;
position:relative;
z-index:2;
}
#nav ul {
left:-9999px;
position:absolute;
top:37px;
width:auto;
}
#nav ul ul {
left:-9999px;
position:absolute;
top:0;
width:auto;
}
#nav li {
float:left;
margin-right:5px;
position:relative;
}
#nav li a {
background:#c1c1bf;
color:#000;
display:block;
float:left;
font-size:16px;
padding:8px 10px;
text-decoration:none;
}
#nav > li > a {
-moz-border-radius:6px;
-webkit-border-radius:6px;
-o-border-radius:6px;
border-radius:6px;
overflow:hidden;
}
#nav li a.fly {
background:#c1c1bf url(../images/arrow.gif) no-repeat right center;
padding-right:15px;
}
#nav ul li {
margin:0;
}
#nav ul li a {
width:120px;
}
#nav ul li a.fly {
padding-right:10px;
}
/*hover styles*/
#nav li:hover > a {
background-color:#858180;
color:#fff;
}
/*focus styles*/
#nav li a:focus {
outline-width:0;
}
/*popups*/
#nav li a:active + ul.dd,#nav li a:focus + ul.dd,#nav li ul.dd:hover {
left:0;
}
#nav ul.dd li a:active + ul,#nav ul.dd li a:focus + ul,#nav ul.dd li ul:hover {
left:140px;
}
New css Worked for me in both crome and firefox!::::
body {
background:#eee;
margin:0;
padding:0;
}
.example {
background:#fff url(../images/tech.jpg);
width:770px;
height:570px;
border:1px #000 solid;
margin:20px auto;
padding:15px;
border-radius:3px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
/* main menu styles */
#nav,#nav ul {
background-image:url(../images/tr75.png);
list-style:none;
margin:0;
padding:0;
}
#nav {
height:41px;
padding-left:5px;
padding-top:5px;
position:relative;
z-index:2;
}
#nav ul {
left:-9999px;
position:absolute;
top:37px;
width:auto;
}
#nav ul ul {
left:-9999px;
position:absolute;
top:0;
width:auto;
}
#nav li {
float:left;
margin-right:5px;
position:relative;
}
#nav li a {
background:#c1c1bf;
color:#000;
display:block;
float:left;
font-size:16px;
padding:8px 10px;
text-decoration:none;
}
#nav > li > a {
-moz-border-radius:6px;
-webkit-border-radius:6px;
-o-border-radius:6px;
border-radius:6px;
overflow:hidden;
}
#nav li a.fly {
background:#c1c1bf url(../images/arrow.gif) no-repeat right center;
padding-right:15px;
}
#nav ul li {
margin:0;
}
#nav ul li a {
width:120px;
}
#nav ul li a.fly {
padding-right:10px;
}
/*hover styles*/
#nav li:hover > a {
background-color:#858180;
color:#fff;
}
/*focus styles*/
#nav li a:focus {
outline-width:0;
}
/*popups*/
#nav li a:hover + ul.dd,#nav li a:focus + ul.dd,#nav li ul.dd:hover {
left:0;
}
#nav ul.dd li a:hover + ul,#nav ul.dd li a:focus + ul,#nav ul.dd li ul:hover {
left:140px;
}
In files for download is different html page. Difference is that live demo contain attribute tabindex="1" in some links. I downloaded source code from live example and it works in chrome now.
New code for your html page.
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<div class="example">
<ul id="nav">
<li>Home</li>
<li><a class="fly" href="#" tabindex="1">Tutorials</a>
<ul class="dd">
<li>HTML / CSS</li>
<li><a class="fly" href="#" tabindex="1">JS / jQuery</a>
<ul>
<li>jQuery</li>
<li>JS</li>
</ul>
</li>
<li>PHP</li>
<li>MySQL</li>
<li>XSLT</li>
<li>Ajax</li>
</ul>
</li>
<li><a class="fly" href="#" tabindex="1">Resources</a>
<ul class="dd">
<li><a class="fly" href="#" tabindex="1">By category</a>
<ul>
<li>PHP</li>
<li>MySQL</li>
<li><a class="fly" href="#" tabindex="1">Menu1</a>
<ul>
<li>Menu1</li>
<li>Menu2</li>
<li><a class="fly" href="#" tabindex="1">Menu3</a>
<ul>
<li>Menu31</li>
<li>Menu32</li>
<li>Menu33</li>
<li>Menu34</li>
</ul>
</li>
<li>Menu4</li>
</ul>
</li>
<li>Ajax</li>
</ul>
</li>
<li><a class="fly" href="#" tabindex="1">By tag name</a>
<ul>
<li>captcha</li>
<li>gallery</li>
<li>animation</li>
</ul>
</li>
</ul>
</li>
<li>About</li>
<li>Go Back To The Tutorial</li>
</ul>
</div>