I'm looking to make a horizontal drop down menu much like the main menu from HowStuffWorks: http://home.howstuffworks.com/community-living
Notice how the submenu covers the full width of the horizontal main menu bar, rather than dropping down in vertical lists. And how the currently selected main menu item and sub menu items are highlighted. I would like those features, with the added bonus of showing the other sub menu lists when hovering over the other main menu items, please look at examples below:
Basically I want to combine the effect of showing different submenu lists as you hover over the links as in this one:
http://jsfiddle.net/SKNYC/
And also having the currently selected menu highlighted in a different colour, as in this one:
http://jsfiddle.net/pRT6S/
.full-width {
width: 100%;
}
.normal-width {
width: 1024px;
margin: 0 auto 0 auto;
}
.main-menu > li {
float:left;
list-style-type:none;
padding-right:30px;
}
.sub-menu {
display:none;
}
.sub-menu li {
float:left;
padding-right:30px;
}
.sub-menu li:hover ul {
float:left;
padding-right:30px;
background-color:green;
}
.main-menu li.active {
background-color:blue;
}
.main-menu > li.active .sub-menu {
display:block;
position:absolute;
left:0;
right:0;
background-color:blue;
}
Note that I'm very new to CSS/HTML, it would be nice to get some direction as to how to proceed. :)
The first jfiddle is modified from this code:
https://gist.github.com/jgoyon/3993263
The second and third jfiddle comes from someone's code in this thread:
CSS full-page-width horizontal menu and horizontal submenu
EDIT:
Another code that I spotted that is very similar to my solution is this one:
http://jsfiddle.net/U65eT/
but I'm not sure why when the hover over item1 and item2 doesn't work?
EDIT:
Current revision
http://jsfiddle.net/pRT6S/4/
It is almost correct, just has the problem of not showing the submenu when hovering over item1
How's this? Check the comments I made.
http://jsfiddle.net/pRT6S/3/
The main problem was needing to modify .main-menu, not .sub-menu, as seen below:
/*Not doing this right*/
.main-menu li:hover ul { /* This needs to be .main-menu, not .sub-menu! */
display: block;
/* float:left; */
position: absolute; /* better than float in this case */
padding-right:30px;
background-color:green;
left: 0; /* make sure everything hangs on the left */
}
Update: You can use the code you originally provided (that I wrongfully commented out), but modify it a bit my adding absolute positioning and z-indexes:
http://jsfiddle.net/pRT6S/5/
Related
I found an issue with .sub_menu code left:-; and transform:translateX(-%);,So I changed position to relative and re-positioned with the two codes above, It seemed to work but now the two sub menus i have are no longer Side-By-Side. What they do is separate by a few centimeters top:, Not sure what made this happen, Any help would be appreciated,Thanks
JSFiddle sub menu pops up when you hover over Gallery
.sub_menu {
display: none;
position:relative;
top:-60%;
left:-350%;
transform:translateX(-40%);
width: auto;
}
.sub_menu > li {
display:inline-block;
}
.sub_menu li a {
background:-webkit-linear-gradient(#77047e,#FF00FF);
background:-o-linear-gradient(#77047e,#FF00FF);
background:-moz-linear-gradient(#77047e,#FF00FF);
background:linear-gradient(#77047e,#FF00FF);
}
.sub_menu li a:hover {
background:#FF00FF;
top:1em;
}
From what I understand at taking a quick look is the sub.menus are odd. They currently have the style position: absolute, and that would make them all align in the same exact place. As you can see you are doing that here:
.sub_menu {
display:none;
position:absolute;
top:-37%;
left:-47%;
transform:translateX(-20%);
width:auto;
white-space:nowrap;
}
So instead a fix would most likely be using position: relative, and then aligning them from there. Also when working with a sub menu, it would help to have an ID on each element to align it correctly (Especially when aligning them vertically and horizontally).
I have this CSS Menu:
http://jsfiddle.net/73GrF/
but i cannot work out what css code i need for the hover:
#nav li a:hover
trigger the hover on your li element. Don't forget to set your submenu position to absolute
#nav li:hover ul {
display:block;
}
http://jsfiddle.net/73GrF/4/ (edited fiddle with crude dropdown styling. ill leave the dressing up to you.)
http://jsfiddle.net/73GrF/5/ is what I came up with while McMastermind was at work.
The main thing I've done is taken the margins off, floated the menu headers, and made the submenus appear on hover
#nav>li {
float:left
}
#nav li:hover ul {
position:absolute;
display:block;
}
#nav li a {
margin:0;
}
Ok, i am gonna try to explain this as well as i can. I want to have a dropdown menu and when you hovering over the sub item of the menu item, I want ONLY that menu item to be a different colour but the sub menu items should stay the same.
Using the li:hover method, makes both the sub menu and the menu item change to that color. Is there any way to only change the top menu item when the sub menu is being hovered over?
Thanks in advance
EDIT:
here is my current CSS
.dropdown-horizontal-container
{
padding-bottom: 0 !important;
margin-bottom: 0 !important;
}
ul.dropdown li ul li
{
border-bottom: #FFF 1px solid;
}
ul.dropdown li
{
position: relative !important;
display: block !important;
}
ul.dropdown li a
{
position: relative !important;
display: block !important;
padding: 10px 15px !important;
}
ul.dropdown li a:hover
{
color:#428bca !important;
}
PS: this is overwriting the css generated by a wordpress plugin. Not quite sure how to post the code it generates...if it helps the plugin is http://wordpress.org/plugins/dropdown-menu-widget/
How about:
ul.dropdown:hover {
background-color:#fff;
}
ul.dropdown li:hover {
background-color:#3e3e3e;
display:block;
}
Since i was short on time, I took the easy way out and removed the background for the hover so i didnt need to change the link color when hovering over the sub menu items. I am going to look into Jquery as some people suggested later on though to see if i cna get it working.
Here is my current jsfiddle for the navigation bar.
http://jsfiddle.net/EPh6j/28/
Please stretch the bar so it is a single line otherwise you will get mixed results.
The problem only occurs in ie9 as far as I know. What happens is when you hover over one of the main links the drop down comes down. However, as soon as the drop down passes the bottom of the main menu it turns invisible. What is even more confusing is that the ul border for the submenu shows but not the elements.
Here is an example of what I mean:
Notice how it is visible and then disappears past the bottom.
http://i.imgur.com/jXsoE.png
I did the above when I was trying to figure out my problem to start. In the jsfiddle, it moves all the way down as it should and is thus completely blank.
I'm completely stumped on getting this one to work.
My CSS:
.menu li li {
float:none;
position: relative;
}
.menu li ul {
left:0;
position:absolute;
top:0;
visibility:hidden;
}
.menu li:hover > ul {
top:100%;
visibility:visible ;
}
Suggestions?
I suspected a z-index issue, so I stripped them all from your fiddle. Seems to have fixed it.
BTW, "sponsorships". ;-)
I'm following this tutorial and am trying to modify it to my use: http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-butt-css3-mega-drop-down-menu/...
If I make the dropdown div to be the same full width as the horizontal menu bar, how do I make sure it's aligned with the menu bar?
I have found that I can change the left declaration in the following CSS rules to get the dropdown to align with the menu bar.
#menu li:hover .dropdown_1column,
#menu li:hover .dropdown_2columns,
#menu li:hover .dropdown_3columns,
#menu li:hover .dropdown_4columns,
#menu li:hover .dropdown_5columns {
left:-1px; /* <-- change this to left: -150px (or whatever value will get it to align) */
top:auto;
}
But this doesn't seem like the best way for me to do this as different browsers render the menu slightly differently and therefore require different values in order to get the drop down to align.
What's a better way to get the dropd down to align with the menu bar? Or perhaps someone can point me to a better tutorial?
I've copied the code from the tutorial to this: http://jsfiddle.net/Pnn6V/. Please disregard the slight issues with the jsfiddle as it's not the problem I'm facing/not what I'm asking about.
You are changing alignment of the menus from tutorial so some css settings also need to change to get the desired effect.
I would like the dropdown div to be the same full width as
the full horizontal menu bar and be aligned with the menu bar.
In tutorial it says
In order to have a perfect drop down container, we need to specify the
width for each one
.dropdown_1column {width: 140px;}
.dropdown_2columns {width: 280px;}
.dropdown_3columns {width: 420px;}
.dropdown_4columns {width: 560px;}
.dropdown_5columns {width: 700px;}
So you are supposed to adjust all the widths according to your need.
what I have done in your css is
#menu li .align_right {
/* Rounded Corners */
/*-moz-border-radius: 5px 0px 5px 5px;
-webkit-border-radius: 5px 0px 5px 5px;
border-radius: 5px 0px 5px 5px;*/
}
#menu li:hover .align_right {
/* left:auto;
right:-1px;*/
top:auto;
}
I removed right border of your 1column because in tutorial it was having different alignment (it was in right) and what you are doing with this 1column is you are putting this on left so right border have to be removed. that was the main reason.
see this output
Output
jsfiddle
There are so many tutorials for mega drop down menu it depends on your need, please take a look if they suit your need.
Jquery and css dropdowns
And i would suggest you to read the tutorial carefully and change css accordingly/oppositely , that will clear so many css doubts/concepts of yours and soon you will learn CSS easily.
and that day is not far when you will be answering css questions here :)
EDIT :
According to your comment i understood this :
Jsfiddle
Output
what I have done is :
I changed the width accordingly:
.dropdown_1column {width: 930px;}
.dropdown_2columns {width: 931px;}
.dropdown_3columns {width: 930px;}
.dropdown_4columns {width: 932px;}
.dropdown_5columns {width: 932px;}
Previously left property was applying on all column which was incorrect you have to apply individual left value in each as per I dont
#menu li:hover .dropdown_1column
{
left:-841px;
top:auto;
}
#menu li:hover .dropdown_2columns
{
left:-2px;
top:auto;
}
#menu li:hover .dropdown_3columns
{
left:-736px;
top:auto;
}
#menu li:hover .dropdown_4columns
{
left:-248px;
top:auto;
}
#menu li:hover .dropdown_5columns {
left:-110px;
top:auto;
}
Hope this is clear...
You can try adding a css reset in your page to reduce browser inconsistencies
http://meyerweb.com/eric/tools/css/reset/