submenu in one line with css - html

I want to make navigation menu like the picture above with hover on Menu. This is my sample code for the navigation menu.
<div id="menu">
<ul>
<li>Menu1
<ul class="submenu">
<li>Menu1Sub1</li>
<li>Menu1Sub2</li>
<li>Menu1Sub3</li>
<li>Menu1Sub4</li>
</ul>
</li>
<li>Menu2
<ul class="submenu">
<li>Menu2Sub1</li>
<li>Menu2Sub2</li>
<li>Menu2Sub3</li>
</ul>
</li>
...
</ul>
</div>
Submenu position are in a line and I also want Submenu position to be exactly same for each Menu if possible.
How to do this with css?
this is what I tried so far not working as I intended.
#menu {
text-decoration:none;
}
#menu li {
line-height:20px;
float:left;
}
#menu li > ul {
display: none;
}
#menu li:hover > ul {
display: block;
}
#menu li ul li {
line-height:13px;
float:left;
position:relative;
}
Any help would be very appreciated.

try this code:
#menu {
position: relative;
background-color: black;
text-decoration:none;
}
#menu li {
background-color: green;
padding: 10px;
height: 30px;
list-style: none;
line-height:30px;
float:left;
}
#menu li > ul {
display: none;
}
#menu > ul > li {
border: 2px solid white;
}
#menu > ul > li:hover {
border: 2px solid black;
}
#menu li:hover > ul {
display: block;
position: absolute;
top: 54px;
left: 0;
}
#menu li ul li {
float:left;
position:relative;
}
DEMO jsfiddle

Related

how to put a single navigation item on the right

good day i need help to separate my navigation bar the WELCOME ADMIN should be on the right side here is my code.
HTML
<div id="menu">
<ul>
<li>item1</li>
<li>item1<ul>
<li>item1</li>
<li>item1</li>
<li>item1</li></ul>
</li>
<li>item1</li>
<li>item1<ul>
<li>item1</li>
<li>item1</li>
<li>item1</li></ul>
</li>
<li class="right"><a href="#" >Welcome Admin</a>
<ul>
<li>Subitem One</li>
li>Subitem Two</li>
<li>Subitem Three</li>
</ul>
</li>
</ul>
</nav>
CSS
#menu {
background:#000;
width:100%;
margin-top:0px;
height:40px;
border-radius: 3px;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
background: #000
padding: 0px;
border-radius: 5px;
float:left;
list-style: none;
margin-top:-20px;
position: relative;
display: inline-table;
}
}
#menu ul:after {
content: ""; clear: both; display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block; margin-top:20px;
padding:10px 5px;
color: #FFF; text-decoration: none;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 80px;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
thankyou for your answers badly need your help for this projects thankyou for those who will answer
You need to specify the width of the ul as 100% otherwise the float:left on it collapses the uls width.
The just float the last li to the right.
JSFiddle Demo
CSS
#menu {
background:#000;
width:100%;
margin-top:0px;
height:40px;
border-radius: 3px;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
background: #000;
width:100%;
padding: 0px;
border-radius: 5px;
float:left;
list-style: none;
margin-top:-20px;
position: relative;
display: inline-table;
}
#menu ul:after {
content: ""; clear: both; display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block; margin-top:20px;
padding:10px 5px;
color: #FFF; text-decoration: none;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 80px;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
#menu ul li.right {
float:right;
}
I have corrected your css and updated here.
html
<div id="menu">
<ul>
<li>item1 </li>
<li>item1
<ul>
<li>item1 </li>
<li>item1 </li>
<li>item1 </li>
</ul>
</li>
<li>item1 </li>
<li>item1
<ul>
<li>item1 </li>
<li>item1 </li>
<li>item1 </li>
</ul>
</li>
<li class="last">
Welcome Admin
<ul>
<li>Subitem One</li>
<li>Subitem Two</li>
<li>Subitem Three </li>
</ul>
</li>
</ul>
</div>
css
#menu {
background:#000;
width:100%;
height:40px;
border-radius: 3px;
float:left;
}
#menu ul ul {
display: none;
}
#menu ul li:hover > ul {
display: block;
}
#menu ul {
padding: 0px;
border-radius: 5px;
list-style: none;
margin:0;
position: relative;
display: block;
}
#menu ul:after {
content:"";
clear: both;
display: block;
}
#menu ul li {
float: left;
}
#menu ul li:hover {
color:#fff;
}
#menu ul li:hover a {
background:#fff;
color: #000;
}
#menu ul li a {
display: block;
padding:0 10px;
color: #FFF;
text-decoration: none;
line-height:40px;
}
#menu ul ul {
background: #fff;
padding:0;
position: absolute;
top: 40px;
box-shadow: 0px 0px 9px rgba(0, 0, 0, 0.15);
}
#menu ul ul li {
float: none;
position: relative;
}
#menu ul ul li a {
padding: 15px 40px;
color: #fff;
}
#menu ul ul li a:hover {
background: #000;
color:#fff;
}
#menu ul li.last {
float:right;
}

CSS, Text-Decoration: Overline

I'm trying to create an overline effect on hover with css. What I have so far is below. Here's the problem I have, the over line appears directly above the text. I want there to be some space b/w them. Here is my site: http://baycity2014.weebly.com, and here's the effect I'm going for: http://www.hartlevin.com. Any advice?
CSS:
#nav-wrap .container {
clear: both;
overflow: hidden;
position: relative;
}
#nav-wrap .container {
/*background:url(nav-bg-medium.jpg) repeat-x top;*/
/*height:45px;*/
}
#nav-wrap .container ul {
list-style: none;
}
#nav-wrap .container ul li {
list-style: none;
float: left;
/* background:url(nav-saperator-medium.jpg) no-repeat right;*/
padding-right:2px;
}
#nav-wrap .container ul > li:first-child a,
#nav-wrap .container ul > li:first-child a:hover,
#nav-wrap .container ul span:first-child li a,
#nav-wrap .container ul span:first-child li a:hover{
border-radius:5px 0px 0px 5px;
}
#nav-wrap .container ul li a {
float: left;
display: block;
font-family: 'Helvetica', san-serif;
color: #000;
padding: 0px 30px;
border: 0px solid;
outline: 0;
list-style-type: none;
font-size: 16px;
line-height:45px;
/*text-shadow: 0px -1px 0px #333333;*/
}
#nav-wrap .container ul li:hover {
/*background:url(nav-saperator-hover-medium.jpg) no-repeat right;*/
}
#nav-wrap .container ul li a:hover {
/*background:url(nav-bg-hover-medium.jpg) repeat-x top ;*/
color: #145D85;
text-decoration:overline;
}
HTML:
<div id="left_content_nav">
<ul class='wsite-menu-default'>
<li id='active'><a href='/'>Home</a>
</li>
<li id='pg886612977153583720'><a href='/about.html'>About</a>
<div class='wsite-menu-wrap' style='display:none'>
<ul class='wsite-menu'>
<li id='wsite-nav-226730044254468285'><a href='/blog.html'><span class='wsite-menu-title'>Blog</span></a>
</li>
</ul>
</div>
</li>
<li id='pg336904325932674008'><a href='/practice-areas.html'>Practice Areas</a>
</li>
<li id='pg342722679661255807'><a href='/press.html'>Press</a>
</li>
<li id='pg204649403653981064'><a href='/contact.html'>Contact</a>
</li>
</ul>
</div>
You should use border-top instead of overline, with some padding-top to pad up the spacing between the string and the top overline.
Just note that am using border-top: 4px solid transparent; which is just a transparent border to reserve the space, because if you won't use that, your menu items will shake on :hover as CSS Default Box Model counts the border outside the element instead of inside, which will result in element nudging..
Demo
HTML
<ul>
<li>Hello</li>
<li>World</li>
</ul>
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 5px;
margin-right: 10px;
border-top: 4px solid transparent;
}
ul li:hover {
border-top: 4px solid #f00;
}
Controlling the width using :before or :after pseudo, HTML stays as above..
Demo 2
CSS
ul {
margin: 40px;
}
ul li {
display: inline-block;
padding-top: 8px;
margin-right: 10px;
position: relative;
}
ul li:after {
position: absolute;
width: 90%;
content: "";
top: 0;
left: 50%;
margin-left: -45%;
}
ul li:hover:after {
border-top: 4px solid #f00;
}
they use border-top instead of overline. Please change this
#nav-wrap .container ul li a:hover {
/*background:url(nav-bg-hover-medium.jpg) repeat-x top ;*/
color: #145D85;
text-decoration:overline;
}
into this
#nav-wrap .container ul li a {
border-top:2px solid transparent;
}
#nav-wrap .container ul li a:hover {
color: #145D85;
border-top:2px solid #145D85;
}
<ul>
<li> Item 1 </li>
<li> Item 2 </li>
<li> Item 3
<ul>
<li> Sub Item 1 </li>
<li> sub Item 1 </li>
</ul>
</li>
</ul>
CSS
body
{
background:grey;
}
ul li ul
{
display:none;
}
ul
{
list-style-type:none;
}
ul li
{
float:left;
width:130px;
margin:0px;
padding:10px;
background-color:#003366;
text-align:center;
}
ul li a{
color:white;
text-decoration:none;
}
ul li:hover
{
border-top:4px solid white;
margin-top:-4px;
}
ul li:hover ul
{
display:block;
margin-left:-50px;
margin-top:10px;
}
ul li ul li
{
background-color:#ffffff;
height:100%;
padding:10px;
}
ul li ul li a
{
color:#003366;
}
fiddle
Output:
You could place your menu in a <span></span> and set border-top for that span.

CSS dropdown menu jumping

I'm stuck with a drop down menu. The problem is that the "parent" link is jumping.
HTML:
<ul id="nav">
<li><span>Page 1</span>
<ul>
<li><a>Extralong Page 1.1</a></li>
<li><a>Page 1.2</a></li>
<li><a>Page 1.3</a></li>
</ul>
</li>
<li>Page 2</li>
<li><span>Page 3</span>
<ul>
<li><a>Page 3.1</a></li>
<li><a>Long description for page 3.2</a></li>
<li><a>Page 3.3</a></li>
<li><a>Page 3.4</a></li>
</ul>
</li>
</ul>
CSS:
* {
margin: 0;
padding: 0;
}
#nav {
float: right;
}
#nav ul {
float: left;
}
#nav li {
float: left;
padding-top: 2px;
list-style: none;
background: #3451ff;
}
#nav li a,
#nav li span {
display: block;
text-decoration: none;
font-size: 12pt;
font-weight: bold;
padding: 13px 10px 9px 10px;
}
#nav li a:link, #nav li a:active, #nav li a:visited,
#nav li span {
color: #FFF;
}
#nav li a:hover, #nav li a.active,
#nav li span:hover {
color: #000;
}
#nav li li {
display: none;
}
#nav li:hover li {
display: block;
float: none;
background: #555;
}
#nav li li a {
font-size: 10pt;
margin: 1px;
width: 100%;
background: #3c6f3a;
padding: 5px 0;
}
Demo
How can I make this parent static such that it's width isn't changed on hover? I don't want to use js.
Set a width for the parent:
#nav li {
float: left;
padding-top: 2px;
list-style: none;
width: 100px; /* Add this bad boy */
background: #3451ff;
}
DEMO HERE
You can use position:absolute and make its parent li position:relative Demo
#nav ul {
position:absolute;
right:0;
}
Use position:relative for ul parent and give position:absolute for parent child..it will be working fine.
Here is the updated fiddle :http://jsfiddle.net/nikhilvkd/gmU55/5/
#nav li li {
display: none;
position:relative;
}
#nav li:hover li {
display: block;
float: none;
position:absolute;
background: #555;
}

Trouble with second nested menu

I'm having an issue with adding a child menu to my first drop down menu. Basically this is the structure I am going for:
<ul id="nav" class="sixteen columns">
<li>Home</li>
<li>Portfolio
<ul>
<li>Asia
<ul>
<li>Korea</li>
<li>China</li>
<li>Japan</li>
</ul>
</li>
<li>Europe
<ul>
<li>France</li>
<li>Germany</li>
<li>Italy</li>
</ul>
</li>
</ul>
</li>
</ul>
And here is the CSS I am using:
#nav {
font-family: lanenar;
font-size: 1.2em;
z-index: 999;
position: relative;
}
#nav ul ul {
display: none;
}
#nav ul li:hover > ul {
display: block;
}
#nav ul {
padding: 0;
list-style: none;
position: relative;
display: inline-block;
background: #111;
}
#nav ul li {
float: left;
}
#nav ul li a {
padding: 5px 10px 5px 10px;
display: block;
color: #FFF;
text-decoration: none;
}
#nav ul li:hover {
background: #666;
}
#nav ul li:hover a {
color: #FFF;
}
#nav ul li:hover > ul { margin: 0px; padding: 0px;}
#nav ul li:hover > ul li { float: none; display: block;}
#nav ul li:hover > ul li a { color: #FFF; min-width: 150px;}
#nav ul li:hover > ul li a:hover {color: #FFF;}
#nav ul li {
position: relative;
}
#nav ul li ul {
position: absolute;
top: 28px;
left: 0px;
}
I am having a hard time figuring out what CSS I need to add to have the 2nd nested menu appear to the right when you mouseover Asia or Europe?
Any help would be much appreciated!
HTML
<ul id="nav" class="sixteen columns">
<li>Home
</li>
<li>Portfolio
<ul>
<li>Asia
<ul>
<li>Korea</li>
<li>China</li>
<li>Japan</li>
</ul>
</li>
<li>Europe
<ul>
<li>France</li>
<li>Germany</li>
<li>Italy</li>
</ul>
</li>
</ul>
</li>
</ul>
CSS
#nav {
width:800px;
margin:30px 50px;
padding: 0;
float:left;
}
#nav li {
list-style: none;
float: left;
padding:0 10px;
background-color:#367FB3;
color:white;
}
#nav li a:hover {
background-color:#52baff;
color:#fff;
}
//daf adf
/*--temp--*/
#nav ul ul li {
clear:left;
}
#nav ul ul {
position:absolute;
left:14em;
top:0;
}
#nav ul ul li a {
display:block;
padding: 3px 15px;
color: #242424;
text-decoration: none;
font-size:13px;
font-family:"Lato" !important;
}
/*--end temp--*/
#nav li a {
display: block;
padding: 3px 15px;
color: #242424;
text-decoration: none;
font-size:13px;
font-family:"Lato" !important;
}
#nav a:hover {
color:#367FB3;
}
#nav a:active {
color:#367FB3;
}
#nav li ul {
display: none;
width: 14em;
/* Width to help Opera out */
background-color:transparent;
z-index:666;
}
#nav li:hover ul, #nav li.hover ul {
display: block;
position: absolute;
margin:0px -10px;
padding:0px;
}
#nav li:hover ul ul {
display:none;
}
#nav li ul li:hover ul {
display:block
}
#nav li:hover li, #nav li.hover li {
float: none;
line-height:30px;
}
#nav li:hover li a, #nav li.hover li a {
background-color:#367FB3;
color:#fff;
font-size:13px;
font-family:"Lato" !important;
}
#nav li li a:hover {
background-color:#52baff;
color:#fff;
}
Working Fiddle
Added this to the Updated Fiddle as per SurjithSM suggestion
#nav li {
position: relative;
}
Updated Fiddle

CSS Menu hover effect

I'm trying to create a hover effect in my drop down menu but I can't figure out how to do it.
What I want to do is this:
instead of this:
My Code - You can also see it here, (updated version)
HTML:
<nav>
<ul>
<li>One
<ul>
<li>1.1</li>
<li>1.2
</ul>
</li>
<li>Two
<ul>
<li>2.1</li>
<li>2.2</li>
<li>2.3</li>
</ul>
</li>
<li>Three
<ul>
<li>3.1</li>
<li>3.2</li>
</ul>
</li>
<li>Four</li>
</ul>
</nav>
CSS:
nav {
float: left;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content:"";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
}
nav ul li:hover {
background-color: #000;
}
nav ul li a:hover {
color: #fff;
}
nav ul li a {
display: block;
padding: 25px 15px;
color: #6F0;
text-decoration: none;
}
nav ul ul {
border-radius: 0px;
padding: 0;
position: absolute;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #000;
}
Any help will be appreciated.
Working fiddle:
Change the styles for the below two:
nav ul li:hover {
border-bottom: 1px solid #000;
color: #000;
}
nav ul li a:hover {
color: #000;
}
And add:
nav ul li:hover li:hover{
background: #000;
}
In order to style the sub-menus.
The first (li:hover) you want to set a bottom border - you can change the width of this border from 1px to something more thick, say, 3px