Submenu not appearing vertical - css

I've been fighting with this for probably 6 hours now and am completely stumped. I can't get the submenu to appear vertical on mouse hover. Here's the link from cssdesk. What am I messing up? I know it's something really simple.
http://www.cssdesk.com/n8WCm
If the link doesn't work for you, please see this snippet:
.nav8 ul .sub-menu{
position:absolute;
display:none;
}
.nav8 li:hover ul.sub-menu {
display: block;
background:#000;
border: 1px solid #ececec;
}
If there is more that you need, please let me know.

Add To your Css
.nav8 ul li li{
clear:both;
}
.nav8 ul li ul{
width:20% !important;
}

you should make it not floated left like the main menu, so i would suggest to clear it after every submenu li and give it a fixed width
.nav8 li:hover ul.sub-menu li {
clear:both;
width: 200px;
}

Related

Keeping dropdown menu active (visible) even after hover out

My sub menu disappears immediately after I move my mouse pointer to scroll towards the sub menu. Feel like I have screwed my CSS somewhere. I could not figure out after several attempts to make it stay active. I followed few tutorials(have a look at it) where they have called the hover on the ul instead of a(anchor), I tried similar ways but could not achieve what I want. Please point out where I have made the mistake. Here is my fiddle(my code). Sample CSS code for hover is below.
#topnav ul li ul
{
display: none;
position: absolute;
text-align: left;
background:#510000;
top:30px;
}
#topnav ul li:hover ul
{
display: block;
}
Put the padding on your list items instead of your ul or container. That way the dropdown overlaps your hover element and your browser never thinks that you hovered out of the element. See this:
#topnav li {
display:inline-block;
padding:10px 0;
margin-right:30px;
position: relative;
}
http://jsfiddle.net/jeffreyTang/q5cmqLrf/1/
You can also give
#topnav ul li ul {
padding-top:30px
}
instead of:
#topnav ul li ul {
top:30px
}
The problem is with your padding being at the nav level and you trying to make the drop down appear below it. Because you position your dropdown away from the parent li, you're no longer hovering over it when you move your mouse down. To fix, remove the padding from the nav and add it to the li.
remove padding from here:
#topnav{
display:block;
clear:both;
width:500px;
margin:0;
padding:0;
text-align:center;
}
add to here:
#topnav li{
display:inline-block;
padding: 15px 0 15px 5px;
margin-right:30px;
position: relative;
}
remove top from here:
#topnav ul li ul {
display: none;
position: absolute;
text-align: left;
background:#510000;
}
fiddle: http://jsfiddle.net/zj8krh95/7/
Here's a way to do it (it's more of a trick):
http://jsfiddle.net/zj8krh95/5/
#topnav ul li:hover {
padding-bottom: 10px;
margin-bottom: -10px; /* so that the menubar's height stays the same */
}
#topnav ul li:hover ul {
margin-top: -10px; /* so that the menu opens at the right position */
}
Basically, on hover, i extend the menu item's height so that no mouseout is trigger when i move down to the menu.

Hover query - NAV bar CSS effecting DIV class

The following CSS code creates a NAV bar with some sample boxes within a container.
I was having problems with the Hover staying on so with some advice from here I included the extra code (second block of code down)
.dropdown>ul>li>a:hover {margin-bottom:20px;}
This extra code worked well
However it has had a side effect on my DIV boxleft in that in wont stay left - as I move the mouse across the NAV bar it moves with it......... I just want to keep DIV boxleft on the left hand side. Can you help? Many thanks.
/* Navigation Style */
.dropdown { position:relative; font-family: arial, sans-serif; width:100%; height:40px; border:1px solid #666666; font-size:14px; color:#ffffff; background:#333333; z-index:2; }
/* Basic List Styling (First/Base Level) */
.dropdown ul {padding:0; margin:0; list-style: none;}
.dropdown ul li {float:left; position:relative;}
.dropdown ul li a { border-right:1px solid #666666; padding:12px 8px 12px 8px; display:block; text-decoration:none; color:#000; text-align:center; color:#fff;}
.dropdown>ul>li>a:hover {margin-bottom:20px;}
.dropdown ul li a:hover {color:#ffffff; background:#232323;}
/* Second Level Drop Down Menu */
.dropdown ul li ul {display: none;}
.dropdown ul li:hover ul { font-size:13px; display:block; position:absolute; top:41px; min-width:150px; left:0;}
.dropdown ul li:hover ul li a {display:block; background:#000; color:#ffffff; width:170px; }
.dropdown ul li:hover ul li a:hover {background:#666666; color:#ffffff;}
/* Third Level Drop Down Menu */
.dropdown ul li:hover ul li ul {display: none;}
.dropdown ul li:hover ul li:hover ul { display:block; position:absolute; left:145px; top:0; }
#container {
overflow:hidden;
background-color:yellow;
width:1250px;
padding 10px 10px 10px 10px;
border:1px solid #666666;
margin: 0 auto;
}
.boxleft {
float:left;
background-color:blue;
margin-top:30px;
margin-bottom:10px;
margin-left:10px;
margin-right:10px;
width:600px;
border:1px solid #666666;
z-index:1;
}
EDIT
Fiddle here : - http://jsfiddle.net/LUzNm/
Rather than address this band-aid fix, let's address the root problem!
To begin, you don't need that margin-bottom: 20px thing. That was never the cause of your initial problem. Rather, it was due to the fact that your .dropdown bar is 40px in height, but your actual dropdowns are absolutely positioned at 41px from the top. If the browser registers a mouse event while the mouse is over that 1px gap, the dropdown will close.
Now, it seems like you want that 41px so a border: 1px solid #666666 on your .dropdown bar will appear. We can do that still, but we'll just be adding that border to your hover menu.
And finally, let's get some best practices going. Padding can be useful, but padding for this use case sucks. Its far easier and more accurate to instead use line-height to achieve the height and spacing in our <a> tags rather than padding, and it allows us to do away with the extra padding-top and padding-bottom declarations on your site title! By setting line-height to 40px, we immediately match the height of the .dropdown bar at all times (and if you're using something like LESS or SASS, it becomes a great variable to reuse).
With all that being said, here's the updated fiddle: http://jsfiddle.net/2r5Mz/
One more thing that I would also recommend doing is moving the entire .dropdown container out of #container. The reason for this is #container has overflow: hidden set, which can mean chopping off your dropdown if the content isn't of sufficient height. Simply moving this .dropdown out of that div solves the issue.

ie7 dropdown menu(list)

Helo!
Dropdown in IE7 displayed not correct. When I put mouse over it's appears like inline block and it's too far to the right. When I put mouse over first element in ul, second one disappears. And near each element is weird angle, which is angle of that menu which appears after I put mouse over.
any help or advice will be appreciated!
http://jsfiddle.net/an4Ng/
My code is:
nav ul {
padding:0;
margin-right:15%;
margin-left:15%;
float:left;
position:absolute;
}
nav ul li{
float:left;
position:relative;
overflow:hidden;
z-index:200!important;
padding:5px 35px;
margin-top:5px;
display:block;
}
nav ul li a{
text-decoration:none;
font-family: BebasNeueRegular, Arial,calibri;
font-size:x-large;
color:#eee;
}
nav ul li:hover{
overflow:visible;
position:static;
}
nav ul li ul{
width: auto; height: auto;
display:block;
position:absolute;
border:3px solid gray;
background-color: black;
}
nav ul li ul li a{
text-decoration:none;
font-size:large;
margin-top:15px;
}
nav ul li ul li a:hover{
text-decoration:underline;
color:#caf9ff;
}
I just threw this together but how's this?
http://jsfiddle.net/PgVQC/3/
Obviously I haven't tested it in IE7 but it's how I tend to do my dropdown menus.
You might have to throw in a bit of jquery to get the menu to display in IE7, here's an example from a site I built a few weeks ago.
http://jsfiddle.net/9L4EC/2/

Navigation border and background not working for a template?

My following code is not working.Means border and background color is not working
#navigation ul
{
background-color: #85A157;
border:3px solid white;
}
here is my fiddle http://tinkerbin.com/ooJNXsdD
i want like this
please help in correcting my fiddle.
try setting a height on the element like so:
#navigation ul
{
background-color: #85A157;
border:3px solid white;
height: 20px;/*added height*/
}
i hope this helps. i added the change to tinkerbin, not sure if it took :)
Use overflow: hidden on your <ul>, like this : http://tinkerbin.com/AMBfS3MY
After testing this on your Tinkerbin, this worked for me. You need a clearfix. In your CSS:
.clear {
clear: both;
}
Then in your HTML:
<ul>
...
<li class="clear"></li>
</ul>
And if you want the navigation bar to flush against the top image, add the following margin-top in your CSS:
#navigation ul
{
margin-top: 0;
...
}
I have just updated your fiddle, I hope you can see where your problems where.
http://tinkerbin.com/g63CbYYZ
For example:
ul has usually a margin. So you need to reset it.
Better define styles on div not on ul.
And a lot more...
This should do it for you.
#navigation ul
{
background-color: #85A157;
border:3px solid white;
margin:0px;
height:22px;
}
#navigation ul li
{
list-style:none;
float:left;
}
#navigation ul li a
{
color:white;
text-decoration:none;
margin:0px 37px 0px 0px;
}

Complex css menu

I have a menu:
<div class="headerMenu">
<ul>
<li>Home <span>Home Page<span></li>
<li>About <span>About My Website<span></li>
<li>Contact <span>Get in touch<span></a></li>
</ul>
</div>
My current CSS is as follow:
.headerMenu{
width: 100%;
}
.headerMenu ul{
margin: 0;
padding: 0;
float: left;
}
.headerMenu ul li{
display: inline;
}
.headerMenu ul li a{
float: left;
color: white;
padding-top:25px;
padding-left:50px;
font-size:24pt;
}
.headerMenu ul li a:visited{
color: white;
}
.headerMenu ul li a:hover, .menu ul li .current{
color: #fff;
background: url(../../Content/Images/menu-selector.png) repeat-x; /* 25x10 arrow/*
}
And now for the question:
How can i get the content in the span tag to be below the Main text.
When i hover over the anchor, How do i add the hover image as shown in screen shot
The Mockup i created in Photoshop looks like this:
I know this would be easily achievable by making use of images, but my solution requires that menu to be created dynamically.
1) How can i get the content in the span tag to be below the Main text.
You need to use display: block on the span to have it appear on a new line:
.headerMenu ul li a span {
display: block;
}
2) When i hover over the anchor, How do i add the hover image as shown in screen shot
Try to center the arrow to the top. This might work:
.headerMenu ul li a:hover, .menu ul li .current {
color: #fff;
background: url(../../Content/Images/menu-selector.png) no-repeat center top;
display:block;
/* also make sure that you use display block with correct height
so that you can positionate the arrow on the correct place... */
}
Add the following code for problem 1:
.headerMenu ul li a span {
display: block;
}
This sets the <span> to display as a block level element, therefore occupying the full parent container width by default.
For problem 2, there are multiple ways to do this. However, my suggestion would be to add the array to the <li> and use the :hover pseudo class. Note: that this will only work in IE for 7+.
.menu ul li:hover{
background: url(../../Content/Images/menu-selector.png) repeat-x;
}
See it in action - http://jsfiddle.net/kxqx8/1/ (I changed the colors to help display)

Resources