Creating drop down UL navigation bar - html

Here is my code so far:
<?php
echo '
<nav class="floatfix">
<ul>
<li>Home</li>
<ul>
<li>£3.99 T-Shirts</li>
<li>£4.99 T-Shirts</li>
</ul>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>
';
?>
Here is my CSS
/* =float clearing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.floatfix {
display: block;
height: 1%;
text-transform: uppercase;
}
.floatfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
How can I get the £3.99 Shirts & £4.99 Shirts as a drop down menu beneath the 'Home' on the navigation bar.
Thankyou very much

Not even going into the CSS you need to enclose the secondary UL in the Home LI like below:
<nav class="floatfix">
<ul>
<li>Home
<ul>
<li>£3.99 T-Shirts</li>
<li>£4.99 T-Shirts</li>
</ul>
</li>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>
CSS stolen from a quick tutorial:
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;
} ​
Demo: http://jsfiddle.net/calder12/7j6H9/

Unless I am missing something, you want to use a select like like so:
<nav class="floatfix">
<ul>
<li>Home</li>
<select id="lstPrice">
<option value="3.99">£3.99 T Shirts</option>
<option value="4.99">£4.99 T Shirts</option>
</select>
<li>Log In</li>
<li>Account</li>
<li>Feedback</li>
<li>Checkout</li>
<li>About Us</li>
</ul>
</nav>

Related

Navigation Menu Alignment

I'm trying to create a basic drop down menu. I'm having issues with the alignment. How can I get sub menu items to be directly underneath one another? For example, I am trying to get twitter, instagram, and facebook underneath "Social".
Thanks.
https://jsfiddle.net/xalxnder/ostaqgyk/
HTML
<body>
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
</body>
CSS
body {
background: #000000;
color: white;
}
.main-nav {
float: left;
}
.main-nav li {
font-size: 10px;
display: inline;
padding-right: 10px;
}
.main-nav .sub {
color: pink;
float: none;
z-index: -200;
}
//** .sub{display: none;
}
.dropdown:hover > .sub {
display: block;
position: absolute;
}
Here's the basics of it.
JSFiddle
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: black;
}
ul {
list-style-type: none;
color: white;
}
.main-nav >li {
display: inline-block;
position: relative;
padding-right: 10px;
}
.sub {
position: absolute;
top: 100%;
left: 0;
color: pink;
/* display:none */ /* disabled for demo */
}
.dropdown:hover .sub {
display:block;
}
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
Since block-level elements take up their own line, this rule should hold you:
.sub li {
display: block;
}
Add to .main-nav .sub:
position: absolute;
padding: 0;
body {
background: #000000;
color: white;
}
.main-nav {
float: left;
}
.main-nav li {
font-size: 10px;
display: inline-block;
padding-right: 10px;
}
.main-nav .sub {
position: absolute;
padding: 0;
color: pink;
float: none;
z-index: -200;
}
.sub li {
display: block;
}
<body>
<ul class="main-nav">
<li>Home</li>
<li>Projects</li>
<li class="dropdown">
Social
<ul class="sub">
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</li>
</ul>
</body>

How to fix navbar dropdown menu in css

I have a problem with the dropdown menu when I hover in services menu. Here's the problem (on Codepen)
*{
margin: 0;
padding: 0;
}
body{
margin: 0 auto;
width: 800px;
}
a{
font-family: 'Alegreya Sans Regular';
}
#navigation{
height: 113px;
width: 800px;
background-color: #17384D;
}
.weblogo{
margin-top: 34px;
margin-left: 20px;
}
nav{
float: right;
margin-top: 60px;
margin-right: 60px;
}
nav ul ul{
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul li{
display: inline-block;
padding-left: 45px;
}
nav ul li a{
text-decoration: none;
list-style: none;
color: #FAD46B;
font-size: 1.3em;
}
.active{
border-bottom: 2px solid #FF972C;
padding-left: 0px;
}
<div id="navigation">
<img class="weblogo"src="weblogo.png"></img>
<nav>
<ul>
<li class="active">home</li>
<li>work</li>
<li>about</li>
<li class="dropdown">services
<ul>
<li>Search</li>
<li>Search</li>
<li>Search</li>
<li>Search</li>
</ul>
</li>
<li>contact</li>
</ul>
</nav>
Better way to create sub menus is this
Replace your html with this
HTML
<div id="navigation">
<img class="weblogo"src="weblogo.png"></img>
<nav>
<ul>
<li class="active">home</li>
<li>work</li>
<li>about</li>
<li class="dropdown"><a onClick="toggleNavPanel('panel')" >services</a>
<div id="panel">
<div>
<ul>
<li>Search</li>
<li>Search</li>
<li>Search</li>
<li>Search</li>
</ul>
</div>
</div>
</li>
<li>contact</li>
</ul>
</nav>
And add this to your css
#panel {
position: absolute;
background-color: red;
height: 0;
width: 100px;
top: 120px;
transition: height 0.3s linear 0s;
overflow:hidden;
}
Add this javascript also
function toggleNavPanel(x) {
var panel = document.getElementById(x), maxH="300px";
if(panel.style.height == maxH) {
panel.style.height = "0px";
}else {
panel.style.height = maxH;
}
}
Also remove this from your css
nav ul li:hover > ul {
display: block;
}

How to position submenus to appear correctly under the main menu (CSS)?

I've been able to create a horizontal menu using (display:inline) and I now have a drop menu thanks to sousMenu. My problem is that all the submenus, regardless of element I hovered over, appear in the same place. How do I work around this?
My menu code thus far:
<ul>
<li>Home</li>
<li class="sousMenu">About Us
<ul>
<li>Board of Directors</li>
</br>
<li>Student Profiles</li>
</br>
<li>Projects</li>
</ul>
</li>
<li class="sousMenu">Get Involved
<ul>
<li>Donations</li>
</br>
<li>Job Board</li>
</br>
<li>Join</li>
</ul>
</li>
<li class="sousMenu">Resources
<ul>
<li>Connections</li>
</br>
<li>Gallery</li>
</br>
<li>Tours</li>
</ul>
</li>
CSS:
#navcontainer ul {
/*margin: 0;*/
margin-left: auto;
margin-right: auto;
padding: 0;
top:180;
right:20;
width:800px;
list-style-type: none;
text-align: center;
position: absolute;
color: #fff;
background-color: #003300;
padding: .2em 1em;
}
#navcontainer ul li {
display: inline;
padding-left:2cm;
}
#navcontainer ul li a {
text-decoration: none;
color: #fff;
background-color: #030;
}
#navcontainer ul li a:hover {
color: #fff;
background-color: #000;
}
.sousMenu:hover ul {
display: block;
}
.sousMenu ul {
text-align: center;
display: none;
list-style-type: none;
}​
Try setting the parent list item to position: relative and the child ul to position: absolute for starters. I made some other slight modifications to your code to achieve the desired effect.
Here's the CSS:
* {
margin: 0;
padding: 0;
vertical-align: baseline;
}
li {
list-style-type: none;
}
ul.main li {
position: relative;
display: inline-block;
}
.main li:hover > ul {
display: block;
}
ul.sub {
position: absolute;
display: none;
top: 100%;
left: 0;
}
ul.sub li {
display: block;
}
I also cleaned up the HTML a bit. You were missing a closing </ul> tag as well:
<ul class="main">
<li>Home</li>
<li class="sousMenu">About Us
<ul class="sub about">
<li>Board of Directors</li>
<li>Student Profiles</li>
<li>Projects</li>
</ul>
</li>
<li class="sousMenu">Get Involved
<ul class="sub get-involved">
<li>Donations</li>
<li>Job Board</li>
<li>Join</li>
</ul>
</li>
<li class="sousMenu">Resources
<ul class="sub resources">
<li>Connections</li>
<li>Gallery</li>
<li>Tours</li>
</ul>
</li>
</ul>
Here's the fiddle: http://jsfiddle.net/vXhZb/2/

My drop down menu isn't displaying the drop down portion of the menu in Chrome/IE

I have recently added a drop down menu to my website... well, in the works of adding a drop down menu to my website. I have the list displayed horizontally but the drop down portions of the list are not.. dropping down. I was wondering if someone would be able to take a look and tell me what I am doing wrong?
Thanks, here is my code.
HTML
<ul id="main-nav">
<li>Home</li>
<li>Products</li>
<ul>
<li>Apparel</li>
<li>Gloves</li>
<li>Punching Bags</li>
<li>Protection</li>
<li>Accessories</li>
</ul>
<li>Wholesales</li>
<ul>
<li>Equipment Catalogue</li>
<li>Wholesale Inqueries</li>
</ul>
<li>Contact</li>
<ul>
<li>Direct Contact</li>
<li>YouTube Channel</li>
<li>LinkedIn Page</li>
<li>Facebook Page</li>
</ul>
</ul>
CSS
#main-nav,
#main-nav ul {
list-style: none;
}
#main-nav {
float: left;
}
#main-nav > li {
float: left;
}
#main-nav li a {
display: block;
height: 25px;
line-height: 2em;
padding: 0 1.5em;
text-decoration: none;
}
#main-nav ul {
position: absolute;
display: none;
z-index: 999;
}
#main-nav ul li a {
width: 80px;
}
#main-nav li:hover ul {
display: block;
}
/* Main menu
------------------------------------------*/
#main-nav {
font-family: Arial;
font-size: 12px;
background: #880202;
}
#main-nav > li > a {
color: #fffff;
font-weight: bold;
}
#main-nav > li:hover > a {
background: #c90000;
color: #ffffff;
}
/* Submenu
------------------------------------------*/
#main-nav ul {
background: #880202;
}
#main-nav ul li a {
color: #ffffff;
}
#main-nav ul li:hover a {
background: #c90000;
}
put this code in you code and check
<ul id="main-nav">
<li>Home</li>
<li>Products
<ul>
<li>Apparel</li>
<li>Gloves</li>
<li>Punching Bags</li>
<li>Protection</li>
<li>Accessories</li>
</ul></li>
<li>Wholesales
<ul>
<li>Equipment Catalogue</li>
<li>Wholesale Inqueries</li>
</ul></li>
<li>Contact
<ul>
<li>Direct Contact</li>
<li>YouTube Channel</li>
<li>LinkedIn Page</li>
<li>Facebook Page</li>
</ul></li>
</ul>
li tag is over after the sub menu ul tag

CSS dropdown menu vertically

I have this site here http://surfthecurve.ca/ and I have a navigation for each nav item there is a drop down menu, the menu works fine, I just cant seem to get it to go vertically.
Here is the CSS for the navigation
.navigation{
width:100%;
background-color:#353636;
font-size:18px;
float:left;
}
.navigation ul {
list-style-type: none;
margin: 0 auto;
width:825px;
}
.navigation li {
float: left;
}
.navigation ul a {
color: #ffffff;
display: block;
padding: 0 105px 0 0;
text-decoration: none;
width:100%;
text-align:center;
text-transform:uppercase;
}
and the CSS for the drop-down
.submenu {
display: none;
}
.submenu li a {
display: block;
text-decoration: none;
color: #ffffff;
padding: 5px 15px 5px 15px;
margin-left: 1px;
white-space: nowrap;
}
.navigation li:hover .submenu {
display: block;
position: absolute;
}
.navigation li:hover .submenu li {
float: left;
font-size: 13px;
}
ul li a:hover {
background: #353636;
}
li:hover a {
background: #353636;
}
li:hover li a:hover {
background: #353636;
}
.navigation ul li ul li a{
padding-left:10px !important;
padding-right:10px !important;
padding-top:0px !important;
padding-bottom:0px !important;
}
and here is the HTML
<div class="navigation">
<ul>
<li>tutoring
<ul class="submenu">
<li>Our Approach</li>
<li>Pricing</li>
</ul>
</li>
<li>the cause
<ul class="submenu">
<li>How It Works</li>
<li>How We Give</li>
<li>Why We Give</li>
</ul>
</li>
<li>company
<ul class="submenu">
<li>About Us</li>
<li>Let's Get In Touch</li>
</ul>
</li>
<li>get involved
<ul class="submenu">
<li>Students</li>
<li>Work For Us</li>
</ul>
</li>
</ul>
</div><!--navigation-->
How would I fix this for my menu goes vertically?
Thanks in advanced,
J
This should be easy enough to get it to display vertically:
.submenu li {
clear: both;
}
What you have to do now is style it, as the individual li elements are different sizes (the element shrink wraps to the size of the text).