I am working on a navbar menu for my website, but I am stacked. The concept is to have the logo in the middle of the navbar and the three menu options from left and the other three menu from right.
<header id="top-header">
<div class="row">
<div class="large-12 columns">
<div class="logo"></div>
<ul class="menu" id="nav-menu">
<li>MENU 1</li>
<li>MENU 2</li>
<li>MENU 3</li>
<li>MENU 4</li>
<li>MENU 5</li>
<li>MENU 6</li>
</ul>
</div>
</div>
</header>
I tried to add a width to <li> with percentage like this which worked for the menu titles:
#top-header ul > li {
display: block;
float: left;
width: 16%;
position: relative;
}
However, my problem now is the image with the logo. It doesn't stay on the center of the screen. The image is the whole navbar with the logo on the middle, so I was hoping to resize vertically the image when the browser change resolution.
#top-header .logo {
background-color: transparent;
background-image: url("img/menubar_logo.png");
height: 100%;
padding-left: 10px;
position: absolute;
transition: all 0.3s ease 0s;
width: 100%;
z-index: 1;
}
I would include the logo as the middle list element and turn it into a faux table. This will eliminate the need to define a width for the elements within.
http://jsfiddle.net/3pf4onbj/
HTML
<header id="top-header">
<div class="row">
<div class="large-12 columns">
<ul class="menu" id="nav-menu">
<li>MENU 1</li>
<li>MENU 2</li>
<li>MENU 3</li>
<li><div class="logo"></div></li>
<li>MENU 4</li>
<li>MENU 5</li>
<li>MENU 6</li>
</ul>
</div>
</div>
</header>
CSS
.logo {
width:100px;
height:30px;
background:#ff0;
}
#top-header ul {
display:table;
width:100%;
margin:0;
padding:0;
}
#top-header ul > li {
display: table-cell;
vertical-align:middle;
margin:0;
padding:0;
text-align:center;
}
#top-header ul > li a {
display:block;
padding:3px 5px;
}
Related
I can't quite figure out why my drop down menu is hidden behind the div which contains the menu. I've tried positioning various elements relative and z-indexing the menu to a higher value than the div it's contained in but I've not had much luck.
My JS Fiddle link is here:
https://jsfiddle.net/Lj919ca6/
And the code for demonstrative purposes is here:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Abel" rel="stylesheet">
<title>Header 1</title>
</head>
<body>
<header id="header">
<div id="action-bar">
<div class="container">
<div>
<p class="ab-p">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<ul class="ab-ul top-bar-links">
<li>We Can Help</li>
<li>Something Random</li>
<li>More Random</li>
</ul>
</div>
</div>
</div>
<div class="main-header">
<div class="container">
<div>
<img class="logo" src="logo.png">
</div>
<div class="main-nav">
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4
<ul>
<li>Deep Menu 1
<ul>
<li>Sub Deep 1</li>
<li>Sub Deep 2</li>
<li>Sub Deep 3</li>
<li>Sub Deep 4</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
<li>Sub Menu 5</li>
</ul>
</li>
<li>Menu 2
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
</ul>
</li>
<li>Menu 3
<ul>
<li class="dir">Sub Menu 1</li>
<li class="dir">Sub Menu 2 THIS IS SO LONG IT MIGHT CAUSE AN ISSEUE BUT MAYBE NOT?
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
<li>Category 5</li>
</ul>
</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4</li>
<li>Sub Menu 5</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</header>
<img src="gentleman.jpg" />
</body>
</html>
CSS:
body{
margin:0;
}
p{
font-family: 'Abel', sans-serif;
-webkit-margin-before: 2px;
-webkit-margin-after: 2px;
}
a{
font-family: 'Abel', sans-serif;
}
li{
font-family: 'Abel', sans-serif;
}
ul{
list-style: none outside;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 0px;
}
ul li{
color:white;
display: inline-block;
margin-right: 6px;
padding-right: 6px;
border-right: 1px solid rgba(255,255,255,.1);
}
#header{
position: relative;
}
#action-bar{
left: 0;
top: 0;
width: 100%;
z-index: 30;
background: #242b33;
height:45px;
}
.container{
max-width: 1220px;
margin:0 auto;
position:relative;
overflow: hidden;
}
.ab-p{
color:#fff;
float:left;
padding:10px;
}
.top-bar-links{
float: right;
padding:10px;
}
.main-header{
position: static;
width: 100%;
background-color: #0c141d;
display:block;
overflow:auto;
}
.logo{
float: left;
width:300px;
height:auto;
}
.main-nav{
float:right;
}
#primary_nav_wrap ul
{
list-style: none;
position: relative;
float: left;
margin: 0;
padding: 0;
z-index: 201;
}
#primary_nav_wrap ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
#primary_nav_wrap ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
#primary_nav_wrap ul li:hover
{
background:#f6f6f6
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary_nav_wrap ul ul li
{
float:none;
width:200px
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
#primary_nav_wrap ul li:hover > ul
{
display:block
}
Any help appreciated greatly.
.container had overflow set to hidden that seems to be the culprit.
You have given two elements with overflow properties.
.container and #header, remove overflow and add the following css to main-header
min-height:200px; // depending on what you want the height to be.
Here is the code pen link : http://codepen.io/saa93/pen/qqdRZy
I can't change the colour of the background that my navigation bar has. I'm not using any framework so there's no conflicts. Here's the code that I have tried:
.navigation-right {
float: right;
}
.navigation-left {
float: left;
}
.navigation-main {
background-color: #000;
width: 100%;
}
.navigation-main li {
display: inline-block;
padding: 10px;
}
.navigation-main a {
color: #F2F2F2;
text-decoration: none;
}
<div class="container">
<section class="navigation">
<nav class="navigation-main">
<ul>
<div class="navigation-right">
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
</div>
<div class="navigation-left">
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
</div>
</ul>
</nav>
</section>
You are missing an overflow:hidden in the parent of the floating elements. Without it, the browser can't calculate the height hence the background colour not coming through. Try adding this line to your CSS:
.navigation-main{
background-color: #000;
width: 100%;
overflow: hidden; // Add this
}
You have to clear your floats. Using overflow is a sneaky, though not always preferable way. The best way - in my opinion - is using a pseudo element, like so:
/* Clear */
ul::after {
content: "";
display: table;
clear: both;
}
.navigation-right {
float: right;
}
.navigation-left {
float: left;
}
.navigation-main {
background-color: #000;
width: 100%;
}
.navigation-main li {
display: inline-block;
padding: 10px;
}
.navigation-main a {
color: #F2F2F2;
text-decoration: none;
}
<div class="container">
<section class="navigation">
<nav class="navigation-main">
<ul>
<div class="navigation-right">
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
</div>
<div class="navigation-left">
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
<li>Menu
</li>
</div>
</ul>
</nav>
</section>
Note though, that you oughtn't split up your menu like that, with divs inside a list. Instead, create two seperate lists.
Just corrected your HTML and add overflow:hidden to you're .navigation-main{...}
JsFiddle There
Teknotica had it aswell :)
PICTURE: http://imgur.com/3GAMFgf
I have a navigation in my header (Main Navigation), which I want to be positioned like shown in the picture. I have tried displaying it like an inline-block element, floating it to the right and it kinda works. The problem is that the navigation won't be horizontally aligned with the logo while still being responsive.
My header consists of:
<header class="primary-header">
<img src="[SOURCE]" alt="Logo">
<h1>[WEBSITE TITLE]</h1>
<nav class="nav secondary-nav">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</nav>
<nav>
<ul>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ul>
</nav>
<header/>
My CSS:
.nav li {
display: inline-block;
}
.primary-header {
padding: 15px;
}
.primary-header img {
width: 17.5%;
height: auto;
}
/*Main Navigation*/
.primary-nav {
vertical-align: middle;
}
h1 {
display: inline-block;
}
I simply can't find a solution on how to position the main navigation like shown in the picture while still being responsive/fluid by using CSS. If anyone could help pointing me in the right direction, I would be very thankful!
Try using flex box like this:
.primary-header {
padding: 15px;
display: flex; /*important line*/
align-items: center; /*important line*/
}
Here a working snippet (see in full page, here is to narrow)
.nav li {
display: inline-block;
}
.primary-header {
padding: 15px;
display: flex;
align-items: center;
}
.primary-header img {
width: 17.5%;
height: auto;
}
/*Main Navigation*/
.primary-nav {
vertical-align: middle;
}
h1 {
display: inline-block;
}
<header class="primary-header">
<img src="http://i.stack.imgur.com/gijdH.jpg?s=328&g=1" alt="Logo">
<h1>[WEBSITE TITLE]</h1>
<nav class="nav secondary-nav">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</nav>
<nav>
<ul>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ul>
</nav>
<header/>
img,
h1,
nav {
display: inline-block;
vertical-align: middle;
}
I am a dropdown menu noob, and I can't seem to figure out how to keep my dropdown menu from blowing out and moving the main buttons. I'm sure its some kind of positioning adjustment, but I can't figure out where and what it is. Here is the jfiddle link: http://jsfiddle.net/F4WvT/
Here is the html:
<div id="global-nav">
<ul>
<li>HOME
</li>
<li>ABOUT
<div id="global-subnav">
<ul>
<li>Sub Category 1</li>
<li>Sub Category 2</li>
<li>Sub Category 3</li>
<li>Sub Category 4</li>
<li>Sub Category 5</li>
<li>Sub Category 6</li> </ul>
</div>
</li>
<li>CONTENT
<div id="global-subnav">
<ul>
<li>Sub Category 1</li>
<li>Sub Category 2</li>
<li>Sub Category 3</li>
<li>Sub Category 4</li>
<li>Sub Category 5</li>
<li>Sub Category 6</li> </ul>
</div>
</li>
<li>CONTACT
</li>
</ul>
</div>
And the CSS:
<style type="text/css">
#global-nav {
width: 180px;
height: 40px;
background-image: none;
float: left;
position: static;
margin-left:0px;
}
#global-nav a {
color:#000;
font-size:12px;
cursor:pointer;
display:block;
width: 200px;
height: 40px;
text-align:center;
vertical-align: central;
text-decoration:none;
font-weight:bold;
}
#global-nav ul {
background: whitesmoke;
padding: 0;
margin: 0;
}
#global-subnav ul{
background: #D3171A;
position: relative;
width: 250px;
text-align:center;
left: 180px;
top: -55px;
}
#global-nav li {
list-style: none;
border-bottom: none;
border-width: 0px;
}
#global-nav ul ul li {
display:none;
}
#global-nav li:hover {
background: none;
}
#global-nav li:hover ul li {
display:block;
}
</style>
How do I get this my main nav buttons to stay still? Good karma for quick advice!
#global-subnav ul {
background: #D3171A;
position: relative;
width: 250px;
text-align: center;
left: 0px;
top: 0;
}
You need to make your sub navigation positioned absolute to it's relative parent, which in your case has to be the <li> element. Setting a top: 0 of your sub navigation element, will position it at the top of its parent, which is exactly what you want.
Edited example of your code: this JSFiddle
I need to achieve this layout, please note on the current item,
The 3 sublists are supoused to be children of the current item,
The problem here is that if I set the position absolute and left:0 and width:100%; the max width would be determined for the parent's width,
So,
How can I keep the lists children and make them use the whole avaliable space?
this is my markup for now: (can i keep it?)
<nav>
<ul class="main">
<li><?=lang('grupo-cabau')?></li>
<li class="active">
<?=lang('nuestros-hoteles')?>
<ul>
<li>
<ul>
<li>list
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
</ul>
<ul>
<li>listt <ul>
<li>item</li>
</ul>
</li>
</ul>
<ul>
<li>list
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><item</li>
<li>item</li>
</ul>
<ul class="lang">
<li>ESP
<ul>
<li>ENG</li>
<li>DEU</li>
</ul>
</ul>
</nav>
My current implementation (almost there):
header .wrapper > div nav ul.main > li.active > ul {
background: none repeat scroll 0 0 #FFFFFF;
display: block;
height: 141px;
left: 0;
position: absolute;
top: 60px;
width: 100%;
}
Problem when I set li.active to position:relative (very far from there):
So question is,
How can the position:absolute child be bigger (and left,right properties respond to the layout) with the parent being position:relative???
Is my only chance to take the list out of the tree?
What you are trying to do is set the width based on a parent's parent. That is the problem. But as you commented, the menu has a fixed width, which makes it easier.
I cleaned the HTML up to this:
<ul class="nav">
<li>item 1</li>
<li>item 2
<ul>
<li>List 2.1
<ul>
<li>item 2.1.1</li>
<li>item 2.1.2</li>
<li>item 2.1.3</li>
</ul>
</li>
<li>List 2.2
<ul>
<li>item 2.2.1</li>
<li>item 2.2.2</li>
<li>item 2.2.3</li>
</ul>
</li>
<li>list 2.3
<ul>
<li>item 2.3.1</li>
<li>item 2.3.2</li>
<li>item 2.3.3</li>
</ul>
</li>
</ul>
</li>
<li>item 3</li>
<li>item 4</li>
</ul>
Then made this CSS:
body, ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.nav {
list-style: none;
margin: 0;
padding: 0;
width: 500px; /* needs to be a fixed width */
background: lightblue;
}
.nav > li {
display: inline-block;
background: lightblue;
margin-right: -4px;
padding: 15px;
}
.nav > li > ul {
position: absolute;
display: table;
width: 500px; /* same width as .nav */
left: 0;
margin-top: 15px;
background: lightgreen;
}
.nav > li > ul > li {
display: table-cell;
width: 33%;
}
Check this demo: http://jsfiddle.net/LinkinTED/4a98c/
You'll probably want to show the submenu on a :hover effect, check http://jsfiddle.net/LinkinTED/4a98c/2/