I'm having great difficultly designing a drop down menu with pure css, that has fluid width. The examples I've found all have a fixed width top menu. As soon as I make the top menu fluid width, the drop down doesn't work. Can anyone help me complete the code? I basically have 7 menu items including a blank middle one. Over the middle one I have an absolute positioned logo.
HTML
<div style="position:relative;">
<img style="position:absolute; width:14.28%; max-height:80px; margin-left: auto;margin-right: auto;left: 0;right: 0;" src="\adrenicon.jpg"/>
<nav>
<ul>
<li>Start Here</li>
<li>Destinations
<ul>
<li>Africa</li>
<li>Europe</li>
<li>America</li>
</ul>
</li>
<li>Features</li>
<li> </li>
<li>Activities</li>
<li>Planner</li>
<li>Contact</li>
</ul>
</nav>
</div>
CSS:
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
nav li {
float: left;
width:14.28%;
text-align: center;
line-height: 50px;
display: inline-block;
position: relative;
}
nav li a {
font-weight: bold;
color: hotpink;
text-align: center;
padding: 0px;
text-decoration: none;
-webkit-transition: color 1s;
transition: color 1s;
}
nav li a:hover {
color: #111;
}
nav ul li ul {
position: absolute;
display: none;
background-color: #f9f9f9;
min-width: 160px;
}
Thanks for any help.
first you need to set overflow:visible to the main ul ( nav ul )
then, because you set a width of 14.28% on the nav ul li you need to set a width of 100% to the second level of li ( nav ul li ul li ) so they don't get on top of eachoter and each stays on a separate row
and because the li has float:left; you need to set float:left;width:100% on the nav ul also.
then on hover on li change display:none to display:block on the second ul
see below snippet. let me know if it works
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: visible;
background-color: #333;
float:left;
width:100%;
}
nav li {
float:left;
width:14.28%;
text-align: center;
line-height: 50px;
position: relative;
}
nav li a {
font-weight: bold;
color: hotpink;
text-align: center;
padding: 0px;
text-decoration: none;
-webkit-transition: color 1s;
transition: color 1s;
}
nav li a:hover {
color: #111;
}
nav ul li ul {
position: absolute;
display: none;
background-color: #f9f9f9;
min-width: 160px;
}
nav ul li ul li {
width:100%;}
nav ul li:hover > ul{
display:block;
}
nav ul ul ul {
right:-100%;
top:0
}
<div style="position:relative;">
<img style="position:absolute; width:14.28%; max-height:80px; margin-left: auto;margin-right: auto;left: 0;right: 0;" src="http://placehold.it/100x100.jpg"/>
<nav>
<ul>
<li>Start Here</li>
<li>Destinations
<ul>
<li>Africa
<ul>
<li>Kenya</li>
<li>Tanzania</li>
</ul>
</li>
<li>Europe
<ul>
<li>Spain</li>
<li>France</li>
</ul>
</li>
<li>America</li>
</ul>
</li>
<li>Features</li>
<li> </li>
<li>Activities</li>
<li>Planner</li>
<li>Contact</li>
</ul>
</nav>
</div>
Edited also for 3rd level of ul .
code : ul ul ul { right:-100%;top:0;}
Related
I'm trying to create a drop-down menu but my text-align command wouldn't seem to work (same applies with font-size and other text-related codes). I tried putting my text-align codes in nav ul li and nothing seem to happen. I've also tried putting it on the main .drop-down menu on CSS but it still has no changes. Can anyone help me out here? I couldn't figure out the reasoning behind this.
My HTML and CSS codes are:
nav{
flex:1;
text-align: right;
}
nav ul li{
list-style: none;
display: inline-block;
margin-left: 60px;
position: relative;
}
nav ul li a{
text-decoration: none;
color: #fff;
font-size: 13px;
transition: all 0.5s;
}
nav ul li a:hover{
color: #E6C7F3;
}
.dropdown-menu{
display: none;
}
nav ul li:hover .dropdown-menu {
display: block;
position: absolute;
left: -35;
top: 100%;
width: 100px;
background-color:black;
opacity: .8;
border-radius: 10px;
}
.dropdown-menu ul{
display: block;
padding-top: 10px;
}
.dropdown-menu ul li{
width: 0px;
left: -58;
bottom: 5;
padding: 10px;
padding-right: 40px;
text-align: center;
}
<div class="navbar">
<img src="image/durra.png" class="logo">
<nav>
<ul>
<li>HOME</li>
<li>ABOUT US</li>
<li>SHOP
<div class="dropdown-menu">
<ul>
<li>Bestsellers</li>
<li>Accessories</li>
<li>Jewelry</li>
<li>Miscellaneous</li>
</ul>
</div>
</li>
<li>FEEDBACK</li>
<li>CONTACT</li>
</ul>
</nav>
</div>
text-align works with a element having width. But you have used width: 0px . So it's pretty obvious you cannot use alignment there.
Hi First you have to add padding to ul under dropdown-menu. and then set width of li item to 100%. Please refer below code.
.dropdown-menu ul {
display: block;
padding-top: 10px;
padding: 10px 0 0;
}
.dropdown-menu ul li {
width: 100%;
left: -58;
bottom: 5;
padding: 10px 0;
/* padding-right: 40px; */
text-align: center;
}
I'm trying to create a dropdown menu for my personal website but something doesn't seem to go right.
HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li><li>
League</li><li>
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
Contact</li>
</ul>
</nav>
</header>
CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li {
display: inline-block;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
height: 20px;
border-radius: 2px;
}
The last few lines of code are the problem I think. The hover part covers every line-item that is within the .nav , but I don't know how to seperate the main navigation links from the sub navigation links (which should drop down) in css.
Can anyone explain to me what code I should add to let it work?
thanks.
I modified your complete code:
Here is it, There are several modification. This is may be helpful for you. You need to hide your drop-down option first and find out the time when firing it out and also how to fire.
And one important thing, you have to set your drop-down options as absolute, so that it is the child of some main option/ menu.
Modified HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li>
<li>
League
</li>
<li>Dropdown
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
</header>
Modified CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
position: relative;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li ul{
display: none;
}
.mainheader nav ul li {
display: inline-flex;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
border-radius: 2px;
}
.nav ul li:hover ul{
background: #aaa none repeat scroll 0 0;
display: block;
margin-left: -20px;
padding: 0;
position: absolute;
top: 60px;
width: 200px;
}
.mainheader nav ul li ul li{
box-sizing: border-box;
color: white;
display: inline-block;
padding: 20px;
width: 100%;
}
I suppose this is what you need:
https://jsfiddle.net/8f2hvdfh/1/
Your CSS was a mess. Check out a guide on how to make CSS dropdown menus: http://www.w3schools.com/css/css_dropdowns.asp
This gives you the basic setup:
nav ul ul {
position:absolute;
display:none;
padding-left:0;
}
nav ul li {
display:inline-block;
height:60px;
}
nav ul ul li {
display:block;
}
nav ul li a {
text-decoration:none;
color:white;
display:block;
padding:21px;
}
nav ul li:hover ul {
display:block;
}
The rest is bells and whistles. Good luck.
I'm beginning to make a website and I managed to make a navigation bar, with the first set of menus. The second set took awhile, but I managed to make. But now I would like to make a third set of submenu, but I have no idea how. Sort of like this image: http://vista-buttons.com/vista-skin/images/help/1_3.gif. Where a visitor has the choice to hover their mouse over products > submenu item 1 > submenu item 1_2
Here's what I have:
HTML:
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>Menu1</li><li>
Menu1
<ul>
<li>Menu2
</li></ul><li>
Menu1</li><li>
Menu1</li>
</ul>
</div>
<div style="z-index:0;left:0;top:0;width:100%;height:100%">
<img src="unknown.jpg" style='width:100%;height:100%'/>
</div>
CSS:
body{
padding: 0;
margin: 0;
overflow-y: scroll;
font-family: Arial;
font-size: 18px;
}
#nav{
background-color: #222;
}
#nav-wrapper{
width: 960px;
margin: 0 auto;
tex-align: left;
}
#nav ul{
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
#nav ul li{
display: inline-block;
}
#nav ul li:hover{
background-color: #333;
}
#nav ul li a,visited{
color: #ccc;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li a:hover{
color: #ccc;
text-decoration: none;
}
#nav ul li:hover ul{
display: block;
}
#nav ul ul{
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
min-width: 200px;
}
#nav ul ul li{
display: block;
}
#nav ul ul li a,visited{
color: #ccc
}
#nav ul ul li a:hover{
color: #099;
}
div#nav{
text-align: center;
}
Sorry if the question is too simple, thank you.
Try with this Fiddle Example..
<ul class="top-level-menu">
<li>About</li>
<li>Services</li>
<li>
Offices
<ul class="second-level-menu">
<li>Chicago</li>
<li>Los Angeles</li>
<li>
New York
<ul class="third-level-menu">
<li>Information</li>
<li>Book a Meeting</li>
<li>Testimonials</li>
<li>Jobs</li>
</ul>
</li>
<li>Seattle</li>
</ul>
</li>
<li>Contact</li>
DEMO FIDDLE
I have originally created my navigation in Chrome in which the outcome fits perfectly to my needs. I have then found out that Mozilla Firefox won't output the same result, the drop-down menus under Member Action and Admin Related will display vertically instead on horizontally as i wanted. However my biggest dissapointment was testing the navigation in Internet Explorer which won't even show the drop-down menus.
I would really appreciate someone checking the below code and your feedback, Thanks.
Solved the problem by changing one of the lines in css;
navigation ul li {float: left; list-style:none; }
HTML
<div id="navigationContainer">
<div id="navigation">
<ul>
<li class="borderleft">Home </li>
<li>Register </li>
<li>Search cars</li>
<li>Display all cars</li>
<li>Member Actions
<ul> <!-- Open drop down menu -->
<li class="bordertop">Login</li>
<li class="floatLeft">Member Area</li>
<li>Reservation</li>
<li>Contact us</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car</li>
<li>Delete a car</li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>
CSS
* {padding: 0%; margin 0%; } /* Overwrites the browser stylesheet */
#navigationContainer {background:url(images/navi.png); width:100%;position: relative; white-space:nowrap; word-spacing:0; }
#navigation {width:1200px; height:65px; position: relative; font-family: Arial; margin: 2px auto; font-size: 125%; }
#navigation ul { list-style-type: none; }
#navigation ul li {float: left; position: relative; }
#navigation ul li a { border-right: 2px solid #e9e9e9; padding: 20px;
display: block; margin: 0 auto; text-align: center; color: black; text-decoration: none; }
#navigation ul li a:hover { background: blue; color: white; }
#navigation ul li ul { display: none; }
#navigation ul li:hover ul {display: block; position: absolute; }
#navigation ul li ul li {float:left; position:relative; }
#navigation ul li:hover ul li a { background: #12aeef; color: white; position:relative; margin: 0px auto; border-bottom: 1px solid white; border-right: 1px solid white; width: 119px; }
#navigation ul li:hover ul li a:hover { background: blue;}
.bordertop { border-top: 1px solid white; }
.borderleft { border-left: 2px solid #e9e9e9;}
Try this
http://jsfiddle.net/Vf3AJ/
Example from: http://www.cssnewbie.com/example/css-dropdown-menu/horizontal.html
EDITED
Misread horizontal for vertical. tested in IE10, FF, and Chrome
As a side note: horizontal menus have serious issues depending on the width of the viewers screen.
CSS
nav {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
nav li {
list-style: none;
float: left;
}
nav li a {
display: block;
padding: 3px 8px;
text-transform: uppercase;
text-decoration: none;
color: #999;
font-weight: bold;
}
nav li a:hover {
background: blue;
color: white;
}
nav li ul {
display: none;
}
nav li:hover ul, nav li.hover ul {
position: absolute;
display: inline;
left: 0;
width: 100%;
margin: 0;
padding: 0;
}
nav li:hover li, nav li.hover li {
float: left;
}
nav li:hover li a, navbar li.hover li a {
color: #000;
}
nav li li a:hover {
color: white;
}
HTML
<div id="navigationContainer">
<nav id="navigation">
<ul>
<li class="borderleft">Home
</li>
<li>Register
</li>
<li>Search cars
</li>
<li>Display all cars
</li>
<li>Member Actions
<ul>
<!-- Open drop down menu -->
<li class="bordertop">Login
</li>
<!-- A bordertop class is given to this listed element in order to style a top border for in in the external CSS file. -->
<li class="floatLeft">Member Area
</li>
<li>Reservation
</li>
</ul>
</li>
<li>Contact us
</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car
</li>
<li>Delete a car
</li>
</ul>
</li>
</ul>
</nav>
</div>
Trying to make just the services link orange on hover with a gray background- can't do it without changing all the menu items.
I can't click on the examples link after hovering over services.
.menu
{
margin:0;
padding:0;
}
.menu ul {
padding-top: 40px;
padding-left: 0px;
line-height: 0px;
margin-bottom: 0px;
float: right;
}
ul li {
display: inline;
}
ul li a:visited {
text-decoration: none;
}
ul li a:hover, .menu ul li .current{
color: #f7823b;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
float: left;
font-size: 20px;
display: block;
text-decoration: none;
color: #ffffff;
padding: 20px;
margin-left: 1px;
white-space: nowrap;
}
li:hover ul {
display: block;
}
li:hover li {
float: none;
font-size: 11px;
}
ul ul li:hover a { background: #818285; }
/*li:hover li a:hover { background: #818285; width:100%; }*/
ul ul {
position: absolute;
z-index: 500;
margin:0;
padding-top: 0px;
}
ul ul li a
{
padding: 20px 0px 20px 5px;
width: 100%;
background: #818285;
}
<div class="socialmedia">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/facebook.png" <="" img="">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/twitter.png" <="" img="">
<a href="http://www.stumbleupon.com/stumbler/CyclonStrategies">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/stumbleupon.png" <="" img=""></a>
<a href="http://www.linkedin.com/company/cyclone-strategies-llc">
<img class="button" src="http://lifeafterclass.com/cyclone/images/header/linkedin.png" <="" img=""></a>
</div>
<div class="menu">
<ul id="menu">
<li>Home</li>
<li> About</li>
<li class="special"> Services
<ul>
<li>Digital Advertising</li>
<li>Promotion Management</li>
<li>Social Media</li>
</ul>
</li>
<li>Examples</li>
<li> Blog </li>
<li> Contact Us</li>
</ul>
</div>
<div style="clear:both"></div>
</div>
I've tried everything- any help is appreciated. Thanks!
http://jsfiddle.net/8ARm5/
Since the li containing services has a class special you can use this to target the element upon hover.
.special:hover{
color: orange;
background: grey;
}
Try to add hover on li not a element:
li:hover > a {
color: #f7823b;
}
Doing so the link keeps style definition even if you points links in submenu.
Take a look: http://jsfiddle.net/8ARm5/5/