Same style repeating for sublinks - css

I'm making a navigation bar. Here's the reference link
The problem is the style I've applied for Main Tabs is repeating for Sub Links as well. I've created separate class for the sub links("nav2"). It works fine in Chrome & Mozilla Firefox, but not able to solve this issue in IE. Please Help, Its bit urgent.
Here's my code
HTML:
<div id="menu">
<ul id="nav">
<li>Tab1
<ul id="nav2">
<li>Menu 1 Submenu item 1</li>
<li>Menu 1 Submenu item 2</li>
<li>Menu 1 Submenu item 3</li>
</ul>
</li>
<li>Tab2
<ul id="nav2">
<li>Sub Link for tab 2</li>
<li>Some other link</li>
<li>Some othe rlink</li>
</ul>
</li>
<li>Tab3</li>
<li>Tab4</li>
</li>
</ul>
</div>
Here's the css
CSS:
#menu {
width: 100%;
height: 35px;
clear: both;
}
ul#nav {
float: left;
width:100%;
margin: 0;
padding: 0;
list-style: none;
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-webkit-border-top-left-radius: 5px;
}
ul#nav li {
display: inline;
}
ul#nav li a {
float: left;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:bold;
line-height: 35px;
color: #7e764c;
text-decoration: none;
text-shadow: 1px 1px #ffffff;
margin:0 4px 0 0;
padding: 0 15px;
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-webkit-border-top-left-radius: 5px;
background: #fff3b3;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffce9', endColorstr='#fff3b3');
background: -webkit-gradient(linear, 0 0, 0 70%, from(#fffce9), to(#fff3b3));
background: -moz-linear-gradient(#fffce9, #fff3b3 70%);
background: linear-gradient(#fffce9, #fff3b3 70%);
-pie-background: linear-gradient(#fffce9, #fff3b3 70%);
behavior: url(PIE.htc);
}
ul#nav .current a, ul#nav li:hover > a {
color: #353535;
text-decoration: none;
text-shadow: 1px 1px #ffe8a1;
background: #fecf3a;
-moz-border-radius-topright: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-webkit-border-top-left-radius: 5px;
}
ul#nav ul {
display: none;
}
ul#nav2 li a {
background:none;
}
ul#nav li:hover > ul {
position: absolute;
display: block;
width: 100%;
height: 35px;
position: absolute;
margin: 35px 0 0 0;
background-color:#fecf3a;
border-bottom:1px solid #c3aa6f;
}
ul#nav li:hover > ul li {
float: left;
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:normal;
line-height: 35px;
color: #86610b;
text-decoration: none;
margin: 0;
background:url(../img/line1.jpg) no-repeat right 15px;
}
ul#nav li:hover > ul li a {
float: left;
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:normal;
line-height: 35px;
color: #86610b;
text-decoration: none;
margin: 0;
background:url(../img/arrow-btm2.png) no-repeat center 28px;
}
ul#nav li:hover > ul li a:hover {
color: #86610b;
text-decoration: none;
text-shadow: none;
}
Thanks in Advance

First: You have not added a class to the submenus. You have added the id "nav2" and ids should be unique. You should change this to class="nav2" and use .nav2 instead of #nav2 in your css to target that.
There are two good ways to solve this.
1)
Create classes for the toplevel items. Something like:
<ul id="nav">
<li class="navLevel1">Tab1
And then you change ul#nav li to .navLevel1 and ul#nav li a to .navLevel1 > a in your css.
2)
Change ul#nav li to #nav > li and #nav li a to #nav > li > a in your css
Note:
I used the child selector(>) which means you only select direct children of the element instead of descendants.

Related

Adding sub-menu to vertical menu CSS

This should be vertical menu with 2nd level sub menu as you can see 2 2.1 2.2
I tried many tutorials but just couldn't make it work i know lot of code for sub-menu is missing but honestly i have no idea what to do with it to fix it .
.menu ul li a {
margin: 2px;
padding: 2px;
font-family: comic sans ms;
border-bottom: 1px solid #ccc;
height: 25px;
width: 160px;
-moz-border-radius: 1em 4em 1em 4em;
border-radius: 1em 4em 1em 4em;
border-color: red;
cursor: pointer;
cursor: url(link.cur), auto;
text-decoration: none;
color: white;
padding: 9px 11px;
background-color: grey;
display: block;
}
.menu ul li a:visited {
color: white;
}
.menu ul li a:hover,
.menu_simple ul li .current {
color: white;
background-color: #0099CC;
/* green #5FD367 */
}
.menu ul li ul {
position: absolute;
display: none;
}
.menu ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
.menu ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
<div class="menu">
<ul>
<li>1
</li>
<li>2
<ul>
<li>2.1
</li>
<li>2.2
</li>
</ul>
<li>3
</li>
<li>4
</li>
</ul>
</div>
Here you go.. why did you use absolute to .menu ul li ul this code was causing problem !!
.menu ul li a {
margin: 2px;
padding: 2px;
font-family: comic sans ms;
border-bottom: 1px solid #ccc;
height: 25px;
width: 160px;
-moz-border-radius: 1em 4em 1em 4em;
border-radius: 1em 4em 1em 4em;
border-color: red;
cursor: pointer;
cursor: url(link.cur), auto;
text-decoration: none;
color: white;
padding: 9px 11px;
background-color: grey;
display: block;
}
.menu ul li a:visited {
color: white;
}
.menu ul li a:hover,
.menu_simple ul li .current {
color: white;
background-color: #0099CC;
/* green #5FD367 */
}
.menu ul li ul {
display: none;
}
.menu ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
.menu ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
<div class="menu">
<ul>
<li>1
</li>
<li>2
<ul>
<li>2.1
</li>
<li>2.2
</li>
</ul>
<li>3
</li>
<li>4
</li>
</ul>
</div>

Responsive menu not showing all my dropdown menus in mobile version

If you reduce my test page here: http://www.linestop.com/Linestop2015/index.php
To display the mobile dropdown menu you will notice that not all my submenu items are displaying. How can I fix this? Can you help me?
Here is my CSS
#navigation { padding:0 21px; margin-bottom: 0; }
.sf-menu{
margin-bottom: 0;
}
.top-nav,.sf-menu li{
background: transparent;
}
.sf-arrows .sf-with-ul:after{
border-top-color: #ff9000;
}
.sf-menu ul li,.sf-menu ul ul li,.sf-menu ul ul ul li {
background: #fff;
}
.sf-menu li:hover, .sf-menu li.sfHover {
background: #ff9000;
}
.sf-menu a{
color: #070707;
border:none;
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
font-size: 1.2em;
padding-left: 2em;
padding-right: 2em;
}
.small-top-menu{
display: none
}
.small-top-menu select{
padding: 5px;
background: #68ceef;
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
border:5px solid #fff;
margin: 10px 0;
}
.small-top-menu select option{
padding: 10px;
}
#navigation ul li a { color: #4a4a4a; padding: 0 7px; display:block; height: 21px; line-height: 21px; border: 2px solid transparent; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; width:100% }
#navigation ul li.active a,
#navigation ul li a:hover { border: 2px solid #029cdb; background: url(images/nav-btn.png) repeat-x 0 0; color:#fff; text-decoration: none; }
#navigation a.nav-btn { display:none; }
Here is my mobile menu css
#navigation { position:relative; z-index: 100; padding:0 0px; margin:0 10px; }
#navigation a.nav-btn { margin-bottom: 15px; text-decoration: none; padding:0 36px 0 10px; line-height:30px; display:block; background: url(images/navigation.png) repeat-x 0 0; height: 30px; position: relative; }
#navigation a.nav-btn span { background: url(images/dd-nav-arrs.png) no-repeat 0 bottom; width: 20px; height: 15px; position:absolute; top: 8px; right: 12px; }
#navigation a.nav-btn.active span { background-position:0 0; }
#navigation ul { display:none; position: absolute; top: 30px; left: 0; width: 100%; }
#navigation ul li { float:none; height: 30px; border-top: 1px solid #fff; display:block; padding:0 0 0 0; background: url(images/navigation.png) repeat-x 0 0; }
#navigation ul li a { border: 0; line-height:30px; float:none; height: 30px; display: block; font-size: 14px; padding-left: 20px; padding-right: 20px; width:100%; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; -o-border-radius: 0px; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; }
#navigation ul li a:hover { background-image:url(images/blue-btn.png); border:0; }
#navigation ul li.active span { background: transparent; border:0; }
#navigation ul li.first { display:block; }
Here is my html code
<nav id="navigation"> HOME<span></span>
<section>
<ul class="sf-menu large-12">
<li class="active">Home</li>
<li class="has-dropdown">Services
<ul class="dropdown">
<li class="has-dropdown">Hottap Services
<ul class="dropdown">
<li>Hottap Free Quote</li>
</ul>
</li>
<li>Linestop Services
<ul class="dropdown">
<li>Linestop Free Quote</li>
</ul></li>
<li>Valve Installations Services
<ul class="dropdown">
<li>Valve Install Free Quote</li>
</ul></li>
<li>Pipeline Bypass Services
<ul class="dropdown">
<li>Pipe Bypass Free Quote</li>
</ul></li>
</ul>
</li>
<li class="has-dropdown">Line Stop Equipment
<ul class="dropdown">
<li class="has-dropdown">Hottap Machines
<ul class="dropdown">
<li>Small Machines</li>
<li>Large Machines</li>
</ul>
</li>
<li>Linestop Machines
<ul class="dropdown">
<li>QualTech QT Linestop Machines</li>
<li>IFT Soft Stop 100</li>
<li>IFT Top Pivot Stop 1000</li>
<li>IFT Folding Heads</li>
</ul></li>
<li>Hottap / Linestop Fittings
<ul class="dropdown">
<li>IFT 499 Fittings Copper, Steel & PVC</li>
<li>IFT Mechanical Joint Fittings</li>
<li>IFT Stainless Steel Hottap Linestop Fittings</li>
<li>IFT On-Size Folder Weld Type Fittings</li>
<li>IFT 400 Series Fittings CMLC</li>
<li>IFT 500 Series Fittings CMLC</li>
<li>AWWA - Fittings</li>
<li>Flanged Steel Knife Gate Valves</li>
<li>Completion Plug Assemblies</li>
</ul></li>
<li>All 2.5"-54.6" Linestop™ Cups</li>
</ul>
</li>
<li class="has-dropdown">About us
<ul class="dropdown">
<li>Contact Us</li>
<li>Customers</li>
<li>Location</li>
<li>Job Application</li>
<li>Online Flip Catalog</li>
<li>Facebook Fan Page</li>
</ul>
</li>
<li>Featured Jobs</li>
</ul>
</section>
<div class="cl"> </div>
</nav>
Thanks, Jesse
Look at the #navigation ul styling, the position: absolute; property should only be applied to the first UL ('.sf-menu'). Also check the .sf-menu ul styling, it should have an absolute position. And remove the height from #navigation ul li, because some li items have sub menus but you can't see them because the height is only 30px.
I figured out the answer to my issue. trying to make the menu too complex there were no easy fixes. So i had to go back to the original code and just use the mobile menu for the main navigation menu. Seems to work fine... Thanks for for the help!

Horizontal sub menu issue

I am facing a problem regarding horizontal submenu that needs to push down body content. But I am not getting it. I have tried out few things with different css. And I want to be done using CSS since it would be a responsive menu with 100% div. So I can't give any pixel width in sub ul. I have almost done it but main menu got push down when I hover on it. I know there might be a solution for this using CSS code and it would be great if someone can help me out on this. And if its can't be done with CSS then I would like to know if there is any jquery solution for it or not. Here I am sharing my CSS along with HTML.
""There are 3 menus in the given css and html and also you can see it in jsfiddle link as well that Menu 1 and Menu 2 submenu along with Body Content got push down but Menu 3 is working fine. I want to fix the Menu 1 and Menu 2 just like the Menu 3.""
Any help would be appreciated.
Thanks, Roy
HTML
<div id="menu">
<ul id="nav">
<li>Menu 1
<ul>
<li>fdesfc</li>
<li>drgdrg</li>
<li>dgvdvg</li>
</ul>
</li>
<li>Menu 2
<ul>
<li>iuoluiouo</li>
<li>abcde</li>
<li>bhnhbnh</li>
</ul>
</li>
<li>Menu 3
<ul>
<li>Menu 3 Submenu item 1</li>
<li>Menu 3 Submenu item 2</li>
<li>Menu 3 Submenu item 3</li>
</ul>
</li>
</ul>
</div>
<div class="clear"></div>
<div class="contArea">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</div>
CSS
#menu{
width: 100%;
height: 40px;
clear: both;
}
ul#nav {
float: left;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
background: #dc0000;
-moz-border-radius-topright: 10px;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topleft: 10px;
-webkit-border-top-left-radius: 10px;
}
ul#nav li {display: inline;}
ul#nav li a {
float: left;
font: bold 1.1em arial, verdana, tahoma, sans-serif;
line-height: 40px;
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 1px #880000;
margin: 0;
padding: 0 30px;
background: #dc0000;
-moz-border-radius-topright: 10px;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topleft: 10px;
-webkit-border-top-left-radius: 10px;
}
ul#nav ul {
display: none;
position: absolute;
}
ul#nav li:hover > ul {
position: relative;
display: block;
height: 45px;
margin: 40px 0 0 0;
background: #aa0000;
-moz-border-radius-bottomright: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomleft: 10px;
-webkit-border-bottom-left-radius: 10px;
}
ul#nav li:hover > ul li a {
float: left;
font: bold 1.1em arial, verdana, tahoma, sans-serif;
line-height: 45px;
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 1px #110000;
margin: 0;
padding: 0 30px 0 0;
background: #aa0000;
}
ul#nav li:hover > ul li a:hover {
color: #120000;
text-decoration: none;
text-shadow: none;
}
.clear {
clear: both;
}
.contArea {
background: #ccc;
padding: 12px;
}
(on JSFiddle: http://jsfiddle.net/indy12/QG9L5/1/)
I assumed this is what u expect
http://jsfiddle.net/QG9L5/6/
add appropriate width and float to main(li) list item and sub lists (ul).
#menu {
width: 100%;
height: 40px;
clear: both;
}
ul#nav {
float: left;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
background: #dc0000;
-moz-border-radius-topright: 10px;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topleft: 10px;
-webkit-border-top-left-radius: 10px;
}
ul#nav li {
display: inline;
}
ul#nav li.main{
float:left; width:150px;
}
ul#nav li a {
float: left;
font: bold 1.1em arial, verdana, tahoma, sans-serif;
line-height: 40px;
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 1px #880000;
margin: 0;
padding: 0 30px;
background: #dc0000;
-moz-border-radius-topright: 10px;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topleft: 10px;
-webkit-border-top-left-radius: 10px;
}
ul#nav ul {
display: none;
position: absolute;
width:500px;
}
ul#nav li:hover > ul {
position: relative;
display: block;
height: 45px;
margin: 40px 0 0 0;
background: #aa0000;
-moz-border-radius-bottomright: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomleft: 10px;
-webkit-border-bottom-left-radius: 10px;
}
ul#nav li:hover > ul li a {
float: left;
font: bold 1.1em arial, verdana, tahoma, sans-serif;
line-height: 45px;
color: #fff;
text-decoration: none;
text-shadow: 1px 1px 1px #110000;
margin: 0;
padding: 0 30px 0 0;
background: #aa0000;
}
ul#nav li:hover > ul li a:hover {
color: #120000;
text-decoration: none;
text-shadow: none;
}
.clear {
clear: both;
}
.contArea {
background: #ccc;
padding: 12px;
}

CSS issue: multiple CSS with the same element

<div id="nav">
<ul id="rightMin">
<li id="selectedmenu" onclick="location.href='index.php'">main</li>
<li onclick="location.href='aboutus.php'">about</li>
<li>contact us</li>
</ul>
</div>
CSS:
#selectedmenu {
display:inline;
float:right;
/*padding: 2px 7px 0px 7px;*/
height: 35px;
background: url('../images/selected.png') repeat-x;
cursor: pointer;
text-align: center;
line-height:35px;
padding: 0 5px 0 5px;
color: white;
}
div#nav ul li {
display:inline;
float:right;
/*padding: 2px 7px 0px 7px;*/
height: 35px;
cursor: pointer;
text-align: center;
line-height:35px;
padding: 0 5px 0 5px;
}
div#nav ul li:hover {
background: #232323;
color:#fff;
}
The element with the ID selectedmenu takes CSS #selectedmenu but when hovering it takes div#nav ul li:hover. how can i make it sticks with #selectedmenu
div#nav ul li#selectedmenu:hover {
add your css rules here...
}
Give selectedmenu a higher precedence:
div#nav ul li#selectedmenu {
...
}
just change it every time you hover it, try this:
div#nav ul li #selectedmenu:hover{ /* the style for #selectedmenu*/ }
hope this helps..

first-child is not working properly in my css code

I have a problem using first-child
I have the following html code to make a menu with first and second levels
<ul id="navMenu" >
<li class="parent">Home
</li>
<li class="parent">Products
<ul ><li>Software
<ul>
<li>Product 1</li>
<li>Product 2</li>
<li>Product 3</li>
</ul>
</li>
<li>Hardware
<ul>
<li>Product 1</li>
<li>Product 2</li>
</ul>
</li>
</ul>
</li>
</ul>
and the following css
#menuContainer{
float: right;
}
ul#navMenu{
margin: 25px 0 0;
list-style: none outside none;
}
ul#navMenu li{
float: left;
margin: 0 0 0 0px;
position: relative;
z-index: 999;
}
ul#navMenu li a{
display: block;
padding: 5px 0px;
font-size: 13px;
line-height: 12px;
background: transparent;
color: #444;
-webkit-transition: background-color 0.1s linear, color 0.1s linear;
-moz-transition: background-color 0.1s linear, color 0.1s linear;
}
ul#navMenu li.parent a{
padding-right: 23px;
background-color: transparent;
background-repeat: no-repeat;
background-position: right top;
font-family: "Lucida Grande", Tahoma, Arial, sans-serif;
text-transform: uppercase;
}
ul#navMenu li a:hover, ul#navMenu li.current a{
color: #CB0167 ;
text-decoration: none;
font-family: "Lucida Grande", Tahoma, Arial, sans-serif;
}
ul#navMenu li.parent a:hover, ul#navMenu li.current.parent a{
background-position: right bottom;
}
/* - -- --- ---- Sub-Menu ---- --- -- - */
ul#navMenu li.parent ul{
display: none;
position: absolute;
top: 25px;
left: 0;
width: 160px;
margin: 0;
padding: 0px 0 0;
list-style: none outside none;
overflow: visible;
z-index: 99;
border-top: 1px solid #eee;
}
.noJs ul#navMenu li.parent:hover ul{
display: block;
}
ul#navMenu li.parent ul li{
float: none;
margin: 0;
padding: 0;
}
ul#navMenu li.parent ul li a{
display: block;
padding: 7px 10px;
color: #444;
background: #fff;
font-size: 11px;
border-right: 1px solid #eee;
border-left: 1px solid #eee;
text-transform: none;
background-image: url('../img/dots_menu.png');
background-repeat: no-repeat;
}
ul#navMenu li.parent ul li:first-child a{
background-image: none;
}
ul#navMenu li.parent ul li:first-child a:hover{
background-image: none;
}
ul#navMenu li.parent ul li:last-child a{
box-shadow: 0 1px 0 rgba(0,0,0,0.05);
border-bottom: 1px solid #eee;
}
ul#navMenu li.parent ul li a:hover{
color: #CB0167 !important;
background: #fefefe;
background-image: url('../img/dots_menu.png');
background-repeat: no-repeat;
}
/* - -- --- ---- Second Level Sub-Menu ---- --- -- - */
ul#navMenu li.parent ul li ul{
display: none;
position: absolute;
top: -1px;
left: 159px;
width: 160px;
margin: 0;
padding: 0 0 0 0px;
border-top: 1px solid #eee;
}
ul#navMenu li.parent ul li ul.leftMenu{
left: -168px;
padding: 0 10px 0 0;
}
.noJs ul#navMenu li.parent:hover ul li ul{
display: none;
}
.noJs ul#navMenu li.parent ul li:hover ul{
display: block;
}
ul#navMenu li.parent ul li ul li:first-child a{
background-image: none;
}
ul#navMenu li.parent ul li ul li:first-child a:hover{
background-image: none;
}
The menu product is exactly what I need , and the hardware menu , but the software menu is not working , any idea how to fix it ??
Thanks a lot :)
using the > you can prevent the style affect the grandchild's , so try to change this
ul#navMenu li.parent ul li:first-child a{
to this
ul#navMenu li.parent ul li:first-child > a{
also
ul#navMenu li.parent ul li:first-child a:hover{
with this
ul#navMenu li.parent ul li:first-child > a:hover{
your code is too messed up... you can replicate the same without <ul> and <li>.. here's a small snippet of your menu of home/products .. home you find your solution here..
http://jsfiddle.net/NMrMN/
You can apply the necessary css yo your specific needs.. but,using div's to achieve this would give you more freedom on how to place the elements on the page.. so,this is my solution to what i think is your problem..

Resources