Making sub menu run horizontal - html

I'm having a bit of trouble turning my vertical sub menu into a horizontal one, everything I try seems to be incorrect or I end up changing the rest of the look of the main menu.
HTML
<nav>
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li><a href='#'><span>WORK</span></a>
<ul>
<li class="services1">
PRINT
BRANDING
EDITORIAL
PHOTOGRAPHY
</ul>
</li>
<li>BLOG</li>
<li>INSPIRED</li>
<li>CONTACT</li>
</ul>
</nav>
Here is the CSS
nav {
height: 70px;
float: left;
font-size: 20px;
color: #00BCDC;
font-family: "geogtq md";
}
nav ul {
list-style-type: none;
color: #00BBE4;
font-family: "geogtq md";
float: left;
display:inline;
}
nav li {
float: left;
margin-right: 20px;
color: #00BBE4;
font-family: "geogtq md";
margin-left: auto;
display: inline;
}
a:link {
text-decoration: none;
color: #00C0EE;
font-family: "geogtq md";
}
a:visited {
text-decoration: none;
color: #00C0EE;
}
a:hover {
text-decoration: none;
color: #007889;
}
a:active {
text-decoration: none;
color: #00C0EE;
}
ul {
font-family: "geogtq md";
font-size: 20px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: inline;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
text-decoration: none;
margin-right:5px;
white-space: nowrap;
color:#066;
}
li:hover ul {
display: inline;
position: absolute;
}
li:hover li {
float: none;
font-size: 16px;
font-weight:bold;
margin-top:3px;
}
.services1 a {
color:#00C0EE;
float: left;
list-style-type: none;
display:inline;
}
http://jsfiddle.net/GMbCU/
Any help would be greatly appreciated as this has been going on for a while and would help with how things sit on my site, thanks

Just give the child UL enough width and place each link in its own LI. You already have them displaying inline.
http://jsfiddle.net/GMbCU/7
li ul {
width: 450px;
}

try this: http://jsfiddle.net/pzC2g/
<nav>
<ul class='root'>
<li>HOME</li>
<li>ABOUT</li>
<li><a href='#'><span>WORK</span></a>
<ul class='sub'>
<li>PRINT</li>
<li>BRANDING</li>
<li>EDITORIAL</li>
<li>PHOTOGRAPHY</li>
</ul>
</li>
<li>BLOG</li>
<li>INSPIRED</li>
<li>CONTACT</li>
</ul>
</nav>
and css
.root {
display: block;
}
.root li {
display: inline-block;
float: left;
margin-right: 20px;
}
.root li .sub {
display: none;
}
.root li:hover .sub {
display: block;
position: absolute;
}
.root li:hover .sub li {
display: inline-block;
float: left;
}

Updated the above with Styles, see link : http://jsfiddle.net/pzC2g/27/
Thanks Goldj for great support,
**
*, html{
margin: 0;
padding:0;
}
nav{
background-color: #222;
}
.wrapper{
margin: 0 auto;
padding: 0px;
max-width: 1150px;
min-height:100%;
}
.root {
display: block;
}
.root li {
padding:10px;
display: inline-block;
margin-right: 20px;
color: #fff;
}
.root li:hover{
background-color:#555;
}
.root li a{
display:block;
text-decoration:none;
color:inherit;
}
.root li a:hover{
display:block;
}
.root li .sub {
background-color: #fff;
border: 1px solid #222;
margin-top: 10px;
left:0;
width:99.9%;
display: none;
font-size:14px;
}
.root li:hover .sub {
display: block;
position: absolute;
}
.root li:hover .sub li {
color: #000;
display: inline-block;
float: left;
}
.root li .sub li:hover {
background-color: #222;
color: #fff;
}
<nav>
<div class="wrapper">
<ul class='root'>
<li>HOME</li>
<li>ABOUT</li>
<li><a href='#'><span>WORK</span></a>
<ul class='sub'>
<div class="wrapper">
<li>PRINT</li>
<li>BRANDING</li>
<li>EDITORIAL</li>
<li>PHOTOGRAPHY</li>
</div>
</ul>
</li>
<li>BLOG</li>
<li>INSPIRED</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
**

Related

Add dropdown login to right side of navbar

My aim goal is to be able to do a drop down login/register form however I am stuck on how I could put the "Login / Register" part at the far right of the navbar, I have tried to do a new div and float it left but it seems to overlap the navbar items, any suggestions would be appreciated.
HTML:
div#navi{
background-color: #C23B22;
}
div#navi_wrapper{
margin: 0 auto;
text-align: left;
width: 1080px;
}
div#navi ul{
list-style-type: none;
padding: 0;
margin: 0;
}
div#navi ul li{
display: inline-block;
font-size: 15px;
font-family: 'Open Sans', sans-serif;
}
div#navi ul li a, visited{
color: #fff;
text-decoration: none;
padding: 16px;
display: block;
}
div#navi ul li a:hover{
color: #fff;
background-color: #AE351E;
}
div#navi ul li:hover ul{
display: block;
}
div#navi ul ul{
display: none;
position: absolute;
background-color: #fff;
color: #000;
border-top: 0;
min-width: 100px;
}
div#navi ul ul li{
display: block;
}
#navi ul li li a,visited{
color: #C23B22;
text-decoration: none;
}
#navi ul ul li a:hover{
background-color: #fff;
color: #C23B22;
font-weight: bold;
}
<div id="navi">
<div id="navi_wrapper">
<ul>
<li>HOME</li>
<li>REVIEWS
<ul>
<li>PC Games</li>
<li>Playstation 4</li>
<li>XBOX One</li>
</ul>
<li>ABOUT US</li>
<li>CONTACT</li>
</li>
</ul>
</div>
</div>
https://jsfiddle.net/q07jv74x/
The problem is you are using the HTML element's ID to set the CSS properties which will override the CSS properties of any nested elements. I would recommend using Classes instead:
HTML:
<div class="navi">
<div class="navi_wrapper">
<ul>
<li>HOME</li>
<li>REVIEWS
<ul>
<li>PC Games</li>
<li>Playstation 4</li>
<li>XBOX One</li>
</ul>
<li>ABOUT US</li>
<li>CONTACT</li>
<li class="navi_float_right">LOGIN</li>
</ul>
</div>
</div>
CSS:
.navi{
background-color: #C23B22;
}
.navi_wrapper{
margin: 0 auto;
text-align: left;
}
.navi ul{
list-style-type: none;
padding: 0;
margin: 0;
}
.navi ul li{
display: inline-block;
font-size: 15px;
font-family: 'Open Sans', sans-serif;
}
.navi ul li a, visited{
color: #fff;
text-decoration: none;
padding: 16px;
display: block;
}
.navi ul li a:hover{
color: #fff;
background-color: #AE351E;
}
.navi ul li:hover ul{
display: block;
}
.navi ul ul{
display: none;
position: absolute;
background-color: #fff;
color: #000;
border-top: 0;
min-width: 100px;
}
.navi ul ul li{
display: block;
}
.navi ul li li a,visited{
color: #C23B22;
text-decoration: none;
}
.navi ul ul li a:hover{
background-color: #fff;
color: #C23B22;
font-weight: bold;
}
.navi_float_right{
float: right;
}
I also removed the width property from the navi_wrapper CSS class as you typically want navbars to extend the full width of the screen.
Working JSFiddle: https://jsfiddle.net/pLofgdoy/1/

CSS Hover State in Drop Down Navigation

I can't figure out why the hover state in my css does not work. I've been successful in hiding the sub navigation, but can't get it to reappear on rollover. I Any help would be appreciated. Thanks.
Here's the html:
<nav>
<ul>
<li>writings</li>
<ul>
<li>devotionals</li>
<li>published</li>
<li>articles</li>
</ul>
<li>fundraising</li>
<li>about</li>
<li>contact</li>
</ul>
</nav>
and the css:
.nav {
position: relative;
margin-left: 200px;
margin-top: -50px;
}
.nav ul {
list-style: none;
margin: 0;
padding: 0;
}
.nav > ul > li {
float: left;
font-size: 30px;
}
.nav ul::after {
content:'';
display: block;
clear: both;
}
.nav ul li:hover > ul {
display: block;
}
.nav ul ul {
float: left;
display: block;
position: absolute;
top: 90%;
display: none;
line-height: 5px;
}
nav ul li a {
display: inline-block;
color: rgb(92,178,227);
font-family: 'Josefin Sans', sans-serif;
padding: 10px 20px;
text-decoration: none;
}
You need the sub nav inside of the list item:
<li>writings
<ul>
<li>devotionals</li>
<li>published</li>
<li>articles</li>
</ul>
</li>

Dropdown menu floating left

I made a menu, and I want the dropdown to go centered underneath the 'Fruitsoorten' tab. But now all three of the items are next to each other.
Does anyone know how to fix this? Thanks in advance.
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
<nav>
<ul>
<li>Home</li>
<li>
Fruitsoorten
<ul>
<li>Kersen</li>
<li>Appels</li>
<li>Pruimen</li>
</ul>
<li>
<li>Team</li>
<li>Agenda</li>
<li>Foto's</li>
<li>Vacatures</li>
<li>Contact</li>
</ul>
</nav>
You can also try this styles.
http://codepen.io/nehemc/pen/LkyQvq
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
padding: 10px;
display:block;
}
nav ul ul {
display: none;
position: absolute;
z-index: 999;
left: 0;
margin-top: 0;
}
nav li:hover ul {
display: block;
}
nav li:hover {
background-color: gray;
}
Add following code to reflect
nav ul { margin-top: 0; }
nav li ul {
display: none;
position: absolute;
left: 0;
z-index: 9;
}
Also clear your HTML code with proper closing of </li>
To affect your inline-block styling to main ul only,
Do this:
nav>ul>li {
display: inline-block;
position: relative;
padding: 10px;
}
instead of
nav li { display: inline-block; position: relative; padding: 10px; }
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
margin-top: 55px;
background-color: black;
}
nav>ul>li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
<nav>
<ul>
<li>Home
</li>
<li>Fruitsoorten
<ul>
<li>Kersen
</li>
<li>Appels
</li>
<li>Pruimen
</li>
</ul>
</li>
<li>Team
</li>
<li>Agenda
</li>
<li>Foto's
</li>
<li>Vacatures
</li>
<li>Contact
</li>
</ul>
</nav>
is that what you want?
nav {
float: right;
border-radius: 15px;
margin-right: 15%;
}
nav ul {
list-style-type: none;
background-color: black;
}
nav li {
display: inline-block;
position: relative;
padding: 10px;
}
nav li ul {
display: none;
}
nav li li {
display:
}
nav li:hover ul {
display: block;
position: absolute;
left: 0;
padding:0;
}
nav a {
text-decoration: none;
color: white;
font-size: 20px;
}
nav li:hover {
background-color: gray;
}
ul.inner li{width:83%}
<nav>
<ul>
<li>Home</li>
<li>Fruitsoorten
<ul class="inner">
<li>Kersen</li>
<li>Appels</li>
<li>Pruimen</li>
</ul>
<li>
<li>Team</li>
<li>Agenda
<li>Foto's</li>
<li>Vacatures</li>
<li>Contact</li>
</ul>
</nav>

Cant center dropdown menu

I have a dropdown below ive creaeted, but im having troulbe centering the the menu. Ive tried to put <center> tags around it and also set the ul to margin auto 0 but its not working. Is there anything im missing?
<style type="text/css">
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}
</style>
</head>
<body>
<ul id="menu">
<li>Home</li>
<li>Portfolio
<ul>
<li>Web Design</li>
<li>Graphic Design</li>
<li>Logo Design</li>
<li>Blog Design</li>
</ul>
</li>
<li>Projects
<ul>
<li>This is a project</li>
<li>So is this</li>
<li>and this</li>
<li>don't forget this too</li>
</ul>
</li>
<li>Contact
<ul>
<li>Support</li>
<li>Quote</li>
<li>General Enquiry</li>
</ul>
</li>
</ul>
I went ahead and put it on jsfiddle Here
I assume that you actually want to center the list items rather than just the menu.
JSfiddle Demo
Revised CSS
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0 auto;
padding: 0;
list-style: none;
text-align: center; /* added this */
font-size:0; /* whitespace adjustment */
}
ul li {
font-size:1rem; /* font-size reset */
display: block;
position: relative;
/* float: left; removed this */
display: inline-block;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}
Do you want the whole menu centered? If so, it helps to stick that all within something, like a table or div
so I added the following to your code:
css
#navbar {
width: 50%;
margin: 0 auto;
}
html
<div id="navbar">
all your ul/li's
</div>
all together
<style type="text/css">
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}
#navbar {
width: 50%;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="navbar">
<ul id="menu">
<li>Home</li>
<li>Portfolio
<ul>
<li>Web Design</li>
<li>Graphic Design</li>
<li>Logo Design</li>
<li>Blog Design</li>
</ul>
</li>
<li>Projects
<ul>
<li>This is a project</li>
<li>So is this</li>
<li>and this</li>
<li>don't forget this too</li>
</ul>
</li>
<li>Contact
<ul>
<li>Support</li>
<li>Quote</li>
<li>General Enquiry</li>
</ul>
</li>
</ul>
</div>
Here is a JSFiddle that demo's what I think you're after: JSFiddle
Basically, I changed your parent <li> to display: inline-block and removed the float: left property. To center those parent nav items, I applied text-align: center to the parent <ul>. Then I changed the nested dropdowns ul ul to be text-align: left and then set those <li>'s to display: block.
Final CSS (changed some selectors to target differently):
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
text-align: center; /* added this */
}
ul > li {
display: inline-block; /* changed from display: block */
position: relative;
/*float: left;*/
}
ul ul { text-align: left; } /* added this */
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul ul li { display: block; } /* added this */
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}

dropdown menu: whole menu comes down

I'm trying to make a basic dropdown menu with css and html. However when I hover on the li that has to drop down, my whole menu comes down with it.
This is my code:
<nav class="icons">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
<li>Account
<ul id="login">
<li>Change password</li>
<li>Update details</li>
<li>Logout</li>
</ul>
</li>
</ul>
</nav>
And the CSS
nav {
height: 70px;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
ul {
margin: 0;
padding: 0;
list-style: none;
margin-left: 5%;
}
ul li {
display: inline-block;
width: 15%;
text-align: center;
line-height: 70px;
}
ul li a {
text-decoration: none;
color: #fff;
font-size: 2em;
display: block;
}
ul li a:hover {
border-bottom: solid black 1px;
}
ul#login{
margin: 0;
padding: 0;
list-style: none;
}
ul#login li {
display: block;
width: 30%;
text-align: center;
line-height: 70px;
}
ul#login li a {
text-decoration: none;
color: #fff;
font-size: 2em;
display: block;
}
ul#login li ul li{
width: 20%;
}
ul#login li ul li a {
text-decoration: none;
color: #fff;
font-size: 0.7em;
display: block;
}
ul#login li a:hover {
border-bottom: solid black 1px;
}
I know it's a lot of CSS for such a basic menu but I don't know how to make it more compact.
Can someone please tell me what I'm doing wrong with the dropdown menu?
Add this css
ul li{
position:relative;
}
#login{
position:absolute;
top:71px;
left:0;
}
FIDDLE