issue with centering nav horizontally in UL - html

It seems the list items are stuck on the left side of the UL no matter what size I make it. It looks centered on some screens but not on larger ones. Float:right has been the only thing that works for my screen size, but it doesn't stay centered if you resize the window.
Site: http://www.lotusroomofboca.com/
HTML:
<div id="header">
<img id="logo" src="images/logo.png" alt="Lotus Room logo">
<ul id="nav">
<li>Home</li>
<li>Our Tea</li>
<li>Menu</li>
<li>Learn More</li>
<li>Contact</li>
</ul>
</div>
CSS:
#header {position:fixed;
width:100%;
background-color:rgba(244,243,243,1);
z-index:100;
-webkit-box-shadow: 0px 10px 60px 0px rgba(219,219,216,0.94);
-moz-box-shadow: 0px 10px 60px 0px rgba(219,219,216,0.94);
box-shadow: 0px 10px 60px 0px rgba(219,219,216,0.94);
}
#nav {list-style:none;
margin:auto;
text-align:center;
width:960px;
padding-top:30px;
padding-bottom:20px;
float:right;}
#nav a {text-decoration:none;
text-align:center;
display:block;
color:#5c5c5c;
font-family:'Avenir';
font-size:12px;
border-right:thin grey solid;
float:left;
width:10%;
}
#nav li:last-child a {border-right:none;}
#nav a:hover {color:#7b8c6f;
transition:ease 0.5s;}

Here's a FIDDLE
Use this config for <ul>
<ul id="nav">
<li>Home
</li><li>Our Tea
</li><li>Menu
</li><li>Learn More
</li><li>Contact
</li>
</ul>
and this css
#nav li {
text-align:center;
display:inline-block;
color:#5c5c5c;
font-family:'Avenir';
font-size:12px;
border-right:thin grey solid;
width:10%;
}
#nav li:last-child {
border-right: none;
}
#nav li a {
text-decoration: none;
color: #000;
transition: color 0.5s ease;
-moz-transition: color 0.5s ease;
-webkit-transition: color 0.5s ease;
}
#nav li a:hover {
color:#7b8c6f;
}

first try adding
#nav a {
margin: 0 auto;
}
#nav a {
display: inline-block; //instead of block
float: left; //remove this too
}

Related

How to center align CSS navigation menu?

Can someone please help me? I'm trying to center my navigation menu. I have tried different things, but nothing works, and i really don't know what to do. I would really appreciate help. thanks in advance!
nav {
display: inline-block;
list-style-type: none;
float: left;
width: 100%;
height: 102px;
text-align: center;
}
nav > ul {
float:right;
width:100%;
height:102px;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
HTML
<div>
<nav>
<ul>
<li> Hjem
<ul>
<li>Sub1</li>
<li>Sub2</li>
<li>Sub3</li>
</ul>
</li>
<li>Bilder</li>
<li>Video</li>
<li>Design</li>
</ul>
</nav>
</div>
Here is what I did.
#outer{
width:100%;
height: 102px;
text-align: center;
background:#222;
border-radius: 10px 10px 0px 0px;
}
nav {
display: inline-block;
list-style-type: none;
margin: 0 auto;
}
nav > ul > li {
float:left;
width:auto;
margin-right:10px;
line-height:102px;
}
nav > ul li a {
padding:50px;
color:white;
font-family:helvetica, sans-serif;
}
nav > ul > li > ul {
background:#222;
opacity:0;
transition:opacity 1s;
-webkit-transition:opacity 1s;
-moz-transition:opacity 1s;
-o-transition:opacity 1s;
-ms-transition:opacity 1s;
border-radius: 0px 0px 10px 10px;
}
nav > ul > li:hover > ul {
opacity:1;
}
And you just need to give an ID to the div.
<div id="outer">

CSS3 Navigation submenu is not inheriting its class

I have been playing with CSS3 trying to really understand it and I have not been able to get the behavior of the sub-menu navigation to be correct. Please see http://jsfiddle.net/jllcpp04/9Jpd6/7/ for a working example. The sub-menu still has the bullet points on it and it is not popping up to the right. This is part of a dynamic menu whose width will change depending upon what offices will appear (based on user profile). I would prefer not to set top/right/left/bottom for div location. I also cannot figure out why derivnav is not overriding the nested submenu.
My HTML Code:
<div class="main_nav">
<ul class="nav">
<li>Home
</li>
<li>
<div class="submenu">Office
<div class="subnav">
<h3>Near You</h3>
<ul>
<li>
<div class="deriv">New York
<div class="derivnav">
<ul>
<li>Upper West Side
</li>
<li>Upper East Side
</li>
<li>Lower West Side
</li>
<li>Wallstreet
</li>
</ul>
</div>
</div>
</li>
</ul>
<h3>Not Near You</h3>
<ul>
<li>chicago
</li>
<li>philadelphia
</li>
<li>san francisco
</li>
</ul>
</div>
</div>
</li>
</ul>
Component CSS:
#charset"utf-8";
/* CSS Document */
.main_nav {
width:56%;
text-align:center;
float:left;
display:inline-block;
}
.nav {
list-style:none;
height:43px;
white-space:nowrap;
margin: 0px auto 10px auto;
min-width:775px;
text-align:left;
}
.nav h3 {
font-size:14px;
margin:7px 0 14px 4px;
padding-bottom:7px;
border-bottom:1px solid #888888;
}
.nav h4 {
font-size:12px;
margin:7px 0 14px 4px;
padding-bottom:7px;
border-bottom:1px solid #888888;
}
.nav > li {
border:none;
text-transform:uppercase;
float:left;
position:relative;
margin:5px 3px 5px 2px;
padding:auto;
}
.nav li {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color: #333333;
outline:0;
text-decoration:none;
padding-left:10px;
}
.nav li:hover > a, .nav li:hover > p {
color:#cccc66;
}
.nav li .drop {
padding-right:15px;
background:url("drop-nonsel.png") no-repeat right 4px;
}
.nav li:hover .drop, .nav li .drop:hover {
background:url("drop-sel.png") no-repeat right 4px;
}
.nav .subnav {
float:left;
position:absolute;
text-align:left;
padding:5px;
margin: 5px 5px 5px 0;
border:1px solid #CCC;
border-top:none;
white-space:nowrap;
/* Gradient background */
background:#FFFFFF;
/* Rounded Corners */
-moz-border-radius: 0px 5px 5px 5px;
-webkit-border-radius: 0px 5px 5px 5px;
border-radius: 0px 5px 5px 5px;
opacity:0;
transition:visibility 0s linear 0.2s, opacity 0.2s linear;
visibility:hidden;
}
.nav .submenu:hover .subnav, .nav li .subnav:hover {
top:auto;
opacity:1;
visibility:visible;
}
.nav .subnav > ul {
padding:2px;
margin:0 0 12px 0;
}
.nav .subnav > li {
list-style:none;
border-bottom:thin;
font-size:12px;
line-height:24px;
position:relative;
text-shadow: 1px 1px 1px #ffffff;
padding:0;
margin:0;
float:none;
text-align:left;
}
.nav .subnav > li:last-chid {
border-bottom:none;
}
.deriv li .dropr {
padding-right:10px;
background:url("drop-right-nonsel.png") no-repeat right 6px;
}
.deriv li:hover .dropr, .deriv li .dropr:hover {
background:url("drop-right-sel.png") no-repeat right 6px;
}
.subnav .derivnav {
float:right;
position:absolute;
text-align:left;
right:-150px;
padding:5px;
margin: 5px 5px 5px 0;
border:1px solid #CCC;
border-left:none;
white-space:nowrap;
/* Gradient background */
background:#FFFFFF;
/* Rounded Corners */
-moz-border-radius: 0px 5px 5px 5px;
-webkit-border-radius: 0px 5px 5px 5px;
border-radius: 0px 5px 5px 5px;
opacity:0;
transition:visibility 0s linear 0.3s, opacity 0.3s linear;
visibility:hidden;
}
.subnav .derivnav > li {
list-style:none;
border-bottom:thin;
font-size:12px;
line-height:24px;
position:relative;
text-shadow: 1px 1px 1px #ffffff;
padding:0;
margin:0;
float:none;
text-align:left;
}
.subnav li .deriv:hover .derivnav, .subnav li .derivnav:hover {
top:auto;
opacity:1;
visibility:visible;
}
.derivnav ul {
padding:2px;
margin:0 0 12px 0;
}
.derivnav li {
list-style:none;
border-bottom:thin;
font-size:12px;
line-height:24px;
position:relative;
text-shadow: 1px 1px 1px #ffffff;
padding:0;
margin:0;
float:none;
text-align:left;
}
I have been playing with it for a few days and can't seem to figure it out. my CSS3 validates and my html code does as well. Any ideas?
Thanks!
Jon
It worked for me when I removed the > marks from these two lines:
Old version
.nav .subnav > li {
.nav .subnav > li:last-chid {
New version
.nav .subnav li {
.nav .subnav li:last-child {
The > in a CSS selector means that the selected element must be a direct child of the previous element, not just the nearest descendant. In your markup, .subnav is a div, not a ul. The li element simply wasn't selected before, so you're styles were never applied.
If you need the .subnav list styles to be completely separate from the .deriv styles, you could use the > operator like this:
Alternate
.nav .subnav > ul > li {
My fork of the DEMO
i add DEMO
.nav li a {
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color: #333333;
outline:0;
text-decoration:none;
padding-left:10px;
}

When I hover over my nav menu it pushes content down, why? How do i change color of li when hover over?

When i hover over the navmenu it pushes other content down on the webpage. In addition, when you hover over the nav the font is no longer in white. I'm sorry I am new at programming and borrowed some of this code so it may be sloppy. Thanks
Here is my html:
<div class="nav">
<ul id="nav">
<li>Home</li>
<li>Shop Online</li>
<li>Online Rentals
<div>
<ul>
<li>Rent Now</li>
<b>Current Rental Customers</b>
<li>Rental Returns</li>
<li>Rental Repairs</li>
<li>Rental Exchanges</li>
</ul>
</div>
</li>
<li>Lessons
<div>
<ul>
<li>Private Lessons</li>
<li>Meet the Teachers</li>
<li>Request a Lesson</li>
</ul>
</div>
</li>
<li>Performing Arts Center
<div>
<ul>
<li>Musical Theater</li>
<li>Kindermusik</li>
<li>Recording Studio</li>
<li>Group Ensembles</li>
</ul>
</div>
</li>
<li>Repairs</li>
<li>My Account</li>
</ul>
</div>
Here is my css:
/* main menu styles */
#nav,#nav ul {
font-family: verdana;
list-style: none;
margin: 0;
padding: 0;
position: fixed;
}
#nav {
height: 50px;
left: 0;
overflow: hidden;
top: 0;
position: relative;
}
#nav li {
float:left;
position:relative;
z-index:10;
}
#nav li a {
background-repeat: no-repeat;
background-position: center top;
color: #fff;
display: inline;
float: left;
font-size: 14px;
height: 51px;
line-height: 40px;
padding: 0 10px;
position: relative;
text-decoration: none;
z-index: 20;
background-color: #005E20;
}
#nav li:first-child a {
background:url(file:///Macintosh%20HD/Users/davidscott/Downloads/example91/images/bg-menu.png) no-repeat left top;
padding-left:35px;
}
#nav li ul li:first-child a {
background-image:none;
padding-left:10px;
}
#nav li.pad {
background: url(file:///Macintosh%20HD/Users/davidscott/Downloads/example91/images/bg- menu.png) no-repeat right top;
display: inline;
height: 51px;
width: 35px;
}
#nav ul {
background-color: #FFFFFF;
height: auto;
padding: 10px 0;
position: absolute;
top: -115px;
width: 180px;
z-index: 1;
border-radius: 8px; /*some css3*/
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
transition: 0.8s ease-in-out;
box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.5);
-moz-transition: 0.8s ease-in-out;
-o-transition: 0.8s ease-in-out;
-webkit-transition: all 0.8s ease-in-out;
color: #005E20;
}
#nav ul li {
width:180px;
}
#nav ul li a {
background:transparent;
height:20px;
line-height:20px;
width:160px;
}
#nav:hover {
height:200px;
}
#nav li:hover ul {
-moz-transform:translate(0,161px); /*some css3*/
-o-transform:translate(0,161px);
-webkit-transform:translate(0,161px);
}
#nav a:hover,#nav li:hover > a {
color:#99ff33;
}
This changes the height of the nav on hover (pushing the rest of the page down):
#nav:hover {
height:200px;
}
This changes the color to green on hover:
#nav a:hover, #nav li:hover > a {
color:#99ff33;
}
Here's a rudimentary example without those hover definitions:
http://jsfiddle.net/w4uyX/
It's all in your CSS code (which seems a bit unorganized to me).
To deal with the menu pushing other content down, please find the selector #nav:hover where a larger height is set.
Then find the selector #nav a:hover,#nav li:hover > a. There is the setting for the different color, when you hover over the menu.
see my navbar and see the difference
http://codepen.io/leandroruel/pen/yrwKI

Centering the horizontal menu in the center of the page

I can't seem to be able to center the horizontal #menu in the center of the page.
I have tried adding a container DIV, but I can't seem to be able to get it to work at all.
Here is my HTML markup:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#container {
margin:0 auto;
width: 100%;
}
#menu {
list-style:none;
width:940px;
height:43px;
background: #014464;
border: 1px solid #002232;
}
#menu ul, li {
font-size:14px;
font-family: Segoe UI;
line-height:21px;
text-align:left;
}
#menu li {
float:left;
display:block;
text-align:center;
position:relative;
padding: 4px 10px 4px 10px;
margin-right:30px;
margin-top:7px;
border:none;
}
#menu li:hover {
border: 1px solid #777777;
padding: 4px 9px 4px 9px;
background: #F4F4F4;
}
#menu li a {
color: #EEEEEE;
display:block;
outline:0;
text-decoration:none;
}
#menu li:hover a {
color:#161616;
}
.dropdown_column {
margin:4px auto;
float:left;
position:absolute;
left:-999em; /* Hides the drop down */
text-align:left;
padding:10px 5px 10px 5px;
border:1px solid #777777;
border-top:none;
background:#F4F4F4;
width: 560px;
}
#menu li:hover .dropdown_column {
left:-1px;
top:auto;
}
.sub_col { width:130px; }
.col { width:550px; }
.sub_col, .col {
display:inline;
float: left;
position: relative;
margin-left: 5px;
margin-right: 5px;
}
#menu .menu_right {
float:right;
margin-right:0px;
}
#menu li:hover .align_right {
left:auto;
right:-1px;
top:auto;
}
#menu ul li {
line-height:21px;
text-align:left;
}
#menu h2 {
font-size:21px;
font-weight:400;
letter-spacing:-1px;
margin:7px 0 14px 0;
padding-bottom:14px;
border-bottom:1px solid #666666;
}
#menu h3 {
font-size:14px;
margin:7px 0 14px 0;
padding-bottom:7px;
border-bottom:1px solid #888888;
}
#menu li:hover div a {
font-size:12px;
color:#015b86;
}
#menu li:hover div a:hover {
color:#FFF;
background: #014464;
}
#menu li ul {
list-style:none;
padding:0;
margin:0 0 12px 0;
}
#menu li ul li {
font-size:12px;
line-height:24px;
position:relative;
text-shadow: 1px 1px 1px #ffffff;
padding:0;
margin:0;
float:none;
text-align: left;
width:130px;
}
#menu li ul li:hover {
background:none;
border:none;
padding:0;
margin:0;
}
</style>
</head>
<body>
<div id="container">
<ul id="menu">
<li>4 Columns<!-- Begin 4 columns Item -->
<div class="dropdown_column"><!-- Begin 4 columns container -->
<div class="col">
<h2>This is a heading title</h2>
</div>
<div class="sub_col">
<h3>Some Links</h3>
<ul>
<li>ThemeForest</li>
<li>GraphicRiver</li>
<li>ActiveDen</li>
<li>VideoHive</li>
<li>3DOcean</li>
</ul>
</div>
<div class="sub_col">
<h3>Useful Links</h3>
<ul>
<li>NetTuts</li>
<li>VectorTuts</li>
<li>PsdTuts</li>
<li>PhotoTuts</li>
<li>ActiveTuts</li>
</ul>
</div>
<div class="sub_col">
<h3>Other Stuff</h3>
<ul>
<li>FreelanceSwitch</li>
<li>Creattica</li>
<li>WorkAwesome</li>
<li>Mac Apps</li>
<li>Web Apps</li>
</ul>
</div>
<div class="sub_col">
<h3>Misc</h3>
<ul>
<li>Design</li>
<li>Logo</li>
<li>Flash</li>
<li>Illustration</li>
<li>More...</li>
</ul>
</div>
</div><!-- End 4 columns container -->
</li><!-- End 4 columns Item -->
</ul>
</div>
</body>
</html>
Add margin: 0 auto; to your #menu ul.
DEMO
Wrap the menu in div with style text-align: center

Using Multiple Unordered(UL) Lists and List ItemsCSS/HTML

I have two separate working 'objects'
A menu bar, working entirely in CSS.
See it working here: http://jsbin.com/EMEraZu/1/edit?html,css,js,output
And I have a fancy CSS/Java slideshow here: http://jsbin.com/ijUW/1/edit?html,css,js,output
These work perfectly until I try to combine them together on one page, where upon the CSS mucks up.Now, every thumbnail on the slideshow is a list item (li) element, in my novice opinion, this is conflicting with the UL and LI elements in the menu bar. Is this the problem? I tried fixing it by creating a div tag for the menubar. But I've had no luck. Any suggestions?
I've copied the CSS and HTML below
#menubar ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
#menubar ul li {
font: 18px;
font-family: latolight;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
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;
}
#menubar ul li:hover {
background: #555;
color: #fff;
font-family: latolight;
}
#menubar ul li ul {
padding: 0;
position: absolute;
top: 43px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
#menubar ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
#menubar ul li ul li:hover { background: #666; }
#menubar ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
<div id="menubar">
<ul>
<li>Home</li>
<li>Title
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul></li>
<li>
Title2
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</li>
</ul>
</div>
//* Above was Menubar code, it somehow conflicts with the gallery code, below,
#gallery{
/* CSS3 Box Shadow */
-moz-box-shadow:0 0 3px #AAAAAA;
-webkit-box-shadow:0 0 3px #AAAAAA;
box-shadow:0 0 3px #AAAAAA;
/* CSS3 Rounded Corners */
-moz-border-radius-bottomleft:4px;
-webkit-border-bottom-left-radius:4px;
border-bottom-left-radius:4px;
-moz-border-radius-bottomright:4px;
-webkit-border-bottom-right-radius:4px;
border-bottom-right-radius:4px;
border:1px solid white;
background:url(img/panel.jpg) repeat-x bottom center #ffffff;
/* The width */
width:920px;
overflow:hidden;
}
#slides{
height:400px;
/* jQuery willchange the width later on to the sum of the widths of all the slides. */
width:920px;
overflow:hidden;
}
.slide{
float:left;
}
#menu{
/* container for the thumbnails */
height:90px;
}
li{
/* Every thumbnail is a li element */
width:120px;
display:inline-block;
list-style:none;
height:90px;
overflow:hidden;
}
li.inact:hover{
/* The inactive state, highlighted on mouse over */
background:url(img/pic_bg.png) repeat;
}
li.act,li.act:hover{
/* The active state of the thumb */
background:url(img/active_bg.png) no-repeat;
}
.fbar{
/* The left-most vertical bar */
width:2px;
background:url(img/divider.png) no-repeat right;
}
li a{
display:block;
background:url(img/divider.png) no-repeat right;
height:70px;
padding-top:10px;
}
a img{
border:none;
}
<div id="main">
<div id="gallery">
<div id="slides">
<div class="slide"><img src="img/sample_slides/1.jpg" width="920" height="400" alt="side" /></div>
<div class="slide"><img src="img/sample_slides/2.jpg" width="920" height="400" alt="side" /></div>
<div class="slide"><img src="img/sample_slides/3.jpg" width="920" height="400" alt="side" /></div>
<div class="slide"><img src="img/sample_slides/4.jpg" width="920" height="400" alt="side" /></div>
</div>
<div id="menu">
<ul>
<li class="fbar"> </li><li class="menuItem"><img src="img/thumb_1.png" alt="thumbnail" width="85" /></li><li class="menuItem"><img src="img/thumb_2.png" alt="thumbnail" width="85" /></li><li class="menuItem"><img src="img/thumb_3.png" alt="thumbnail" width="85" /></li><li class="menuItem"><img src="img/thumb_4.png" alt="thumbnail" width="85" /></li>
</ul>
</div>
</div>
</div>
</body>
</html>
Any ideas at all would be appreciated on why they are clashing.
i think your gallery css needs to be more specific to which elements to style, like you have done with the menu css by adding parents id. as there is no id with gallery css, its going to effect all li elements