Hi Please help me on this issue.
Issue: dropdown values of the menu is shown in other menu (it is not in-line with menu).
Example: Dropdown values of Home menu is Home-1, Home-2, Home-3 and it will shown under National parties menu. How can I show appropriately under the right menu
Demo: http://jsfiddle.net/shrikanth/Sv79m/
<div id="menu">
<ul>
< li>Home<ul>
<li>Home-1</li>
<li>Home-2</li>
<li>Home-3</li>
</ul></li>
<li ><a href="aboutus.html">National Parties<ul>
<li>BJP</li>
<li>Congress</li>
<li>CPM</li>
</ul></a></li>
<li><a href="services.html">Services<ul>
<li>TV</li>
<li>Cell</li>
<li>Radio</li>
</ul></a></li>
<li>Contact Us
<ul>
<li>India</li>
<li>USA</li>
<li>SAUS</li>
</ul>
</li>
</ul>
</div>
CSS
#menu {
width: 550px;
height: 35px;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-align: center;
text-shadow: 1px 2px 1px #333333;
background-color: #8AD9FF;
border-radius: 8px;
}
#menu ul {
height: auto;
padding: 8px 0px;
margin: 0px;
}
#menu li {
display: inline;
padding: 20px;
}
#menu ul li a {
text-decoration: none;
color: #00F;
padding: 8px 8px 8px 8px;
}
#menu a:hover {
color: #F90;
background-color: #FFF;
}
#menu ul li ul{
display:none;
position:absolute;
top:31px;
background-color:red;
}
#menu ul li:hover ul{
display:inline-block;
height:auto;
width:135px;
}
#menu ul li ul:before{
content: '';
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 10px; /* The border on the drop down box */
position: absolute;
top: -20px;
left: 37%;
margin-left:10px;
}
http://jsfiddle.net/Sv79m/1/
Give #menu li a position of relative:
#menu li {
display: inline;
padding: 20px;
position:relative;
}
Adjust a little the absolute positioning with left:0 :
#menu ul li ul{
display:none;
position:absolute;
top:51px;
background-color:red;
left:0;
}
Edit:
Also, to solve the overlapping links, add this:
#menu ul li ul li{
display:block;
padding:5px;
}
http://jsfiddle.net/Sv79m/2/
Also, you had some unclosed tags, I closed them and now it's much better:
http://jsfiddle.net/Sv79m/3/
<a href="aboutus.html">National Parties<ul>
^^CLOSE ME!
It's all down to the positioning of the containing element. If you use position: relative; it allows you to position elements absolutely inside of it.
Here's a tutorial on creating a dropdown navigation, it explains about the positioning and structure. This should help - CSS 3 navigation menu
Related
So I'm, attempting to create a drop down menu on my website and for the most part have been successful, however I'm having one issue.
<div id="nav">
<ul>
<li>content</li>
<li>
content
<ul>
<li>subcontent</li>
<li>subcontent</li>
<li>subcontent</li>
</ul>
</li>
<li>content</li>
<li>content</li>
</ul>
</div>
Above is the content
body{
margin: 0px;
}
ul, li{
margin: 0px;
padding: 0px;
}
#nav{
width: 100%;
background-color: #000000;
color: #ff0000;
}
#nav ul{
position: absolute;
list-style-type: none;
text-align: center;
cursor: pointer;
}
#nav ul li{
min-width: 100px;
display: inline-block;
border: 1px solid #000000;
}
#nav ul li:hover{
background-color: #0000ff;
}
#nav ul li ul li{
display: none;
margin-left: -1px;
margin-top: -1px;
}
#nav ul li:hover ul li{
display: block;
}
And that is the CSS
Basically, because I'm positioning my content as 'absolute' in order to stop anything from being misplaced when the dropout menu is used, the layer black layer which acts as the navigation bar section ends up disappearing. Is there any way around this, or do I need to restructure my website completely?
This is what is looks like in a browser:
Try adding background-color to ul, li
ul, li{
margin: 0px;
padding: 0px;
background-color: #000;
}
or give #nav a height
#nav{
width: 100%;
background-color: #000000;
color: #ff0000;
height: 50px;
}
Never mind, I realized it was because I hadn't set a height in #nav.
I have a dropdown list item in my navbar and can't get the dropdown section to align underneath the parent link. I am trying to use just css and know I've done it before, it's just stumping me at the moment. None of the other examples I've come across use the same menu format so it's been troubling trying to force fit pieces of code. Please help me with this easy solution
HTML
<div id="navbar">
<li>Home</li><!--
--><li>Link2</li><!--
--><li>Link3</li><!--
--><li><a href="#">Link4
<ul>
<li>SubLink1</li><br />
<li>SubLink2</li><br />
<li>SubLink3</li><br />
<li>SubLink4</li>
</ul>
</a></li><!--
--><li>Link5</li>
</div>
CSS
#navbar {
width:75%;
margin:0px auto;
text-align:right;
position:relative;
top:218px;
}
#navbar li {
list-style:none;
display:inline;
position:relative;
}
#navbar a {
background-color:#862D59;
font-size:18px;
width:60px;
margin:0px;
padding:10px 15px;
color:#FFF;
text-decoration:none;
text-align:center;
}
#navbar a:hover {
background-color:#602040;
border-bottom:solid 4px #969;
}
#navbar li ul {
display:none;
}
#navbar li:hover ul {
position:absolute;
display:block;
}
Working Example
https://jsfiddle.net/o6Ldutp5/
Firstly, you should use a reset css of some kind to remove the default margin / padding attached to ul & li.
Then validate your HTML, it contained a number of errors such as missing the opening ul etc.
Then it's just a matter of using position:absolute and appropriate values.
top:100% will place the menu directly below the li parent (with position:relative) regardless of the height of the li.
left:0 will align the left edge of the submenu to the left side of the parent li.
#navbar {
margin: 0px auto;
text-align: right;
}
ul,
li {
margin: 0;
padding: 0;
}
#navbar li {
list-style: none;
display: inline-block;
position: relative;
}
#navbar a {
background-color: #862D59;
font-size: 18px;
width: 60px;
margin: 0px;
padding: 10px 15px;
color: #FFF;
text-decoration: none;
text-align: center;
display: block;
}
#navbar a:hover {
background-color: #602040;
border-bottom: solid 4px #969;
}
#navbar li ul {
display: none;
position: absolute;
top: 100%;
left: 0;
}
#navbar li:hover ul {
display: block;
}
<div id="navbar">
<ul>
<li>Home
</li>
<li>Link2
</li>
<li>Link3
</li>
<li>Link4
<ul>
<li>SubLink1
</li>
<li>SubLink2
</li>
<li>SubLink3
</li>
<li>SubLink4
</li>
</ul>
</li>
<li>Link5
</li>
</ul>
</div>
I've written my own minimal CSS without the styling, try replacing your whole CSS with this -
I've also edited your HTML by removing the comments and <br /> tags
div#navbar li {
display: inline-block;
}
div#navbar li ul {
width: 200px;
position: absolute;
display: none;
top: 10px;
}
div#navbar li ul li {
display: block;
width: 150px;
}
div#navbar li:hover ul {
display: block;
}
ul,ol,li {
margin-left: 0;
padding-left: 0;
}
Here is the fiddle
I cannot get the drop down aspect of this menu to show- I'm sure this is an easy fix- I just do not see it. The menu itself is nothing fancy, no sub-menu- just simple drop options are needed. I have checked out several tutorials and they are all different, so if I can get help in adjusting the work I have already done this would be the best scenario. Thanks for any help in advance!
#headernav {
float: right;
width: 555px;
padding: 0px;
text-align:center;
margin:0;
list-style-type:none;
}
#headernav li {
float:left;
}
#headernav li a {
display: block;
text-decoration: none;
width:6em;
height:35px;
text-decoration:none;
color:#161616;
background:url(../images/linkbg2.png);
background-repeat:no-repeat;
padding:0.2em 0.6em;
padding-top:20px;
margin-left:3px;
font-size:14px;
letter-spacing:1px;
font-weight:500;
}
#headernav li a:hover {
text-decoration: none;
height:35px;
color: #161616;
position: relative;
width: 6em;
text-align: center;
padding:0.2em 0.6em;
display: inline;
float:left;
padding-top:20px;
margin-left:3px;
cursor:pointer;
}
#headernav li ul {
display:none;
}
#headernav li hover:ul {
display:block;
position:absolute;
width:150px;
background:#03C;
list-style:none;
}
#headernav ul li {
float: none;
}
#headernav ul li a {
display: block;
border-top: 1px solid #666;
}
HTML:
<ul id="headernav">
<li>Donate</li>
<li>Answers</li>
<li><a style="width:8.5em;" href="news.html">News & Events</a></li>
<li>About Us
<ul>
<li>Mission</li>
</ul>
</li>
<li>Contact</li>
</ul>
I think you meant to write
#headernav li:hover ul {
instead of #headernav li hover:ul {
Also you should probably add something like top: 60px; to this class.
A pretty simple way to add an arrow would be:
#headernav li {
float:left;
position:relative; <-- add this
}
then add this class to your css
#headernav li a.hasdropdown:after {
content: " ";
width: 0px;
height: 0px;
border-style: solid;
border-width: 7px 6px 0 6px;
border-color: #000000 transparent transparent transparent;
position:absolute;
left: 90px;
top: 24px;
}
Add the "hasdropdown" class to every Anchor-Tag that should display an arrow:
<li>About Us
Hope this helps a bit.
Here's the link to the page:
http://themes.brixwork.com/altamont/
The positioning of the tags under the ul#menu appears to be skewed on IE7. I have put borders on the UL (#f00) and LI (#0f0) items to clarify.
IN Firefox, the LI items nest properly to the top of the UL, however on IE the LI nests to the top of the div#menubar rather than the ul#menu under it.
The DOM tree is like this:
<div id="menubar" class="grid_16 alpha omega">
<ul id="menu">
<li style="margin-left:0px;">home</li>
<li>about me</li>
<li>featured listings
<ul class="submenu">
<li>
on a map
</li>
</ul>
</li>
<li>
MLS® search
</li>
<li>
resources
<ul class="submenu">
<li>
for buyers
</li>
<li>
for sellers
</li>
<li>
pre-sale / assignment
</li>
<li>
useful links
</li>
</ul>
</li>
<li>
blog
</li>
<li>
contact me
</li>
</ul>
</div>
Pretty standard div>ul>li menu structure, with optional submenus under each as a ul.submenu>li structure.
I tried putting a "float:left;" to the #menu li node, and that did solve the positioning; however then I don't have a nice centre aligned menu - everything goes to the left on the menu.
Here's the current css revolving around this (note that I'm using 960 grid, and also the reset.css and text.css file that comes with it).
#menubar {
height:40px;
text-align: center;
}
#menu {
margin:10px auto;
padding:0px;
z-index: 20;
width: auto;
display: block;
list-style:none;
white-space: nowrap;
position: relative;
border: 1px solid #f00;
}
#menu li {
display:inline;
margin-left:40px;
margin-right:0px;
margin-top:10px;
margin-bottom:0px;
padding:0px 0px 0px 0px;
list-style:none;
z-index: 25;
position: relative !important;
border: 1px solid #0f0;
}
#menu li a:link, #menu li a:visited {
color:#fff;
text-decoration:none;
font-size:12px;
padding: 10px 0px;
text-transform: uppercase;
}
#menu li a:hover {
color:#ddd;
}
#menu li a:active {
position:relative;
top:1px;
color:#fff;
}
.submenu {
position:absolute;
left: -9999px;
display: block;
background-color:#906117;
padding:0px 0px 0px 0px;
top:0px;
z-index:30;
}
#menu li:hover .submenu {
left: 0px;
}
.submenu li {
text-align: left !important;
margin:0px !important;
padding: 3px 0px 5px 0px !important;
clear: both;
float: left;
position:relative;
overflow: hidden;
z-index: 35;
width: 100% !important;
}
.submenu li:hover {
background-color: #f79c10;
}
.submenu li a:link, .submenu li a:visited {
color:#fff !important;
font-size:12px !important;
padding: 0px !important;
margin: 0px !important;
white-space:nowrap;
display: block;
width: 100%;
padding:3px 10px 5px 10px !important;
z-index: 40;
}
.submenu li a:hover, .submenu li a:active {
color:#fff !important;
}
IE7 ignores margins when ul elements have a relative position. You can fix this by removing the margin in your ul#menu styles and add that value back in the parent div#menubar.
This will give you the same layout result, but will resolve the IE7 margin/relative bug.
So i have an issue with a CSS dropdown menu being displayed wrong in IE. In other browsers it works like it should.
<body>
<div id="container">
<header>
<div id="hlogo">
title
</div>
<nav id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</nav>
</header>
<section id="container-body">
<div id="content">
</div>
</section>
</div>
So this is my complete HTML. It has a layout provided by the following css.
/* layout styles */
*{margin:0;padding:0;font-family:Arial;}
header{overflow:hidden;}
body{background-color:#cc3333;}
a {display: inline-block;font-weight: bold;text-decoration:none;}
footer {
display:block;
position:relative;
width:100%;
}
footer > #disclamer {
margin-left: auto;
margin-right: auto;
width: 200px;
padding-bottom:5px;
font-size:small;
font-weight: bold;
}
#container{
background-color:#ffffff;
margin:auto;
min-width:756px;
width:60%;
overflow:hidden;
border:solid 2px #666666;
margin-top:10px;
margin-bottom:10px;
box-shadow:0 1px 3px rgba(0,0,0,0.6);
}
#hlogo {float:left;height:105px;width:181px;padding:10px;}
#hlogo a{background-position: 0px 0px;float:left;display:inline;height:105px;text-indent:-999999em;width:181px;}
#hlogo a{background-image:url('../images/logo.png');background-repeat:no-repeat;overflow:hidden;}
#hmenu{margin-top:45px;padding:10px;}
nav {
list-style:none;
display:inline;
float:right;
}
nav ul{
list-style: none;
text-align:center;
background-color:#666666;
float:left;
}
nav ul li {
width:128px;
float:left;
display:inline-block;
}
nav ul li:hover{
background-color:#cc3333;
cursor:pointer;
}
nav ul li a {
color:#ffffff;
padding:10px;
}
nav ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer
}
section {margin:10px;}
#container > header {display:block;}
#container-body {
background-color:#ececec;
height:600px;
display:block;
overflow:auto;
}
#container-body > #content {
margin: 10px;
height:95%;
position:relative;
}
.hiddenMenu
{
position:absolute;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer;
width: inherit;
}
.hiddenMenu > a
{
position:relative;
text-align: left;
clear:both;
font-size:0.75em;
}
nav li .hiddenMenu > a
{
display:none;
}
/*nav li:hover .hiddenMenu > a
{
display:block;
}*/
nav li .hiddenMenu > a:hover
{
background-color:#cc3333;
cursor:pointer;
border: 1px black solid;
}
This is the full CSS.
This is the CSS i use. Now in firefox it works as it should. The menu is show when i hover the menu2 item. On IE it shows the first submenu item (submenu1) and then it is cleared so i can't even click it.
I can't see what i'm doing wrong so if you can help me i would appreciate it. Thanks!
edit: added code.
The header tag has an overflow:hidden attribute; if i set that to visible it will show the complete menu but will mess up my layout completely. Is there a way around it or am i doing something wrong?
Also, i have a jquery script to set the display on the menu to none/block accordingly but in IE if i hover on the submenu items the menu will still be hidden. Why does this happen?
In my experience IE gets a bit buggy when you don't set the positions of an absolute positioned object. Like top: 0 and left: 0 for instance.
Edit:
Also, parent of the absolute positioned object should have position: relative; if the position should be using the parent dimensions as a starting point.
Edit2:
li:hover doesn't work in IE6 I think. Can't remember about IE7. One of them will only accept a:hover, and browsers below maybe none of them. jQuery solves things like that though.
Edit3:
I don't know what the nav stuff is, I haven't jumped to HTML5 so I don't know if it's relevant later. But anyway I've made something that works of your code.
Script (jquery):
$(document).ready(function () {
$('#hmenu ul li').hover(function () {
$(this).children('div').css('display', 'block');
},
function () {
$(this).children('div').css('display', 'none');
});
});
CSS:
#hmenu {
list-style: none;
display: inline;
float: right;
}
#hmenu ul {
list-style: none;
text-align: center;
background-color: #666666;
float: left;
}
#hmenu ul li {
width: 128px;
float: left;
position: relative;
display: inline-block;
}
#hmenu ul li:hover {
background-color: #cc3333;
cursor: pointer;
}
#hmenu ul li a {
color: #ffffff;
padding: 10px;
}
#hmenu ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer
}
.hiddenMenu {
display: none;
position: absolute;
top: 60;
left: 0;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
width: inherit;
}
(sorry for the formatting, bit new to this, but you can apply source formatting in your editor I guess. I changed the navs to have the id and changed the HTML nav to be div. That's it.
HTML:
<div id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</div>
You cannot have a tag named nav change it to div and try again.