How do I get my menu to centre on all displays - html

http://jsfiddle.net/aw4zgwso/
Here's what's happening at the moment and I can't seem to center the nav menu unless I add something like width:40% to .menu But that doesn't work well and will knock the text down on smaller resolution displays
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>

You can simply use text-align:center and make li inline-block like this :
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
here is the full code
.nav {
width: 100%;
height: 40px;
display: block;
background-color: #313131;
}
.nav_inner {
height: 100%;
margin: 0 auto;
position: relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color: #ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color: white;
}
.clearfix:after {
display: block;
clear: both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width: 100%;
background: #3e3436;
}
.menu {
margin: 0px auto;
}
.menu li {
margin: 0px;
list-style: none;
}
.menu a {
color: #ffffff;
text-decoration: none;
}
.menu li:hover>a,
.menu .current-item>a {
text-decoration: none;
color: #ffffff;
}
.menu .arrow {
font-size: 12px;
line-height: 0%;
color: #00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
.menu>ul>li>a {
padding: 9px 40px;
display: inline-block;
}
.menu>ul>li:hover>a,
.menu>ul>.current-item>a {
background: #191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 160%;
padding: 5px 0px;
position: absolute;
top: 95%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
background: #313131;
}
.sub-menu li {
display: block;
font-size: 16px;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>

try this :
ul {
text-align: center;
}
.menu > ul > li {
float: none;
}

Set text-align: center; for parent(.menu) and display: inline-block; for children(.clearfix).
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
//more code...
}
.nav { width:100%; height:40px; display:block; background-color:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>

To center the menu you just need to add this CSS to your menu. I'm diffinatly sure it's helpful for you.
.menu ul {
margin: 0 auto;
display: table;
}
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>

/HTML/
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="navs">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
.nav { width:100%;display:block; text-align:center;background-color:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;text-align:center}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
line-height: 15px;
}
.nav_menu li {
display:inline-block;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
.navs {
float: left;
width: 100%;
}
/*----- Top Level -----*/
.menu > ul > li {
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}

Using text-align: center to horizontally center nested elements
If you declare text-align: center on the containing parent element (.menu > ul), remove any arbitrary margin or padding that may offset horizontal alignment, and remove the float rule declared on the list items (li) - you should achieve the intended result.
Note: for horizontal alignment, using text-align: center to work as expected, a few requirements should be met:
The containing parent element must be a block element (e.g:
display: block)
The nested elements you need centered should be inline-block
elements (e.g: display: inline-block)
No float rules should be declared on the nested elements you are
intending to horizontally align, float rules will negate any effort
to align elements in this way
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
margin: auto;
padding: 0px; /* remove arbitrary padding */
text-align: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:none; /* remove float */
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
Or... you could Just use Flex...
Using flex-box to horizontally center nested elements
By declaring display: flex on a parent element and justify-content: center you will be able to horizontally center elements. flex-box is actually great for list items specifically since it usually required specific nested children, e.g: ordered (ol) or unordered (ul) lists only accept li elements as directly nested children for valid markup, and flex-box typically has a parent-to-direct-child "dependency" (so in other words, flex-box rules work great for directly nested children, but may adversely affect other elements nested deeper in/down the DOM tree in ways you are either not anticipating or do not desire).
/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
See collapsed Code Snippet below demonstrating flex-box solution
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li>Home</li>
<li>About us<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Our Values</li>
<li>Technology Partners</li>
</ul>
</li>
<li>IT Solutions<span class="arrow">▼</span>
<ul class="sub-menu">
<li>Audio Visual</li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li>Visitor & Entry Management</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
Heads up! flex-box has poor or limited support for legacy browsers, so if this is going to be a concern for you, it's probably better not to use it in production.
IE <= 9 - Not Supported
IE 10,11 - Partial Support
See more: https://caniuse.com/#feat=flexbox

Related

DropDown Aligned

I have a menu with dropdown option, I'm trying to align the dropdown menu under the respective item selected from list. So far is aligned to the left, the dropdown ul list is inside the element that should display the dropdown list.
I'm not sure about what I'm doing wrong here, some suggestion?
DEMO
HTML
<div id="menu">
<div id="menu-wrapper">
<img id="home-icon" src="images/home.svg" />
<nav id="menu">
<ul>
<li>SUBSCRIBE</li>
<li>NEWS</li>
<li>MARINA GUIDE</li>
<li class="submenu">PRACTICAL
<ul>
<li>Glossary</li>
<li>Tips</li>
</ul>
</li>
<li>OUT AT SEA</li>
<li>GEAR</li>
<li>FORUM</li>
</ul>
</nav>
<div id="menu-icon-container">
<img id="menu-icon" src="images/menu.svg" />
</div>
<div id="menu-icon-container">
<img id="menu-icon" src="images/search.svg" />
</div>
</div>
CSS
#menu-icon-container {
position: relative;
float: right;
height: 100%;
width: 60px;
background-color: ;
}
#menu-icon-container:hover {
background-color: #bf1b33;
cursor: pointer;
}
#menu-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
cursor: pointer;
}
#menu ul {
list-style:none;
position:relative;
float:left;
margin:0;
padding:0;
margin-left:20px;
}
#menu ul li {
display: inline;
}
#menu ul li a {
color: #00599b;
padding: 0px 15px;
text-decoration: none;
border-radius: 4px 4px 0 0;
font-family: 'Open Sans', sans-serif;
}
#menu ul li a:hover {
border-bottom: 2px solid #bf1b33;
}
#menu ul ul
{
display:none;
position:absolute;
top:100%;
background: fuchsia;
padding:0
}
#menu ul ul li
{
float:none;
width:200px
}
#menu ul ul a
{
line-height:120%;
padding:10px 15px
}
#menu ul li:hover > ul
{
display:block
}
Add position: relative; to #menu ul li { and left:0; to #menu ul ul will make it proper below the selected.
#menu ul li {
display: inline;
position: relative;
}
#menu ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background: fuchsia;
padding:0
}
Fiddle

My navbar collapse is collapsing but when im not hovering on it

Im making a landing page for a job and doing the navbar then i figured it out that i have to set the navbar fixed to top, after i fixed it the collapse of the second bar is just showing up when im not even hover on it. Had to add more margin to the next item to work "propertly" but is kinda ugly
.fixed-top {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
top: 0;
border-width: 0 0 1px;
}
#nav ul li a {
display: block;
padding: 7px 15px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
}
#nav li a:hover {
color: #000000;
background-color: #fff;
}
#nav .navbar-izquierda ul {
width: 100%;
float: left;
margin: auto;
padding: 0;
list-style: none;
background-color: #434343;
box-shadow: 10px 0 10px #000000;
border-bottom: 1px solid #000000;
}
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width: auto;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:14px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- DropDown Navbar Inferior -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:100%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition: opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:inline-block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
}
<div class="navbar-izquierda menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li class="active">Portatil</li>
<li>Desk</li>
<li>Workstation</li>
<li>Promotions</li>
<li>Services and Guarantees <span class="arrow">▼</span>
<ul class="sub-menu">
<li>Error 1</li>
<li>Error 2</li>
<li>Horror 3</li>
</ul>
</li>
</ul>
</nav><!-- Navegador inferior -->
</div><!-- Navegador Inferior -->
The key is to set the dropdown to visility:hidden; in the start and visility:visible; in :hover state.
.fixed-top {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
top: 0;
border-width: 0 0 1px;
}
#nav ul li a {
display: block;
padding: 7px 15px;
text-decoration: none;
font-weight: bold;
color: #FFFFFF;
}
#nav li a:hover {
color: #000000;
background-color: #fff;
}
#nav .navbar-izquierda ul {
width: 100%;
float: left;
margin: auto;
padding: 0;
list-style: none;
background-color: #434343;
box-shadow: 10px 0 10px #000000;
border-bottom: 1px solid #000000;
}
.clearfix:after {
display:block;
clear:both;
}
.menu-wrap {
width:100%;
box-shadow:0px 1px 3px rgba(0,0,0,0.2);
background:#3e3436;
}
.menu {
width: auto;
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
transition:all linear 0.15s;
color:#919191;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#be5b70;
}
.menu .arrow {
font-size:11px;
line-height:0%;
}
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:14px;
}
.menu > ul > li > a {
padding:10px 40px;
display:inline-block;
text-shadow:0px 1px 0px rgba(0,0,0,0.4);
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#2e2728;
}
/*----- DropDown Navbar Inferior -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
visibility:visible;
}
.sub-menu {
width:100%;
padding:5px 0px;
position:absolute;
top:100%;
left:0px;
z-index:-1;
opacity:0;
transition: opacity linear 0.15s;
box-shadow:0px 2px 3px rgba(0,0,0,0.2);
background:#2e2728;
visibility:hidden;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:inline-block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#3e3436;
}
<div class="navbar-izquierda menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li class="active">Portatil</li>
<li>Desk</li>
<li>Workstation</li>
<li>Promotions</li>
<li>Services and Guarantees <span class="arrow">▼</span>
<ul class="sub-menu">
<li>Error 1</li>
<li>Error 2</li>
<li>Horror 3</li>
</ul>
</li>
</ul>
</nav><!-- Navegador inferior -->
</div><!-- Navegador Inferior -->

CSS - How can I center my navigation bar?

I am new to HTML/CSS so please don't hurt me :)
How can I center my navigation? I've researched as much as I can...
CSS:
#navigation ul {
font-family:Arial;
list-style-type:none;
margin:0;
padding:0;
width:auto;
height:auto;
text-align:center;
}
#navigation ul li {
display:inline-block;
margin-right:-2px;
position:relative;
}
#navigation ul li a {
display:inline-block;
padding:5px 10px;
background:#ccc;
color:#000;
text-decoration: none;
}
#navigation ul li a:hover {background: #666;}
#navigation ul ul {
position:absolute;
left:0;
width:200px;
transition:all .5s;
max-height: 0;
overflow: hidden;
}
#navigation ul.submenu li {
display:block;
}
#navigation ul.submenu li a {
display:block;
background:#fff;
color: #000;
}
#navigation ul.submenu li a:hover {background: #333;}
#navigation ul li:hover ul {
max-height: 10000px;
}
#navigation li {
font-family:Arial;
font-size:11px;
display:inline;
float:left;
background-color:#FFF;
}
#navigation a {
display:block;
width:60px;
background-color:#FFF;
}
#navigation.center {
display:block;
margin-left:auto;
margin-right:auto;
}
#navigation {
disply:inline-block;
height:50px;
}
HTML:
<div id="navigation">
<ul>
<li>Aperture Science
<ul class="submenu">
<li>GLaDOS</li>
<li>Testing Chambers</li>
<li>The Player (Chell)</li>
</ul>
</li>
</ul>
<ul>
<li>Black Mesa
<ul class="submenu">
<li>The Combine</li>
<li>The Resistance</li>
<li>The Player (Gordon Freeman)</li>
</ul>
</li>
</ul>
</div>
Any help would be great! Thanks!
(Yes, my starter site is on Half Life and Portal)
You can try using below html code and css
HTML:
<div id="navMenu">
<ul>
<li>
Black Mesa
<ul>
<li>GLaDOS</li>
<li>Testing Chambers</li>
<li>The Player (Chell)</li>
</ul>
</li>
<li>
Black Mesa
<ul>
<li>The Combine</li>
<li>The Resistance</li>
<li>The Player (Gordon Freeman)</li>
</ul>
</li>
</ul>
</div>
CSS
#navMenu {
margin: 0;
padding: 0;
text-align: center;
}
#navMenu ul {
margin: 0;
padding: 0;
line-height: 30px;
display: inline-block;
}
#navMenu li {
margin: 0;
padding: 0;
text-align: left;
float: left;
list-style: none;
position: relative;
background-color: #999;
border-radius: 5px;
}
#navMenu ul li a {
text-align: center;
text-decoration: none;
height: 30px;
width: 150px;
display: block;
color: #FFF;
border: 1px solid #FFF;
text-shadow: 1px 1px 1px #000;
}
#navMenu ul ul {
position: absolute;
visibility: hidden;
top: 32px;
}
#navMenu ul li:hover ul {
visibility: visible;
}
#navMenu li:hover {
background-color: #09F;
}
#navMenu ul li:hover ul li a:hover {
background-color: #CCC;
color: #000;
}
#navMenu a:hover {
color: #000;
}
fiddle : http://jsfiddle.net/Khumesh/adx2g1z0/
You need to adjust navigation Div by applying width and setting its margin property using css:
#navigation{
width:50%;
margin:0 auto;
}
Please refer to fiddle for demo

Dropdown menu width misbehaving

My menu item with a dropdown submenu expands each time I mouse over. Below is the HTML code for it.
<header id="header">
<div style="width:90%; margin:auto;">
<div id="logo">Inversion iDeas</div>
<nav id="nav">
<ul>
<li>welcome</span></li>
<li>Discover<br /><span class="desc">About Us</span>
<ul>
<li>Our Services</li>
<li>Content Marketing Strategy</li>
<li>Print & Digital Publishing</li>
<li>Direct Interactive Marketing</li>
<li>Social Media Marketing</li>
<li>Search Marketing</li>
<li>Video</li>
<li>Experiential Marketing Events</li>
<li>Current Media Ideas</li>
<li>Events</li>
<li>Web & Mobile</li>
<li>Leadership</li>
</ul>
</li>
<li>Experience<br /><span class="desc">media</span></li>
<li>Testimony<br /><span class="desc">Satisfied Clients</span></li>
<li>Reach Us<br /><span class="desc">contact us</span></li>
</ul>
</nav>
</div>
</header>
css
header {
width: 100%;
background:#000;
opacity:0.8;
height: 80px;
position: fixed;
margin-top: 30px;
z-index:999;
}
#logo a {
color: #fff;
text-decoration: none;
float: left;
font-size: 30px;
margin-top: 20px;
font-family:"century gothic";
font-weight: normal;
height:45px;
width:287px;
text-indent:-9999px;
background:url(../images/logo.png) 0 0 no-repeat;
}
#nav {
width: 800px;
position:fixed;
top:50px;
left:400px;
}
#nav ul{
list-style: none;
display: block;
margin: 0;
padding: 0;
}
#nav li{
float: left;
padding: 10px 20px 0 20px;
border-left:solid 1px #fff;
text-align:center;
height:40px;
display:block;
font-size:12px;
}
#nav li:first-child{
border-left:none;
}
#nav li a {
color: #fff; opacity:0.7; font-size: 16px; text-decoration: none; font-family: Verdana, Geneva, sans-serif;
}
#nav li a.active { color: #94c600; opacity:1;}
#nav li a:hover { color: #94c600; opacity:1; width:100%;}
#nav li ul { display: none;}
#nav li:hover ul {display: block; position: relative; top:8px; left:-20px; width:160px; padding:0;}
#nav li:hover li {float: none; font-size:12px; background:rgba(0,0,0,0.8); border-left:none; text-align:left; }
#nav li:hover li a {font-size:12px; padding:0; margin:0;}
#nav li:hover li a:hover {color:#94c600;}
.desc{
font-size:12px;
color:#333;
display: block;
}
position: relative; on the parent. position: absolute; on the child.
JSfiddle (please include one the next time you post)
I added some positioning to your CSS
#nav li ul { display: none; position: relative;}
#nav li:hover ul {display: block; position: absolute; top:48px; left:168px; width:160px; padding:20px 0 0 0;}
#nav li:hover li {float: none; font-size:12px; background:rgba(0,0,0,0.8); border-left:none; text-align:left;}
See working live here
http://codepen.io/jhawes/pen/lyevj

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;
}