Submenu positioning issues - html

Here's what I'm working with currently, I'm trying to create a drop down menu for the team section but it keeps showing up to the left of the menu selection for teams. Here the site for reference:
http://lakenonabaseballassociation.com/
CSS
.header
{
background: none ;
height: 50px;
width:960px;
margin: auto auto;
padding: 25px 0 0 33px;
}
.header ul
{
float:left;
list-style:none;
margin:0;
overflow:hidden;
padding:9px 9px 0 0;
}
.header ul li
{
float:left;
}
.header ul li a
{
color:#656465;
font-family:bevanregular;
font-size:16px;
font-weight:400;
letter-spacing:.025em;
line-height:30px;
text-decoration:none;
text-transform:uppercase;
margin: 175px 11px 0 11px;
}
.header ul li.selected a, .header ul li a:hover
{
color:#026593;
}
With this as a basic menu
<ul>
<li>
Home|
</li>
<li>
Teams|
<!--<ul>
<li>8U</li>
<li>9U</li>
<li>10U</li>
<li>11U</li>
</ul>-->
</li>
<li>
Schedule|
</li>
<li>
Forms|
</li>
<li>
Sponsors|
</li>
<!--
<li>
News|
</li>
-->
<!--
<li>
Media|
</li>
-->
<li>
About|
</li>
<li>
Contact
</li>
<li> </li>
If I change the position in CSS to relative it will move it from where it is to the left of the image. Center position will shift the contact link over the logo. I'm guess I'm missing some extra coding in the CSS for the submenu but I've tried a few things and they don't seem to work. Any assistance in getting this functional would be great. Thanks in advance

As I mentioned in the comments, the code you've posted does not contain any styling for the dropdown menu. Here's a fiddle showing how you could go about creating a CSS-only dropdown menu based on your existing markup and styles:
http://jsfiddle.net/w3khgygb/2/
.header ul {
overflow: visible;
}
.header ul li {
position: relative;
}
/* Dropdown */
.header ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #ddd;
}
.header ul ul li {
float: none;
}
.header > ul > li:hover > ul {
display: block;
}
Please note that the top level ul on your site currently has overflow set to hidden, which will hide any dropdown menu. As you can see I have changed the overflow to visible.

Related

Navigationbar - Text in the mid (vertical)

I have to code a Website for my term paper and I really have no clue how to get my Links in the navigationbar in the middle of my box.
I already looked it up on the Internet but I didnt managed to fix it. It would be cool if someone could at least give me a hint :)
nav {
background-color: lightblue;
position: absolute;
height: 5%;
width: 100%;
top: 0%;
left: 0%;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
list-style: none;
}
nav ul li a {
text-decoration: none;
float: left;
display: table-cell;
padding-right: 30px;
color: black;
}
nav ul li a:hover {
<nav>
<ul>
<li>Home
</li>
<li>About
</li>
<li>Products
</li>
<li>Contact us
</li>
</ul>
</nav>
http://jsfiddle.net/y6L589f7/1
It would be really nice because I need it but I really dont get it.
Instead of specifying a height for the nav bar, you could remove the height and add padding to the links to give the bar it's height:
nav {
background-color:lightblue;
position:absolute;
width:100%;
top:0%; left:0%;
}
nav ul li a {
text-decoration:none;
float:left;
display:table-cell;
padding:15px 30px 15px 0;
color:black;
}
Updated Fiddle

How to do a Navigation bar

I need some help with a navigation bar! I want to make it horizontal and they're all seperate, kinda like the bit next to the stack overflow thingy, (where it says: questions, tags etc.).
I tried just doing a menu but I realised that treats it all as one, not seperate things, so I added divs and everything went askew when I altered the CSS to make sure it gets eeverything within the divs, so I reverted it back to it's original menu form.
Here's my HTML:
<!-- navigation bar for: ALL PAGES --->
<nav style="width=100%;">
<ul id="menu">
<li>Welcome</li>
<li>Review
<ul>
<li>Customer Reviews</li>
<li>Leave a Review</li>
</ul>
</li>
<li>Gallery</li>
<li>Discounts
<ul>
<li>Refer us!</li>
<li>Claim discount</li>
</ul>
</li>
<li>Send me an email!
</li>
</ul>
</nav>
<!-- end navigation bar for: ALL PAGES --->
and my CSS:
/* nav */
#menu {
margin:0 auto;
display: inline-block;
list-style-type:none;
padding:0;
}
#menu li {
float: left;
}
#menu li a {
font-family:helvetica;
display:block;
padding:10px 10px;
text-decoration:none;
}
#menu li a:hover {
}
#menu, #menu ul {
margin:0 auto;
padding: 0;
}
#menu li {
float: left;
position: relative;
list-style-type: none;
}
#menu > li:hover > ul {
display: block;
}
#menu > li > ul {
display: none;
position: absolute;
}
#menu li a {
white-space: nowrap;
}
Are you looking for this
Then use this
#menu li {
float: left;
position: relative;
list-style-type: none;
background:gray;
margin-left:10px;
margin-top:5px;
}

Css display submenu on menu item hover

I have a menu where each menu item has a background image, when hovering over a menu item it is underlined by scrolling up the corresponding background image. Now I also want to display the submenu(with text items, no background image), but the submenu text isn't diplayed , if I set the border of the submenu I can see a rectangle with no proper content. I don't see what's wrong with the code, please help me correct (and improve) it.
//html structure
<div id="menu_top">
<ul id="menu">
<li class="home">Home</li>
<li class="menu">Menu
<ul class="submenu">
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
</li>
<li class="contact">Contacts</li>
<li class="about">About</li>
</ul>
</div>
//css styles
#menu_top
{
margin: 0 auto;
text-align: center;
background: url(../images/nav-bg.jpg) no-repeat 0 0;
height: 150px;
width: 815px;
}
ul#menu
{
list-style: none;
margin: 0;
position: relative;
}
ul#menu li
{
background-position: left top;
background-repeat: no-repeat;
display: block;
text-indent: -9000px;
position: absolute;
outline: none;
}
/*Menu items*/
// all menu items similar to this ...
ul#menu li.menu
{
background-image: url(../images/nav-menu.png);
height: 50px;
width: 116px;
top: 30px;
left: 380px;
}
/* underline menu items*/
ul#menu li:hover
{
background-position: left bottom;
}
#menu >li ul
{
position:absolute;
left:0px;
top:50px;
width:100%;
}
#menu >li ul>li
{
list-style:none;
}
#menu >li:hover > ul
{
display:block;
}
The sub menu items are not being displayed because you have set a text-indent:-9000px for ul#menu li, which means the text indent will apply to all the li items under the ul #menu. To display the sub menu items apply the below styles to the submenu li
#menu >li ul>li
{
list-style:none;
text-indent:0;
position:relative; // this is set to remove position absolute set for ul#menu li
}
OR
#menu .submenu li{
position:relative;
text-indent:0;
}

drop down menu 3 level (horizontal followed by 2 verticals)

I have a menu bar. The menu bar is horizontal. The sub menu is then extended vertically upon hovering. The items in this sub menu includes Manage subjects, Manual Crawl, Crawl Interval and Archive List. When the mouse is hover to Manage subjects, it should prompt another dropdown list at the right side of it to product a sub sub menu. However, I can make this sub sub menu to appear on the right. its over lapping my sub menu. as i am really new to CSS, i definitely need help in this. i have a feeling i am not even editing
#menu ul li ul li ul, #menu ul li ul li:hover ul ,#menu ul li ul li:hover ul li and #menu ul li ul li ul li a:hover. thank you.
HTML
<div id="menu">
<ul>
<li>Home</li>
<li>Executive Summary</li>
<li><a href="#" > Visual Analytics</a></li>
<li><a href="#" >Settings</a>
<ul>
<li><a href="#" >Manage Subject</a></li>
<ul>
<li>Add Subject</li>
<li>Edit Subject</li>
<li>Delete Subject</li>
<li>Export Subject</li>
</ul>
<li>Manual Crawl</li>
<li>Crawl Interval</li>
<li>Archive List</li>
</ul>
</li>
</ul>
</div>
CSS
#menu {
position: relative;
float: left;
width: 1200px;
height: 35px;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
padding: 0;
background-color:#000;
text-align: center;
z-index:1;
}
#menu ul {
position: relative;
list-style: none;
display: inline-block;
margin: 0;
padding: 0;
}
#menu ul li {
position: relative;
float: left;
height: 100%;
padding: 0;
line-height: 35px;
}
#menu ul li a {
position: relative;
height: 100%;
width: auto;
float: left;
text-decoration: none;
padding: 0px 10px 0px 10px;
margin: 0 3px;
color: #fff;
text-align: center;
}
#menu ul li ul {
display: none;
width: 150px; /* Width to help Opera out */
background-color: rgba(0,0,0,0.5);
}
#menu ul li:hover ul {
display:block;
position: absolute;
top: 35px;
left: 0;
margin: 0;
padding: 0;
z-index: 1;
width:150px;
}
#menu li li a{
height: 35px;
width: 150px;
float: left;
text-decoration: none;
padding: 0px;
margin: 0 0px;
color: #fff;
text-align: center;
}
#menu ul li ul li a:hover{
background: rgba(255,255,255,0.5);
width:150px;
float:left;
}
#menu ul li ul li ul{ display:none; position:absolute;background-color:rgba(28,28,240,0.5);}
#menu ul li ul li:hover ul { display:block; position:absolute; top:0px;background-color:#fff;}
#menu ul li ul li:hover ul li { list-style:none; float:none; margin-left:1px; padding:0px; position:relative;background-color:#fff;}
#menu ul li ul li ul li a:hover{
background-color: rgba(28,28,240,0.5);
width:150px;
float:left;
}​
First Question
You have to wrap the submenus ul in the higher level menuitem li to make them appear correctly. Here is an easy example for the html structure.
<ul id="menu">
<li><a>mainmenu</a></li>
<li><a>mainmenu</a></li>
<li><a>mainmenu</a>
<ul>
<li><a>first level submenu</a></li>
<li><a>first level submenu</a></li>
<li><a>first level submenu</a>
<ul>
<li><a>second level submenu</a></li>
<li><a>second level submenu</a></li>
<li><a>second level submenu</a></li>
<li><a>second level submenu</a></li>
</ul>
</li>
<li><a>first level submenu</a></li>
<li><a>first level submenu</a></li>
</ul>
</li>
<li><a>mainmenu</a></li>
<li><a>mainmenu</a></li>
</ul>
Second Question
The trick for moving the second level submenus to the right was giving them the property left:150px.
#menu ul ul{
left:150px;
}
Improvements of your Stylecheet
By the way notice that you can specify all properties of a initially hidden box in css first. Then your :hover selector only needs to set the display:block rule to show the element. If it is hidden by display:none the already set background color won't be visible.
But there are other points you could improve your stylecheet, too. For example you can set properties for all submenus with the selector #menu ul (if your ul of the menu has the id menu) because they are all lists in your menu. If you want to only set something for the first level submenu you can use #menu > li > ul as it only approaches direct children. For the second level submenus use #menu ul ul.
Using these techniques your stylecheet is more abstract. My solution also works for and unlimited number of levels of submenus. You could for example implement a third level submenu only by adding the html code. The stylecheet can handle it.
Example
Here is a working fiddle of your example: http://jsfiddle.net/m8Bcb/4/
There you can see the improved source code (both html and css) and a working live demo. And with this edit the stylecheet is also commented for your understanding. I hope that helps you and you will continue learning css!
Your submenu needs to be inside of the list item of the parent menu.
Modify your HTML like so:
<ul>
<li>Home</li>
<li>Executive Summary</li>
<li><a href="#" > Visual Analytics</a></li>
<li><a href="#" >Settings</a>
<ul>
<li><a href="#" >Manage Subject</a>
<ul>
<li>Add Subject</li>
<li>Edit Subject</li>
<li>Delete Subject</li>
<li>Export Subject</li>
</ul>
</li>
<li>Manual Crawl</li>
<li>Crawl Interval</li>
<li>Archive List</li>
</ul>
</li>
</ul>
Notice that all I did was move the </li> to be after the </ul> of the submenu.
change your css like this
#menu ul li:hover > ul {
display:block;
position: absolute;
top: 35px;
left: 0;
margin: 0;
padding: 0;
z-index: 1;
width:150px;
}
when you hover li the whole ul shows, thats why you must select direct siblings.
and add
#menu ul li ul li ul {
display: none;
}
Just to add to danijar's js fiddle solution.
You may wish for all sub menus to display relative to the first list ('main menu items') however a better solution may be to display lists or 'sub menus' relative to their parent list item.
/* ensure each submenu displays relative to it's parent list item */
#menu ul li {
position: relative;
}
Here is an example of a menu that you may want to add the above line of styling for:
http://jsfiddle.net/codk1sgm/5/

CSS 3 Gradient Confines Nested List to Parent UL

I have a horizontal unordered list which I'm using as a main menu, with a nested unorderd list which I'm using as a dropdown sub menu.
I'm using a CSS 3 Gradient on the Main Menu but it is causing the sub menu to be confined to the list in IE. What I mean is, if I increase the height of the list items I can see part of the sub menu but this obviously ins't an option.
I have heard about someone encountering this problem before and was wondering if anyone could help.
This is the HTML of the menu.
<div id="menu">
<div class="mainmenu">
<ul>
<li>
<a href='path'>Home</a>
</li>
<li>
<a href='path'>Country Garden</a>
</li>
<li>
<a href='path'>Inner City Garden</a>
</li>
<li>
<a href='path'>Winter Garden</a>
<ul>
<li>
<a href='path'>Featured Products</a>
</li>
<li>
<a href='path'>Best Sellers</a>
</li>
<li>
<a href='path'>Special Offers</a>
</li>
</ul>
</li>
<li>
<a href='path'>Water Garden</a>
</li>
<li>
<a href='path'>Window Box</a>
</li>
</ul>
</div>
</div>
This is the CSS that controls it.
.mainmenu{
clear: both;
height: 42px;
margin: 0;
width: 980px;
}
.mainmenu ul{
list-style: none;
margin: 0;
padding: 0;
text-align:center;
}
.mainmenu li{
display: inline-block;
margin: 0;
padding: 0;
z-index:1000;
height: 42px;
position: relative;
}
.mainmenu li a{
display: inline-block;
height: 33px;
padding: 9px 25px 0;
}
.mainmenu ul ul{
float: left;
left: 0;
padding: 5px 0 10px 0;
position: absolute;
text-align: left;
top: 42px;
width: 200px;
z-index: 10000;
}
.mainmenu li li{
clear: both;
text-align: left;
height: 30px;
}
.mainmenu ul li ul{
display:none;
}
.mainmenu li ul li a {
height: auto;
padding: 2px 25px;
width: 150px;
}
.mainmenu li ul li a, .mainmenu li.over li a {
text-decoration: none !important;
}
.mainmenu li:hover ul, .mainmenu li.over ul {
display: block;
}
This is style that causes the problem in IE8.
.mainmenu li{
background-color: #25abec;
background-image:-moz-linear-gradient(top,#25abec,#1984b8);
background-image:-webkit-gradient(linear,left top,left bottom,from(#25abec),to(#1984b8));
filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#25abec,endColorStr=#1984b8);
}
It's the final line that causes the problem. If I take it out it works but looks wrong. The problem is in IE and Opera but it works in Firefox, Google Chrome and Safari.
The IE filter can indeed cause various issues at times. My recommendation is to not put the filter on at all, letting IE8 just have the plain default background-color, and then perhaps using SVG to get the background for IE9.