I'm trying to figure out how to get the .sub_menu to display when hovering over the main menu.
I know you hide the .sub_menu but how do you code when hovering over <li> to show sub menu <ul>? You would have to target hover for the first <li> but then change the display: none to however you want the sub menu to look like right?
I can't figure out how to do it.
#navagation{
float:left;
width:70%;
height:100%;border: 1px solid green;
margin:0;
padding:0;
}
#btmenu{
position:relative;
width:100%;
list-style: none;
margin:0;
padding:0;
border: 1px solid blue;
height:62px;text-align:center;
}
ul#btmenu li{
padding:0;
margin:0;
display: inline;
height:62px;
width:200px;
}
#btmenu li > a{ height:62px;
line-height:62px;
margin-left:1%;
margin-right:1%;
border: 1px solid green;
text-align:center;
display:inline-block;
text-decoration:none;
font-weight:bold;
font-size:15px;
color:#000;
padding-left:1%;
padding-right:1%;
text-transform:uppercase;
vertical-align: middle;
}
#btmenu > li > a:hover{
background-color:#000;
color:#FFF;
}
.sub_menu{
display:none;
position:absolute;
width:680px;
background-color:#666;
border: 1px solid red;
list-style: none;
margin:0;
padding:0;
}
#btmenu .sub_menu li{
}
.sub_menu li a{display:inline-block;
background-color:#F00;
height:100px;
width:100px;margin:10px;
text-decoration:none;
color:#FFF;
}
<div id="navagation">
<ul id="btmenu">
<li class="top_quote"><a href="services">services
<ul class="sub_menu">
<li class="auto body repair">1</li>
<li class="rental & loaner">2</li>
<li class="hail damage repair">3</li>
<li class="towing">4</li>
<li class="glass repair">5</li>
</ul></a></li>
<li class="top_quote">locations</li>
<li class="top_quote">partners</li>
<li class="top_quote">our work</li>
<li class="top_quote">contact</li>
</ul>
</div><!--navagation-->
You need to add this line to make the sub menu appears when you hover a li :
#btmenu li:hover ul {display: block}
See it here
You shouldn't have the submenu inside the a tag (this can cause problems with the a tags inside the submenu)
If you put the submenu just after the a tag (as a sibling) then you can act on the li:hover
something like:
#btmenu > li:hover .sub_menu{
display: block;
}
working example with your snippet:
#navagation{
float:left;
width:70%;
height:100%;border: 1px solid green;
margin:0;
padding:0;
}
#btmenu{
position:relative;
width:100%;
list-style: none;
margin:0;
padding:0;
border: 1px solid blue;
height:62px;text-align:center;
}
ul#btmenu li{
padding:0;
margin:0;
display: inline;
height:62px;
width:200px;
}
#btmenu li > a{ height:62px;
line-height:62px;
margin-left:1%;
margin-right:1%;
border: 1px solid green;
text-align:center;
display:inline-block;
text-decoration:none;
font-weight:bold;
font-size:15px;
color:#000;
padding-left:1%;
padding-right:1%;
text-transform:uppercase;
vertical-align: middle;
}
#btmenu > li > a:hover{
background-color:#000;
color:#FFF;
}
.sub_menu{
display:none;
position:absolute;
width:680px;
background-color:#666;
border: 1px solid red;
list-style: none;
margin:0;
padding:0;
}
#btmenu .sub_menu li{
}
.sub_menu li a{display:inline-block;
background-color:#F00;
height:100px;
width:100px;margin:10px;
text-decoration:none;
color:#FFF;
}
#btmenu > li:hover .sub_menu{
display: block;
}
<div id="navagation">
<ul id="btmenu">
<li class="top_quote">
services
<ul class="sub_menu">
<li class="auto body repair">1</li>
<li class="rental & loaner">2</li>
<li class="hail damage repair">3</li>
<li class="towing">4</li>
<li class="glass repair">5</li>
</ul>
</li>
<li class="top_quote">locations</li>
<li class="top_quote">partners</li>
<li class="top_quote">our work</li>
<li class="top_quote">contact</li>
</ul>
</div><!--navagation-->
Related
I am trying to center my nav bar. I checked my sites but nothing works
and I'm completely stumped as to why it won't center, here is my navigation bar HTML that I want to center:
<div class='nav'>
<ul class='menu' id='menu'>
<li><a expr:href='data:blog.homepageUrl'>home</a></li>
<li><a class='drop-ctg' href='#'>PORTFOLIO</a>
<ul>
<li><a href='http://effectsforshare.blogspot.com/p/trailer.html'>TRAILER</a></li>
<li><a href='http://effectsforshare.blogspot.com/p/motion-graphics.html'>MOTION GRAPHICS</a></li>
<li><a href='http://effectsforshare.blogspot.com/p/trapcode-particular.html'>TRAPCODE PARTICULAR</a></li>
</ul>
</li>
<li><a href='http://effectsforshare.blogspot.com/'>TEMPLATES</a></li>
<li><a href='http://effectsforshare.blogspot.com/p/my-blog.html'>MY BLOG</a></li>
<li><a href='http://effectsforshare.blogspot.com/p/contact-me.html'>CONTACT ME</a></li>
</ul>
</div>
and here is the CSS
*{
margin:0;
padding:0;
outline:0;
}
.nav {
width:950px;
height:auto;
border-bottom:1px solid #eee;
margin:10px auto 5px;
display:inline-block;
}
.menu {
width:auto;
list-style:none;
font:$pagenavifont;
text-align:center;
margin:0 auto;
}
.menu a {
float:left;
color:#999;
text-decoration:none;
text-transform:uppercase;
width:auto;
line-height:36px;
padding:0 20px;
}
.menu a:hover,li.menuhover a{
color:#111;
}
.menu li {
position:relative;
float:left;
width:auto;
}
.menu li:last-child {
background:none;
}
.menu ul{
display:none;
position:absolute;
top:36px;
left:0;
background:#fbfbfb;
display:none;
list-style:none;
}
.menu ul li{
float:none;
border-top:1px solid #e3e3e3;
border-right:1px solid #e3e3e3;
border-left:1px solid #e3e3e3;
width:auto;
background:none;
}
.menu ul li:last-child {
border-bottom:1px solid #e3e3e3
}
.menu ul li a{
float:none;
display:block;
background:none;
line-height:36px;
min-width:137px;
width:auto;
text-align:left;
padding-left:10px;
color:#444;
}
.menu ul li a:hover{
background:#fdfdfd;
color:#777;
}
I would give you a link to the page but it's being done in Dreamweaver and is not up yet. The logobar.jpg is the logo for the webpage. I love how it looks, but it needs to be centered and not be cut off or taken to the next line when I shrink my screensize.
I tried each of float: right, float: left, and float: none on almost all of the classes; text-align: center on each class on the html side; I have tried align=center on each class; display: inline, inline-block on ul and li classes.
Thank you for your help!
On your .menu class, you do have text-align:center set. We can certainly use that to center the child nodes.
So within your .menu li css property, add display:inline-block and remove the floats. This will center your list items.
See the fiddle: http://jsfiddle.net/RGREA/
<style>
div.nav{margin: 3px auto;}
</style>
I am relatively new to CSS and I'm having trouble getting my navigation bar aligned horizontally. I tried the display:inline; function with no success. When using the float:left function, I get all the li aligned horizontally, but in this case, I cannot center it on the page. Also the margin:0 auto; does not do it in this case.
The navigation bar is created via an ul inside a DIV, which is also contained inside a "wrapper div".
Is the problem linked to the various ID selectors used and the nesting of the various elements?
Please find the jsfiddle below for visualisation:
JsFiddle
Any help would be greatly appreciated :)
Thanks, Danny
HTML
<div id="wrapper">
<div id="navigation">
<ul>
<li>HOME</li>
</ul>
<ul>
<li>GALLERY</li>
<li class="sublinks">
PORTRAITURE
NATURE
</li>
</ul>
<ul>
<li>BLOG</li>
</ul>
<ul>
<li>ABOUT</li>
</ul>
<ul>
<li>MODEL RELEASE</li>
</ul>
<ul>
<li>CONTACT</li>
</ul>
</div>
</div>
CSS
ul {
list-style:none;
margin:0px 5px;}
ul li {
display:inline;}
ul li a {
color:#ffffff;
background:#09F;
padding:0px 0px;
margin:0 auto;
font-weight:bold;
font-size:14px;
font-family:'sans open', Arial, Helvetica, sans-serif;
text-decoration:none;
display:block;
width:auto;
height:40px;
line-height:15px;
text-align:center;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border: 1px solid #560E00;}
ul li a:hover {
color:#cccccc;
background:#06F;
font-weight:bold;
text-decoration:none;
display:block;
width:auto;
text-align:center;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border: 1px solid #000000;}
ul li.sublinks a {
color:#000000;
background:#f6f6f6;
border-bottom:1px solid #cccccc;
font-weight:normal;
text-decoration:none;
display:block;
width:100px;
text-align:center;
margin-top:2px;}
ul li.sublinks a:hover {
color:#000000;
background:#FFEFC6;
font-weight:normal;
text-decoration:none;
display:block;
width:100px;
text-align:center;}
ul li.sublinks {
display:none;}
Your ul needs inline-block and the menu wrapper needs text-align:center plus some width to make menu center regardless of an ammount of menu items.
I've updated your fiddle here: jsFiddle
You just need to make the the ul and ul li display inline-block. I also added text-align: center; to the #navigation element.
Here is the working code example on JsFiddle: http://jsfiddle.net/hhjfypmt/
You could do as said above, but if you also want to align it to the left/right, you can add a float:right (or left) instead, to your ul li:
ul {
list-style:none;
margin:0px 0px;
}
ul li {
display:inline-block;
float:left;
}
ul li a {
color:#ffffff;
background:#09F;
padding:0px 0px;
margin:0 auto;
font-weight:bold;
font-size:14px;
font-family:'sans open', Arial, Helvetica, sans-serif;
text-decoration:none;
width:auto;
height:40px;
line-height:15px;
text-align:center;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border: 1px solid #560E00;
}
ul li a:hover {
color:#cccccc;
background:#06F;
font-weight:bold;
text-decoration:none;
width:auto;
text-align:center;
-webkit-border-radius:5px;
-moz-border-radius:5px;
border: 1px solid #000000;
}
ul li.sublinks a {
color:#000000;
background:#f6f6f6;
border-bottom:1px solid #cccccc;
font-weight:normal;
text-decoration:none;
width:100px;
text-align:center;
margin-top:2px;
}
ul li.sublinks a:hover {
color:#000000;
background:#FFEFC6;
font-weight:normal;
text-decoration:none;
width:100px;
text-align:center;
}
ul li.sublinks {
display:none;
}
/* CSS For Dropdown Menu End */
<div id="wrapper">
<div id="navigation">
<ul>
<li>HOME</li>
</ul>
<ul>
<li>GALLERY</li>
<li class="sublinks">
PORTRAITURE
NATURE
</li>
</ul>
<ul>
<li>BLOG</li>
</ul>
<ul>
<li>ABOUT</li>
</ul>
<ul>
<li>MODEL RELEASE</li>
</ul>
<ul>
<li>CONTACT</li>
</ul>
</div>
</div>
basically i'm trying to create a navigation bar and I'm trying to position two (and more) li elements next to each other, I've tried to figure it out but can't seem to do it???
css is below.... html is below css
don't even know whether i've laid it out correctly, if you know a tutorial or something to do the same thing let me know I've spent days figuring out how to set it up correctly......
CSS
li {
list-style-type:none;
list-style:none;
background:clear;
padding:0;
margin:0;
}
ul {
list-style-type:none;
list-style:none;
margin:0;
padding:0;
background-color:clear;
}
li.nav a {
text-align:center;
font-family:"Helvetica";
font-weight:lighter;
text-decoration:none;
display:inline;
background-color:green;
padding:10px;
margin:0;
color:#FF0;
float:none;
}
li.nav a:hover {
text-align:center;
font-family:"Helvetica";
font-weight:lighter;
text-decoration:none;
display:inline;
background-color:blue;
padding:10px;
margin:0;
color:#0FF;
}
li.sub a {
position:relative;
top:2px;
background:pink;
display:block;
margin:0;
padding:10px;
color:red;
width:100px;
}
li.sub a:hover {
position:relative;
top:2px;
background:pink;
display:block;
margin:0;
padding:10px;
color:red;
width:100px;
}
HTML
<li class="nav">Community
<ul>
<li class="sub">Third Age</li>
<li class="sub">Tide Timetables</li>
<li class="sub">Schools</li>
<li class="sub">Religion</li>
<li class="sub">Clubs+Societies</li>
<li class="sub">Courses</li>
<li class="sub">The Council</li>
<li class="sub">Culture</li>
</ul>
</li>
<!--END OF COMMUNITY SECTION-->
<!--START OF EVENTS NAVIGATION BUTTON AND SUBMENU-->
<li class="nav">Events
<ul>
<li class="sub">Festivals</li>
<li class="sub">Family</li>
<li class="sub">Music</li>
<li class="sub">Comedy</li>
<li class="sub">Theatre</li>
<li class="sub">Exhibitions</li>
<li class="sub">Film</li>
<li class="sub">Literature</li>
</ul>
</li>
<!--END OF EVENTS SECTION-->
Try to add this lines in your css.
li.nav{display:inline-block;position:absolute;}
li.nav:nth-child(2)
{margin-left:140px;}
OR
HTML
<div class="main-navigation">
<nav class="navigation">
<ul>
<li>1
<ul class="sub-menu"><li>1a</li><li>1b</li></ul>
</li>
<li>2
<ul class="sub-menu"><li>2a</li><li>2b</li></ul>
</li>
<li>3</li>
<li>4</li>
</ul>
</nav>
</div>
CSS
nav.navigation{
width: 75%;
height:50px;
}
nav ul ul.sub-menu{
display: none;
margin-left:-40px;
margin-top:-10px;
}
nav ul li:hover > ul.sub-menu{
display: block;
}
nav ul{
height:50px;
list-style:none;
padding: 3px 0 0 0;
position: relative;
text-transform: uppercase;
}
nav ul:after{
content:"";
clear:both;
display:block;
}
nav ul li{
float: left;
padding:10px 30px;
background:yellow;
margin-left:5px;
}
nav ul ul.sub-menu{
background-color: #fcfcfc;
padding: 0;
position: absolute;
z-index:100;
top: 100%;
}
nav ul ul.sub-menu li{
float: none;
margin-top: -3px;
height:30px;
background-color:green;
}
The DEMO is here
add float:left; to the li-items.
li
{
float:left;
}
DEMO
you can use display:inline-block level property to all li element.
Is it possible to modify the following code to maintain the hover on for this combination of menu+submenu, using only CSS? The submenu should remain visible if either the main or submenu is hovered. Right now only the main menu hover is working. Thanks!
HTML + CSS below:
<div id="dropnav">
<ul>
<li id="main">One</li>
<li id="main">Two
<ul>
<li>Two A</li>
<li>Two B</li>
<li>Two C</li>
<li>Two D</li>
</ul>
</li>
<li id="main">Three</li>
<li id="main">Four</li>
<li id="main">Five</li>
</ul>
</div>
#dropnav {
height:50px;
width: 100%;
text-decoration: none;
margin-left:auto;
margin-right:auto;
margin-top: 10px;
}
#dropnav ul{
margin:0px;
padding:0px;
text-align: center;
}
#dropnav ul li{
display:inline;
float:left;
list-style:none;
margin-left:auto;
position:relative;
height:25px;
width: 20%;
font-size: 20px;
font-family: 'Cabin', Helvetica, Arial;
}
#dropnav ul li ul{
margin:0px;
padding:0px;
display:none;
position:absolute;
left:0px;
z-index: 99;
top:50px;
}
#dropnav ul li:hover > ul{
display:block;
width:500px;
left: -50%;
}
#dropnav ul li ul li:hover > a{
color:#FFFFFF;
text-decoration:none;
display:block;
width:500px;
left: -50%;
}
Try changing your submenu style to:
#dropnav ul li ul {
margin:0px;
padding:0px;
display:none;
position:relative;
left:0px;
z-index: 99;
top:0px;
padding-top: 50px;
}
Demo Fiddle
hello
what i am trying to is to create a sub menu from a sub menu. for example if a user hovers over Actions this then drops to show say billing - mail etc. i would like to create another sub if a user hovers over billing. i have attached the code i am using which is stu nicholls pro dropdown. thanks
menu css
.nav {
height:35px;
background: url(images/pro_line_0.gif) repeat-x;
margin-top:100px;
position:relative;
font-family:arial, verdana, sans-serif;
font-size:11px;
width:100%;
z-index:500;
}
.nav .table {
display:table;
}
.nav .select,
.nav .current {
margin:0;
padding:0;
list-style:none;
display:table-cell;
white-space:nowrap;
}
.nav li {
margin:0;
padding:0;
height:auto;
float:left;
}
.nav .select a {
display:block;
height:35px;
float:left;
padding:0 5px 0 30px;
text-decoration:none;
line-height:35px;
white-space:nowrap;
color:#fff;
}
.nav .current a {
display:block;
height:35px;
float:left;
background: url(images/pro_line_2.gif);
padding:0 0 0 10px;
text-decoration:none;
line-height:35px;
white-space:nowrap;
color:#fff;
}
.nav .current a b {
display:block;
padding:0 30px 0 15px;
background:url(images/pro_line_2.gif) right top;
}
.nav .select a:hover,
.nav .select li:hover a {
padding:0 0 0 15px;
cursor:pointer;
color:#088;
}
.nav .select a:hover b,
.nav .select li:hover a b {
display:block;
float:left;
padding:0 5px 0 15px;
cursor:pointer;
}
.nav .select_sub {
display:none;
}
/* IE6 only */
.nav table {
border-collapse:collapse;
margin:-1px;
font-size:1em;
width:0;
height:0;
}
.nav .sub {
display:table;
padding:0;
list-style:none;
}
.nav .sub_active .current_sub a,
.nav .sub_active a:hover {
background:transparent;
color:#f00;
}
.nav .select :hover .select_sub,
.nav .current .show {
display:block;
position:absolute;
width:100%;
top:35px;
background:url(images/back_0.gif);*/
padding:0;
z-index:100;
left:0px;
text-align:left;
}
.nav .current .show {
z-index:10;
}
.nav .select :hover .sub li a,
.nav .current .show .sub li a {
display:block;
float:left;
background:transparent;
padding:0 5px 0 30px;
margin:0;
white-space:nowrap;
border:0;
color:#444;
}
.nav .current .sub li.sub_show a {
color:#088;
cursor:default;
/*background:url(images/back_1.gif);*/
}
.nav .select :hover .sub li a:hover,
.nav .current .sub li a:hover {
visibility:visible;
font-weight:bold;
/*background:url(images/back_1.gif);*/
}
sample html
<ul class="select"><li><a href="#nogo"><b>Control Panel</b>
<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<div class="select_sub show">
<ul class="sub">
<li>Tickets</li>
<li>Messages</li>
<li>Actions</li>
<li>History</li>
<li>Settings</li>
<li>Destruction</li>
<li>Contacts</li>
<li>Users</li>
<li>Companies</li>
</ul>
</div>
Try using nested <ul>s in your HTML. That is, build your menu like so:
<ul class="menu">
<li>
<a>My Link</a>
<ul class="submenu">
<li><a>My Nested Link</a></li>
</li>
</ul>
Then use a simple Javascript solution like Superfish (or one of your chosing)
http://users.tpg.com.au/j_birch/plugins/superfish/