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..
Related
I like to know how bootstrap3 drop-down-menu system in its tutorial page works.
1. It folds all to main topic by default (you can click or scroll-up/down to expand)
2. It expands automatically when you scroll up and down or click particular menu.
3. It matches you with the topic and has some hi-light in the sub-menu
http://getbootstrap.com/css
Can this matching only complete with only css and html, or it has to deal with JavaScript also?
If it can be both way what is the suit case for it uses.
This is PURE CSS solution of bootstrap dropdown menu, here is working fiddle
http://jsfiddle.net/DTcHh/1837/
HTML
<nav>
<ul>
<li>
Has Dropdown
<ul>
<li>
Change password </li>
<li>
Edit personal data
</li>
</ul>
</li>
<li>
Support
</li>
<li>
Logout
</li>
</ul>
</nav>
CSS
nav > ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
color: #555;
}
nav > ul li {
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 10px;
background: #fff;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
nav > ul li:hover {
background-color: #e7e7e7;
color: #555;
}
nav > ul li ul {
padding: 0;
position: absolute;
top: 48px;
left: 0;
min-width: 225px;
display: none;
opacity: 0;
visibility: hidden;
background-color: #fff;
border: 1px solid rgba(0, 0, 0, 0.15);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.176);
font-size: 14px;
list-style: outside none none;
padding: 5px 0;
text-align: left;
z-index: 10000;
}
nav > ul li ul li {
background-color: transparent;
display: block;
color: #262626;
width:90%;
text-align:left;
padding-left:10px;
padding-right:10px;
text-transform:uppercase;
}
nav > ul li ul li:hover {
background-color: #f5f5f5;
color: #262626;
text-decoration:none;
}
nav > ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
ul li ul a li i{
padding-right:5px;
}
nav ul li ul a li{
color:grey !important;
}
nav ul li ul a{
color:grey;
font-size:12px;
}
I am looking for help on this navigation bar, I need it to be able to drop down while keeping the other items of the navigation bar in place. I have looked through all of the other submissions and still didn't find anything that helped. Here is the code and example.
http://jsfiddle.net/doctor_turkey/G2xfz/
<html>
<style>
#div5 {
background-color: black;
-webkit-box-shadow: 0px 0px #000000;
box-shadow:0px 5px 5px #5B5454;
width: 100%;
clear: both;
margin-left: -1%;
margin-right:-1%;
padding-left:1%;
padding-right:1%;
}
#div5 ul{
margin: 0 0 0 60px;
padding: 0px;
list-style: none;
}
#div5 ul li{
display: inline;
-webkit-box-shadow: 0px 0px #000000;
box-shadow: 0px 0px #000000;
position:relative;
}
#div5 ul li a{
float: left;
width: 15%;
height: 20px;
margin-top: -5px;
margin-bottom: 10px;
padding: 0;
font-size: 15px;
font-weight: none;
text-align: center;
text-decoration: none;
color: black;
border-left: 1px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
}
#div5 ul li .firstmenu{
border-left: 2px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
-webkit-box-shadow: 0px 0px;
box-shadow: 0px 0px;
}
#div5 ul li .smallmenuend{
border-left: 1px solid #CCCCCC;
border-right: 2px solid #CCCCCC;
}
/* HOVER MENU TEST*/
#div5 li ul {
float: left;
left: 0;
opacity: 0;
position:relative;
display:none;
z-index: 1;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#div5 li:hover ul {
opacity: 1;
/* top: 50px;*/
display:block;
float: left;
color:black;
clear:left;
display:block;
margin-left:20%;
}
#div5 li ul li {
clear:left;
color:black;
display:block;
width:100%;
}
#div5 li ul li a{
width:100%;
}
#div5 li ul a:hover {
background: #bbb;
}
</style>
<div id="div5" class="fluid">
<p align="center">
<div align="center">
<ul>
<li> One</li>
<li> Two
<ul>
<li> Test 1 </li>
<li> Test 2 </li>
</ul>
</li>
<li><a href="#" >Three</a></li>
<li> Four </li>
<li>Five</li>
<li >Six</li>
</ul>
</div>
</p>
</div>
Your code needs a lot of work - it is a soup of unnecessary markup and styles.
Here's a cleaned up version of this navigation bar. You are welcome to study this code and optimize yours.
HTML:
<ul id = "nav">
<li>Home</li>
<li>Energy
<ul>
<li>Test 1</li>
<li>Test 2</li>
</ul>
</li>
<li>Account</li>
<li>Contact</li>
<li>Services</li>
<li >Solutions</li>
</ul>
CSS:
* {
margin: 0;
padding: 0;
}
body {
background-color: #eee;
}
#nav {
list-style-type: none;
display: table;
min-width: 610px;
margin: 0 auto;
background-color: #fff;
text-align: center;
}
#nav > li {
display: inline-block;
position: relative;
}
#nav ul {
list-style-type: none;
background-color: #5f6975;
position: absolute;
min-width: 100%;
}
#nav li a {
font: normal 15px/1 Sans-Serif;
text-decoration: none;
color: #4b545f;
display: block;
padding: 10px 20px;
text-align: left;
white-space: nowrap;
}
#nav ul a {
color: #fff;
}
#nav ul > li + li {
border-top: 1px solid #6b727c;
}
#nav li:hover {
background-color: #4b545f;
}
#nav > li:hover > a {
color: #fff;
}
#nav ul {
display: none;
}
#nav li:hover > ul {
display: block;
}
And, a fiddle: http://jsfiddle.net/bE2D2/.
im using ready made dropdown menu from http://cssmenumaker.com/menu/grey-red-drop-down-menu
the menu is working pretty fine but i like to center the buttons.Is there any way to do that?
Here is the css code:
#import url(http://fonts.googleapis.com/css?family=Open+Sans:600);
/* Menu CSS */#cssmenu,
#cssmenu > ul {
background: url(images/highlight-bg.png) repeat;
padding-bottom: 3px;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
}
#cssmenu:before,
#cssmenu:after,
#cssmenu > ul:before,
#cssmenu > ul:after {
content: '';
display: table;
}
#cssmenu:after,
#cssmenu > ul:after {
clear: both;
}
#cssmenu {
width: auto;
zoom: 1;
}
#cssmenu > ul {
background: url(images/menu-bg.png) repeat;
margin: 0;
padding: 0;
position: relative;
}
#cssmenu > ul li {
margin: 0;
padding: 0;
list-style: none;
}
#cssmenu > ul > li {
float: left;
position: relative;
}
#cssmenu > ul > li > a {
padding: 23px 26px;
display: block;
color: white;
font-size: 13px;
text-decoration: none;
text-transform: uppercase;
text-shadow: 0 -1px 0 #0d0d0d;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);
line-height: 18px;
}
#cssmenu > ul > li:hover > a {
background: url(images/highlight-bg.png) repeat;
text-shadow: 0 -1px 0 #97321f;
text-shadow: 0 -1px 0 rgba(122, 42, 26, 0.64);
}
#cssmenu > ul > li > a > span {
line-height: 18px;
}
#cssmenu > ul > li.active > a,
#cssmenu > ul > li > a:active {
background: url(images/hover.png) repeat;
}
/* Childs */
#cssmenu > ul ul {
opacity: 0;
visibility: hidden;
position: absolute;
top: 120px;
background: url(images/menu-bg.png) repeat;
margin: 0;
padding: 0;
z-index: -1;
}
#cssmenu > ul li:hover ul {
opacity: 1;
visibility: visible;
margin: 0;
color: #000;
z-index: 2;
top: 64px;
left: 0;
}
#cssmenu > ul ul:before {
content: '';
position: absolute;
top: -10px;
width: 100%;
height: 20px;
background: transparent;
}
#cssmenu > ul ul li {
list-style: none;
padding: 0;
margin: 0;
width: 100%;
}
#cssmenu > ul ul li a {
padding: 18px 26px;
display: block;
color: white;
font-size: 13px;
text-decoration: none;
text-transform: uppercase;
width: 150px;
border-left: 4px solid transparent;
-webkit-transition: all 0.35s ease-in-out;
-moz-transition: all 0.35s ease-in-out;
-ms-transition: all 0.35s ease-in-out;
transition: all 0.35s ease-in-out;
}
#cssmenu > ul ul li a:hover {
border-left: 4px solid #d64e34;
background: url(images/hover.png) repeat;
}
#cssmenu > ul ul li a:active {
background: url(images/menu-bg.png) repeat;
}
Here is the basic html code:
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>Products</span></a>
<ul>
<li><a href='#'><span>Product 1</span></a></li>
<li class='last'><a href='#'><span>Product 2</span></a></li>
</ul>
</li>
<li><a href='#'><span>About</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
If you want to center the main menu links, you could try this:
#cssmenu ul {text-align: center;}
#cssmenu ul li {float: none; display: inline-block;}
Rather than float: none, you can just remove the original float on the lis.
If you are worried about the inline-block gaps that appear between the menu items, you could do this:
#cssmenu ul {text-align: center;display: table; width: 100%; word-spacing:-.25em;}
#cssmenu ul li {float: none; display: inline-block; word-spacing:0;}
To avoid the submenu text being centered, try this:
#cssmenu ul {text-align: center;display: table; width: 100%; word-spacing:-.25em;}
#cssmenu ul > li {float: none; display: inline-block; word-spacing:0;}
#cssmenu ul li li {text-align: left;}
My css code is:
.horizontalcssmenu ul{
margin: 0;
padding: 0;
list-style-type: none;
list-style:none;
}
.horizontalcssmenu ul a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
/*Top level list items*/
.horizontalcssmenu ul li{
position: relative;
display: inline;
float: left;
height: 34px;
top: 25px;
left: 111px;
width: 71px;
margin-left: 0px;
}
.horizontalcssmenu ul li a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
/*Top level menu link items style*/
.horizontalcssmenu ul li a{
border-left: 2px solid #202020;
border-right: 2px solid #202020;
border-top: 2px solid #202020;
border-bottom: 2px solid #202020;
display: block;
width: 54px; /*Width of top level menu link items*/
padding: 2px 8px;
text-decoration: none;
background: url(menubg.gif) center center repeat-x;
color: Red;
font: bold 13px Tahoma;
height: 27px;
margin-left: 0px;
}
/*Sub level menu*/
.horizontalcssmenu ul li ul{
left: 0;
top: 0;
border-top: 1px solid #202020;
position: absolute;
display: block;
visibility: hidden;
z-index: 100;
}
.horizontalcssmenu ul li ul a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
/*Sub level menu list items*/
.horizontalcssmenu ul li ul li{
display: inline;
float: none;
}
.horizontalcssmenu ul li ul li a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
/* Sub level menu links style */
.horizontalcssmenu ul li ul li a{
width: 100px; /*width of sub menu levels*/
font-weight: normal;
padding: 2px ;
background: #663300;
border-width: 1px 1px 1px;
}
.horizontalcssmenu ul li ul li a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
.horizontalcssmenu ul li a:hover{
color: #0066FF;
background: #FF0033;
text-decoration: none;
}
.horizontalcssmenu ul li a:active{
color: #00FFFF;
background: #FF0033;
text-decoration: none;
}
.horizontalcssmenu ul li ul li a:hover{
color: #00FFCC;
background: #CCCC66
}
.horizontalcssmenu .arrowdiv{
position: absolute;
right: 1;
background: transparent url(image/bg-bubplastic-button.gif) no-repeat center left;
}
* html p#iepara{ /*For a paragraph (if any) that immediately follows menu, add 1em top spacing between the two in IE*/
padding-top: 1em;
}
/* Holly Hack for IE \*/
* html .horizontalcssmenu ul li { float: left; height: 1%; }
* html .horizontalcssmenu ul li a { height: 1%; }
/* End */
When the user moves to the specified page, the button color should change and remain the same as long as he is in that page. How can I do this?
You could simply tag your <body> tags with ids, and then make CSS selectors from there. Example: http://css-tricks.com/id-your-body-for-greater-css-control-and-specificity/
There's no css selector link state for what you want to achieve.You should use some Php to check the page you're at and style the button right after
Below is the css for my menu
#menu
{
position: absolute;
left: 170px;
top: 92px;
background: #336699;
float: left;
z-index:50;
}
#menu ul
{
list-style: none;
margin: 0;
padding: 0;
width: 9em;
float: left;
}
#menu a, #menu h2
{
font: bold 11px/20px arial, helvetica, sans-serif;
display: block;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
border-style: solid;
border-color: #ccc #888 #555 #bbb;
margin: 0;
padding: 4px 3px;
}
#menu h2
{
color: #fff;
background: #336699;
text-transform: uppercase;
border-top-width: 0px;
border-bottom-width: 0px;
border-left-width: 1px;
border-right-width: 1px;
}
#menu a
{
color: #fff;
background: #79A3CF;
text-decoration: none;
}
#menu a:hover
{
color: #a00;
background: #fff;
}
#menu li
{
position: relative;
}
#menu li ul li
{
position: relative;
width: 12em;
}
#menu ul ul
{
position: absolute;
z-index: 500;
}
#menu ul ul ul
{
position: absolute;
top: 0;
left: 100%;
}
div#menu ul ul, div#menu ul li:hover ul ul, div#menu ul ul li:hover ul ul
{
display: none;
}
div#menu ul li:hover ul, div#menu ul ul li:hover ul, div#menu ul ul ul li:hover ul
{
display: block;
}
Here is my html design for the menu. It is a horizontal menu with dropdown submenus
<div id="menu">
<ul>
<li><h2>Computers</h2>
<ul>
<li>subitem
<ul><li>subitems</li>
</li>
<li>submitem</li>
<li>submitem</li>
</li>
<li><h2>Network</h2>
<ul><li>subitems</li>
</li>
</ul>
</div>
I am using the minified version of the whatever hover script. Checked few posts here on this issue but couldn't solve the problem. The submenus are not appearing on IE6 and IE7. I trid adding
<!--[if lt IE 8]>
but no results...
Your HTML is poorly formed. ** indicates additions.
<div id="menu">
<ul>
<li><h2>Computers</h2>
<ul>
<li>subitem
<ul><li>subitems</li>**</ul>**
</li>
<li>submitem</li>
<li>submitem</li>
**</ul>**
</li>
<li><h2>Network</h2>
<ul><li>subitems</li>**</ul>**
</li>
</ul>
</div>
One good way to check for poorly formed html and other html problems is to validate your html in the w3c validator here.By using the validator to make sure my html is compliant, I can usually weed out browser discrepancies issues pretty easily.