I am making a dropdown menu on one of my menu item.
ie: | Home | About | Store | Contact |
I want to create a dropdown menu for say About page...but Whenever I try to add
<div id="snaznav"> Home
<ul>
<li>About
<ul>
<li><a href="#">Submenu1</li>
<li><a href="#">Submenu2</li>
<li><a href="#">Submenu3</li>
</ul>
</li>
</ul></div>
Every next menu item gets disturbed as:
Home | About
Store |
Contact |
I dont know..where the problem is?
My CSS code is:
#snaznav {
float:left;
height:42px;
top:151px;
width:670px;
}
#snaznav a {
float:left;
height:41px;
display:block;
}
#home {
background:url(http://www.abc.com/home.gif) no-repeat transparent;
background-position:0 -2px!important;
width:77px;
}
#about {
background:url(http://www.abc.com/about.gif) no-repeat transparent;
background-position:-78px -2px!important;
width:104px;
}
#store {
background:url(http://www.abc.com/storegif) no-repeat transparent;
background-position:-307px -2px!important;
width:82px;
}
#contactus {
background:url(http://www.abc.com/contact.gif) no-repeat transparent;
background-position:-388px -2px!important;
width:131px;
}
If you need anything to know, just say me !!
Can you rewrite your HTML Code this way:
HTML:
<div id="snaznav">
<ul>
<li>Home</li>
<li>
About
<ul>
<li>Submenu1</li>
<li>Submenu2</li>
<li>Submenu3</li>
</ul>
</li>
</ul>
</div>
So that the CSS you can apply this way:
CSS:
#snaznav ul {border-bottom: 1px solid #999;}
#snaznav ul li a {display: block; text-decoration: none; color: #333; padding: 5px; border: 1px solid #fff;}
#snaznav ul > li:hover {border: 1px solid #666; border-bottom: 1px solid #fff;}
#snaznav ul li a:hover {background: #ccc; border: 1px solid #999;}
#snaznav ul > li {display: inline-block; position: relative; border: 1px solid #fff;}
#snaznav ul > li ul {display: none; position: absolute; left: -1px; width: 150px; border: 1px solid #666; border-top-color: #fff; margin-top: 1px;}
#snaznav ul > li:hover ul {display: block;}
#snaznav ul > li ul li {display: block;} /* Vertical Menu */
#snaznav ul > li ul li {display: inline-block;} /* Horizontal Menu */
Fiddle: http://jsfiddle.net/VmHXb/1/ (Vertical) http://jsfiddle.net/VmHXb/3/ (Horizontal)
Related
As you can see, I commented out the code for the dropdown menu, the menu works. But it isn't aligned with the rest of the navigation bar. Any help is appreciated.
<div id="top_nav">
<div id="top_nav_container">
<ul>
<li>Home</li>
<li>Redacted</li>
<li>How It Works</li>
<li>FAQs</li>
<li>Special Offers</li>
<li>Customer Service</li>
<!-- <span class="dropdown">
<span class="dropbtn">Special Offers</span>
<span class="dropdown-content">
Link 1
Link 2
Link 3
</span> -->
</ul>
</div>
Here's the CSS - the original is towards the bottom (after "cont.", the top was added later from an external source)
/* TOP NAV */
/* dd
/* Style The Dropdown Button */
.dropbtn {
background-color: #5d72b3;
color: white;
margin:auto;
padding: 0px;
text-align:center;
font-size: 14px;
border: none;
cursor: pointer;
text-decoration:none;
border-right:1px solid #FFF;
padding:9px 12px 0 12px;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #f1f1f1}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
/*________________________cont. */
#top_nav_container {
position:relative;
width:1000px;
margin:auto;
height:33px;
}
#top_nav {
width:1000px;
height:33px;
background-color:#5d72b3;
border-bottom:1px solid #FFF;
border-top:1px solid #FFF;
margin:auto;
}
#top_nav ul {
width:849px;
margin:0;
padding:0;
list-style:none;
}
#top_nav ul li {float: left;}
#top_nav ul li a {
display:block;
width:auto;
height:24px;
text-align:center;
font-size:14px;
font-family:Arial, Helvetica, sans-serif;
color:#FFF;
text-decoration:none;
border-right:1px solid #FFF;
padding:9px 12px 0 12px;
}
#top_nav ul li a:hover {
background-color:#86a3ff;
}
#sub_nav_bar {
width:1000px;
height:40px;
margin:0 auto 6px auto;
text-align:center;
}
Redacted company info djdjsjshsjshhshshshshshshshhshshshshshshshshshhshshs
Sjshshsjs
Hshshshshshshsh jsjsjsjsjhshss
.dropbtn { display: block;
height: 24px; }
Can anyone suggest what might be the problem on my flickering menu bar?
Please suggest anything that will make the flickering of menu bar stop.
Thanks much!
#mainmenu{
margin-bottom: 2.5em;
}
.menubar{
position: fixed;
top:0;
left:0;
max-height:10em;
width:100%;
list-style: none;
background-color:#333333;
text-align: left;
margin:0;
padding: 0;
z-index: 1;
border-bottom: 1px solid #ccc;
}
.menubar .first {
margin-left: 1em;
}
.menubar li{
position: relative;
display: inline-block;
width:15em;
text-align: center;
font-family: 'Oswald', sans-serif;
font-size: 1em;
border-bottom: none;
cursor: pointer;
}
.menubar li:hover{
background-color:#6666ff;
}
.menubar a{
display: block;
padding: 0.5em 0.5em 0.5em 0.5em;
text-decoration: none;
color:#ffffff;
}
/* for submenus */
.menubar .first .submenubar {
padding: 0;
position: absolute;
top:2em;
left:0;
width:auto;
display: none;
-webkit-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
-moz-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
}
.menubar li .submenubar li {
text-align: left;
list-style-type: none;
background-color:brown;
display: block;
color:#fff;
}
.menubar > li > .submenubar > li:hover {
background-color:black;
}
.menubar li:hover .submenubar{
display: block;
}
See this JsFiddle for my complete code.
I suspect that one of 2 things are happening.
Is the whole header "flickering" when you go to a new page? If so,
that's because you are building an html page from your php on the
server and then rendering the page again. Sometimes this will flash.
Sucks.
The sub-menu appears to "flicker" because it's broken and when you
try and hove over it, it disappears.
If it's 1, you can use caching to try and lessen the chances of this happening, or you can learn how to use ajax, or a js framework to build single page apps, but that's a lot of work.
If it's 2, then this code I'll include below, and this fiddle - will set you up with some more solid code to work with.
My real advice, is to just never use drop-down menus. They are a terrible interface pattern.
HTML
<nav class='container navigation'>
<div class='inner-w'>
<ul class='menu'>
<li>
<a href='#'>Top-level menu item 1</a>
<ul class='sub-menu'>
<li><a href='#'>Sub-menu item 1</a></li>
<li><a href='#'>Sub-menu item 2</a></li>
<li><a href='#'>Sub-menu item 3</a></li>
<li><a href='#'>Sub-menu item 4</a></li>
</ul>
</li>
<li><a href='#'>Top-level menu item 2</a></li>
<li>
<a href='#'>Top-level menu item 3</a>
<ul class='sub-menu'>
<li><a href='#'>Sub-menu item 1</a></li>
<li><a href='#'>Sub-menu item 2</a></li>
</ul>
</li>
<li><a href='#'>Top-level menu item 4</a></li>
</ul>
</div>
</nav>
CSS
/* global-structure */
.container {
width: 100%;
float: left;
}
.container .inner-w {
margin-right: auto; margin-left: auto;
max-width: 900px; /* arbitrary */
/* this should have a clear-fix */
}
/* menu styles */
.menu, .menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
}
.menu > li { /* just the top-level li */
position: relative;
/* so the sub-menu can be positioned to this */
border-right: 1px solid rgba(0,0,0,.3)
}
.menu > li:last-child {
border-right: 0;
}
.menu a {
display: block;
padding: .8rem .5rem;
background: #eee;
min-width: 160px;
color: inherit;
text-decoration: none;
}
.sub-menu {
position: absolute;
top: 100%;
left: 0;
height: 0;
width: 0; /* just hide it visually */
overflow: hidden;
z-index: 5; /* arbitrary, keep them small though... */
}
.sub-menu li {
clear: left;
border-bottom: 1px solid rgba(0,0,0,.3)
}
.sub-menu li:last-child {
border-bottom: 0;
}
.sub-menu a {
background: #ccc;
}
.sub-menu a:hover {
background: #aaa;
}
.menu > li:hover .sub-menu {
height: auto;
width: auto;
}
If I was absolutely forced to write a drop-down menu, It would have to be like this: http://codepen.io/sheriffderek/pen/qdBryb/?editors=010
I am creating a menu bar with rollovers, when i roll over the option the background and text colour change but when i move my mouse down to the sub menu that appeared with hovering on the menu the text colour changes back but the background stays.
This is my HTML for the menu bar:
<div id="menuBar">
<div id="nav">
<div id="nav_wrapper">
<ul>
<li class="bar">Home
</li>
<li class="bar"> Services
</li>
<li class="bar"> Sales →
<ul>
<li class="bar">dropdown #1 item #1
</li>
<li class="bar">dropdown #1 item #2
</li>
<li class="bar">dropdown #1 item #3
</li>
</ul>
</li>
<li class="bar"> Repairs →
<ul>
<li class="bar">Bar
</li>
<li class="bar">Kitchen
</li>
<li class="bar">dropdown #2 item #3
</li>
</ul>
</li>
<li class="bar"> Installations
</li>
<li class="bar"> Contact Us
</li>
</ul>
</div>
<!-- Nav wrapper end -->
And the CSS that im using:
#menuBar {
background:#FF0;
box-shadow:5px 5px 2px #888888;
position:absolute;
height:55px;
width:1000px;
left:0;
right:0;
margin:auto;
top:253px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
behavior: url(/css/border-radius.htc);
z-index:5;
}
#nav {
padding: 0;
margin: 0;
font-family: Arial;
font-size: 21px;
left:0;
right:0;
margin:auto;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: center;
}
#nav a {
color:#0000FF;
}
#nav a:hover {
color:#FF0;
}
#nav a:active {
color:#FF0;
}
#nav a::focus {
color:#FF0;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #00F;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-khtml-border-radius: 10px;
color:#FF0;
border-radius: 10px;
behavior: url(/CSS/border-radius.htc);
}
#nav ul li a, visited {
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
-khtml-border-radius: 15px;
color:#FF0;
border-radius: 15px;
behavior: url(/CSS/border-radius.htc);
}
#nav ul ul {
display: none;
position: absolute;
background-color: #FFFF00;
border: 3px solid #00F;
border-top: 1;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color:#FF0;
}
.bar {
color:#FF0;
}
Im sure that im missing something simple but i cant find it at all.
Help!
Building on what Niet the Dark Absol said:
you would need to add styles (notice the > - this selects ONLY direct children, works with IE8+ and elsewhere)
#nav ul li:hover > a {
color: #ff0;
}
and you can probably remove this because it would be redundant:
#nav ul ul li a:hover {
color:#FF0;
}
You are applying the color change to a:hover, but the background-color change to li:hover.
Both must be on the li:hover to work. You may need to add color:inherit to the a elements within the menu to ensure natural link colours don't override the setting.
I have a Joomla site using Mosets Tree for a business directory. On the right side all the categories are listed. If the sub-categories for an item are expanded, for example under GENERAL SERVICES and you roll over the next menu item (GOVERNMENT AGENCIES), all the sub-category items above get highlighted, which obviously shouldn't happen.
http://www.downtownnewwest.ca/index.php/directory/general-services
The CSS looks like this:
#sidebar ul {
list-style:none;
margin: 0;
padding-left:0;
}
#sidebar .active ul li a {
text-transform: none;
margin-left: 10px;
}
#sidebar ul.menu li a {
display: block;
width: 190px;
color: #00215b;
padding: 10px 20px 10px 20px;
border-bottom: 1pt solid #ccc;
text-decoration: none;
}
#sidebar ul.menu li a:hover {
background: #00215b;
color: #fff;
}
Thanks in advance.
You would use the direct child combinator, >, in order to only select the direct li children elements of ul.menu. Additionally, the anchor elements should be inline-block as opposed to block:
This will fix the issues:
#sidebar ul.menu > li > a {
width: 190px;
color: #00215b;
padding: 10px 20px 10px 20px;
border-bottom: 1pt solid #ccc;
text-decoration: none;
display: inline-block;
}
This file below is working alone as menu.php, but when I include it in another file using
<?php include("menu.php") ?>
it generates a line break. But why is that I don't understand, I tried several times, but not solved. So, please help me guys and girls.
<style>
/* Menu style starts*/
nav ul li:hover > ul {
display: block;
}
nav ul {
background: maroon;
background: linear-gradient(top, maroon 0%, #800000 100%);
background: -moz-linear-gradient(top, maroon 0%, #800000 100%);
background: -webkit-linear-gradient(top, maroon 0%,#800000 100%);
list-style: none;
display: inline-table;
position: relative;
padding: 0 15px;
box-shadow: 0px 0px 20px #888888;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #4b545f;
background: linear-gradient(top, black 0%, #5f6975 40%);
background: -moz-linear-gradient(top, black 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, black 0%,#5f6975 40%);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block;
padding: 10px 38px;
text-decoration: none;
color: white;
font-size: 19px;
font-weight: bold;
}
nav ul ul {
display: none;
background: #5f6975;
border-radius: 0px;
padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
nav ul ul li a {
padding: 10px 40px;
color: white;
font-size: 12px;
font-weight: bold;
}
nav ul ul li a:hover {
background: #4b545f;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
/* Menu style ends*/
</style>
<div align="center"
style="height: 100px; color: #FFFFFF; background-color: #0033CC;">
<font size="12" style="z-index:; margin-bottom:0px;">
Open Public Library
</font>
<br />
<font size="4">
It's still under process, coming soon with full facility
</font>
</div>
<nav align=center>
<ul>
<li><a href="index.php">
<!--img src="images/home_icon.png"/-->HOME
</a>
</li>
<li>ABOUT US</li>
<li>USER
<ul>
<li>LOGIN
<ul>
<li>GUEST</li>
<li>MEMBER</li>
<li>ADMINISTRATOR</li>
</ul>
</li>
<li>REGISTRATION</li>
</ul>
</li>
<li>BOOK
<ul>
<li>INSERT</li>
<li>UPDATE</li>
<li>SHOW</li>
<li>SEARCH</li>
</ul>
</li>
<li>CONTACT US
<ul>
<li>GIVE FEEDBACK</li>
<li>SEE CONTACTS</li>
</ul>
</li>
<li>REGISTER</li>
</ul>
</nav>
If you are using UTF-8 encoding, save file as UTF-8 without BOM