menu expands a little to the right - html

My menu is expanding a little to the right, and i can't find the cause. I am new to coding.
If i put the #nav ul ul position to relative, it expands the menu cell, if i put it to absolute i doesn't do that, but the menu appears under the next menu cell.
this is my .HTML
<div id="navWrap">
<div id="nav">
<ul>
<li>Home </li>
<li>Meniu 1
<ul>
<li>Sm1.1</li>
<li>Sm1.2</li>
<li>Sm1.3</li>
</ul>
</li>
<li>Meniu 2
<ul>
<li>Sm2.1</li>
<li>Sm2.2</li>
<li>Sm2.3</li>
</ul>
</li>
<li>Meniu 3
<ul>
<li>Sub meniu 3.1</li>
<li>Sub meniu 3.2</li>
<li>Sub meniu 3.3</li>
</ul>
</li>
<li>Meniu 4
<ul>
<li>Sub meniu 4.1</li>
<li>Sub meniu 4.2</li>
<li>Sub meniu 4.3</li>
</ul>
</li>
<li>Meniu 5
<ul>
<li>Sub meniu 5.1</li>
<li>Sub meniu 5.2</li>
<li>Sub meniu 5.3</li>
</ul>
</li>
<li>Meniu 6
<ul>
<li>Sub meniu 6.1</li>
<li>Sub meniu 6.2</li>
<li>Sub meniu 6.3</li>
</ul>
</li>
</ul>
<br class="clearleft"/>
</div>
</div>
and this is my .CSS
#navWrap {
height:30px;
background:#0d364c;
margin:0px;
padding:0px;
width:705px;
}
#nav {
padding:5px;
margin:0px;
background:#0d364c;
height:25px;
font-size:15px;
width:700px;
}
#nav ul {
margin: 0px;
padding: 0px ;
list-style: none;
position: relative;
display: block;
}
#nav ul:after {
content: "";
clear: both;
display: block;
}
#nav li {
padding:5px 0px;
background-color: #0d364c;
margin: 0 0 0 0;
color: #FFF;
list-style-type: none;
border-right: 1px solid #fff;
display:inline;
font-family:sans-serif;
height:30px;
width:70px;
}
#nav li:last-child{
border-right:none;
}
#nav li a {
color: #FFF;
text-decoration: none;
}
#nav li a:hover {
text-decoration: underline;
background:#577283;
}
#nav ul ul {
display:none;
border-radius: 0px;
padding: 2px;
position: absolute;
height:30px;
background:black;
top:30px;
}
#nav ul li:hover>ul{
display:inline-table;
float:none;
}
#nav ul li:hover{
background:#577283;
}
#nav ul ul li {
position: relative;
float:none;
border:0px;
padding:0px;
width:70px;
}
#nav ul ul li a {
display: block;
text-decoration: none;
height:40px;
width:70px;
color: white;
background:gray;
text-align:center;
padding: 5px;
margin: 1px;
}
here is my JsFiddle http://jsfiddle.net/tHUWc/
Thank you, Iosif

Set #nav li { position: relative; } and #nav ul ul { left: 0; }
Example:
http://jsfiddle.net/tHUWc/2/

Have you tried using float. I fixed the "expanding to the right" by floating the #nav
See this example http://jsfiddle.net/monnoval/tHUWc/3/

Related

Combining two css pseudo class [duplicate]

I wonder if there is a way to lower opacity (on hover) to all of the 'li's' except the one I'm actually hovering? Something similar to this picture:
.main-navigation {
margin: 0;
padding: 20px 0px 25px;
list-style: none;
background-color: #ffffff;
text-align: center;
display:block;
font-size:1.1em;
}
.main-navigation li.hvr a.lvl1:link,
.main-navigation li.hvr a.lvl1:visited
{
display: block;
padding: 5px 2px 5px 3px;
color: #000;
text-decoration: none;
text-align:center;
}
.main-navigation li.hvr a.lvl1.active {
background: #eeeeee;
color:#000000;
}
.main-navigation li.hvr a.lvl1:hover
{
background-color: #E6E6E6;
color:#666666;
}
.main-navigation li.hvr {
float: left;
position: relative;
width:191px;
margin:0;
font-family: 'Open Sans', sans-serif;
}
.main-navigation li.hvr:hover {
background-color: #E6E6E6;
}
.main-navigation ul {
display: none;
position: absolute;
top:100%;
left: 0;
z-index: 9999;
background-color: #777;
margin: 0;
padding: 0;
min-width:100%;
text-align:left;
}
.main-navigation li.hvr:hover ul { display: block; }
.main-navigation li.hvr ul li {
margin: 0;
padding: 0;
list-style: none;
}
.main-navigation li.hvr ul li a:link,
.main-navigation li.hvr ul li a:visited
{
display: block;
padding: 5px 20px;
color: #fff;
text-align: center;
}
.main-navigation li.hvr ul li a:hover,
.main-navigation li.hvr ul li a:active
{
display: block;
padding: 5px 20px;
color: #fff;
background-color:#cccccc;
}
<ul class="main-navigation clearfix">
<li class="hvr ">
<a class="lvl1 active" href="">Title 1</a>
<ul>
<li>Sub title 1</li>
<li>Sub title 2</li>
<li>Sub title 3</li>
</ul>
</li>
<li class="hvr ">
<a class="lvl1" href="">Title 2</a>
<ul>
<li>Sub title 1</li>
<li>Sub title 2</li>
<li>Sub title 3</li>
</ul>
</li>
<li class="hvr ">
<a class="lvl1" href="">Title 3</a>
<ul>
<li>Sub title 1</li>
<li>Sub title 2</li>
<li>Sub title 3</li>
</ul>
</li>
<li class="hvr ">
<a class="lvl1" href="">Title 4</a>
<ul>
<li>Sub title 1</li>
<li>Sub title 2</li>
<li>Sub title 3</li>
</ul>
</li>
</ul>
You lower the opacity of all alements except the hovered one with CSS.
The point is to lower the opacity of all <li> elements when the parent (ul) is hovered and to reset the opacity to 1 on the hovered li element like this :
ul:hover li { opacity:0.5; }
ul li:hover { opacity:1; }
Here is a simple demo :
li{
float:left;
width:33.33%;
line-height:50px;
background:grey;
list-style-type:none;
}
ul:hover li{
opacity:0.5;
}
ul li:hover{
opacity:1;
}
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>

CSS Navigation menu not dropping the sub menu

Created a navigation menu with one drop menu. For some reason I am unable to get the correct CSS dropping the menu on "Main 3." Would someone mind looking at my CSS to see if there is something I may have missed.
HTML
<ul class="navmenu">
<li>Main 1</li>
<li>Main 2</li>
<li>
Main 3
<ul>
<li>Sub 1</li>
<li>Sub 2 </li>
<li>Sub 3</li>
<li>Sub 4</li>
</ul>
</li>
<li>Main 4</li>
<li>Main 5</li>
<li>Main 6</li>
<li>Main 7</li>
</ul>
CSS
.navmenu{
background: #510E2A;
height: 35px;
margin: 0;
padding: 0;
list-style-type: none;
overflow: hidden;
text-align: justify;
}
.navmenu li{
float: left;
}
.navmenu li a{
display: block;
padding:9px 20px;
text-decoration: none;
font-family: THCFontSemiBold;
color: #f3ac3f;
font-weight: bold;
}
.navmenu ul{
list-style-type: none;
position: absolute;
z-index: 1000;
left: -9999em;
}
.navmenu li:hover{
position: relative;
}
.navmenu li:hover ul {
left:0px;
top:30px;
background:#5FD367;
padding:0px;
}
.navmenu li:hover ul li a {
padding:5px;
display:block;
width:168px;
text-indent:15px;
background-color:red;
}
.navmenu li:hover ul li a:hover { background:#005555; }
Fiddle is here
Just remove overflow from navmenu
.navmenu{
background: #510E2A;
height: 35px;
margin: 0;
padding: 0;
list-style-type: none;
text-align: justify;
}
Updated Fiddle

Navbar Horizontal Menu positioning help. Very basic

apologies for basic-ness of question, just creating a dropdown menu and having some problems with the margins and positioning.
Ive set the div of it as 85% but i want that centered in the page,
And then the list items centered in the middle of that so it's all neat but can't get it too.
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Home</li>
<li>Second Page</li>
<li>Third Page<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Dropdown One</li>
<li>Dropdown Two</li>
</ul>
</li>
<li>Fourth Page</li>
<li>Fifth Page<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Dropdown 1</li>
<li>Dropdown Item 2</li>
<li>Dropdown 3</li>
<li>Dropdown 4</li>
</ul>
</li>
</ul>
</nav>
CSS:
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap ul {
margin:0px;
padding:0px;
}
.menu-wrap {
width:80%;
background: #85D2CD;
display: inline-block;
margin: auto;
}
.menu {
width:100%;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#FFF;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 30px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
text-decoration:none;
}
.menu > ul > li:hover > a { /* Hover background color */
background:#5D9390;
}
.menu li:hover .sub-menu {
opacity:1;
}
.sub-menu {
width: 100%;
padding:5px 0px;
position:absolute; /* Need this so menu height doesnt extend to dropdown size*/
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#6D9E9B;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
text-decoration:none;
}
.sub-menu li a:hover {
background:#5D9390;
}
I think that is the only relevant code needed, I've kinda lost my mind a bit and put margin auto in too many spots to try fix this but none of it is working
First of all change the
.menu-wrap {
width: 80%;
background: #85D2CD;
display: block;
margin: 0 auto;
overflow: hidden;
}
And to center your menu items, change the ul style to
ul.sub-menu {
text-align: center;
}
That should get the things sorted out and be aligned in middle.
If you know the width of the wrapping div, you can do this:
.menu-wrap{
left: 10%;
position: relative;
}
If you get rid of the float:left, you can add this to the menu, to center the menu:
.menu {
text-align: center;
}
JsFiddle: http://jsfiddle.net/d8sstx6t/2/
If you don't know the width and the height of the content you can use display: table;
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap ul {
margin:0px;
padding:0px;
}
.menu-wrap {
width:80%;
background: #85D2CD;
display: table;
margin: 0 auto;
}
.menu {
display: table;
margin:0 auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#FFF;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:19px;
}
.menu > ul > li > a {
padding:10px 30px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
text-decoration:none;
}
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>Home</li>
<li>Second Page</li>
<li>Third Page<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Dropdown One</li>
<li>Dropdown Two</li>
</ul>
</li>
<li>Fourth Page</li>
<li>Fifth Page<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Dropdown 1</li>
<li>Dropdown Item 2</li>
<li>Dropdown 3</li>
<li>Dropdown 4</li>
</ul>
</li>
</ul>
</nav>

dropdown on menu hover

i have a menu that when i hover has a drop down i follow this
and this but unfortunately im getting different result than expected..im getting list but it is displayed as line horizontally and not vertically like the example here is the code i added to make the drop down
css
ul # menu li ul .submenu{
display:none;
}
ul # menu li : hover ul .submenu{
display:block;
}
here is the html
<div id="menu">
<ul id="menu-list">
<li id="">Home</li>
<li id="">
Menu
<ul class="sub-menu">
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4</li>
</ul>
</li>
<li id="">Menu</li>
<li id="">Menu</li>
<li id="">Menu</li>
</ul>
</div>
Here you go:
Updated Fiddle
Just the small change. Made UL id = "menu"
<ul id="menu">
<li id="home">Home</li>
<li id="townoffice">
Menu
<ul class="sub-menu">
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4</li>
</ul>
</li>
<li id="busines">Menu</li>
<li id="residents">Menu</li>
<li id="tourists">Menu</li>
</ul>
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;
}
FIDDLE

How to create a drop down menu like the one in this picture

How can I create a drop down menu like the one in this picture:
What I already tried:
Check out this jsfiddle
I really can't get it to work, sorry for this noobish question and the code in the JSFiddle is all I have.
CSS:
#import url(http://fonts.googleapis.com/css?family=Homenaje);
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', sans-serif;;
color: #666666;
font-size: 14px;
background: url(../img/header.jpg) repeat-x;
margin: 0;
}
/*=============================*/
/*===== Functionality =====*/
/*=============================*/
/*===== Parents =====*/
#navMenu,
#navMenu ul,
#navMenu li {
display: block;
color: black;
font-size: 12px;
}
#navMenu ul {
line-height:30px;
}
#navMenu li {
list-style:none;
float:left;
position:relative;
width: 120px;
height:45px;
}
#navMenu ul li a {
line-height:45px;
display:block;
background-color: #333333;
margin-left: auto;
text-align: left;
color: white;
padding-left: 10px;
}
#navMenu ul li a:hover {
background-color: #03A6CF;
}
/*end Parents*/
/*===== Children =====*/
#navMenu ul ul {
position:absolute;
visibility:hidden;
margin-left: -13px;
}
#navMenu ul li:hover > ul {
visibility:visible;
}
/*end children*/
/*==========================*/
/*===== Prettyness =====*/
/*==========================*/
#navMenu ul li a {
text-decoration:none;
}
What about something like this? http://fiddle.jshell.net/Egg4t/
#navMenu ul,
#navMenu li {
display: block;
font-size: 12px;
margin: 0;
}
#navMenu {
position: relative;
}
#navMenu ul {
line-height:30px;
}
#navMenu li {
list-style:none;
float: left;
padding-right: 20px;
padding-left: 10px;
font-size: 14px;
}
#navMenu li li {
line-height: 25px;
color: #03A6CF;
float: left;
}
#navMenu li li li {
float: none;
display: block;
}
#navMenu ul li a {
display: block;
font-size: 12px;
line-height: 25px;
margin-left: auto;
text-align: left;
}
#navMenu ul ul {
position:absolute;
left: 0;
padding: 0;
width: 500px;
background-color: #333333;
visibility:hidden;
}
#navMenu ul ul ul {
position: static;
display: inline;
}
#navMenu ul li:hover ul {
visibility:visible;
}
<div id="navMenu" class="last-topnav">
<ul>
<li> Menu 1
<ul>
<li> Menu 1 Column 1
<ul>
<li>item 1</li>
<li>item 2</li>
<li> Level 2
<ul>
<li>item 2</li>
<li>item 2</li>
</ul>
</li>
</ul>
</li>
<li> Menu 1 Column 2
<ul>
<li>
item 1
</li>
<li>item 2</li>
<li>item 3<li>
<li>item 4<li>
</ul>
</li>
</ul>
</li>
<li> Menu 2
<ul>
<li> Menu 2 Column 1
<ul>
<li>item 1</li>
<li>item 2</li>
<li> Level 2
<ul>
<li>item 2</li>
<li>item 2</li>
</ul>
</li>
</ul>
</li>
<li> Menu 2 Column 2
<ul>
<li>
item 1
</li>
<li>item 2</li>
<li>item 3<li>
<li>item 4<li>
</ul>
</li>
<li> Column 3
<ul>
<li>
item 1
</li>
<li>item 2</li>
<li>item 3<li>
<li>item 4<li>
</ul>
</li>
</ul>
</li>
</ul>
</div>