I have my horizontal navigation, and one of the links has a dropdown menu. I'm having trouble removing my the vertical scrollbar from my horizontal navigation. Because of this, you have to scroll down to see the dropdown. If I remove the scrollbar, you cannot see the dropdown menu. I've tried to set a height, tried different overflow settings, even z-index.. nothing has worked.
https://jsfiddle.net/83qgv1nb/
nav.mainNav {
margin: 0;
padding: 0;
width: 75%;
float: right;
display: block;
overflow: auto;
}
ul.menu {
margin: 0;
padding: 0;
height: 100px;
overflow-y: visible;
}
li.item {
margin: 0;
padding: 0;
height: 100px;
width: 16%;
position: relative;
float: left;
list-style-type: none;
}
a.navLink {
margin: 0;
padding: 0;
display: block;
text-align: center;
line-height: 95px;
text-decoration: none;
font-weight: bold;
}
<nav class="mainNav">
<ul class="menu">
<li class="item">
About
<ul class="sub_menu">
<li class="sub_item">
Location
</li>
<li class="sub_item">
History
</li>
<li class="sub_item">
Community Involvement
</li>
<li class="sub_item">
Leadership
</li>
</ul>
</li>
<li class="item">Services</li>
<li class="item">Projects</li>
<li class="item">Blank</li>
<li class="item">Blank</li>
<li class="item">Contact</li>
</ul>
</nav>
1st you should remove your
.mainNav{
...
overflow:auto"
...
}
This is clearly what makes your menu "scrollable"!
Here, your "submenu" is always visible... If you're looking for a way to show/hide your submenu then You should use "bootstrap", it's easy and it has lots of examples of dropdown menus.
If you want to make it yourself, then :
Try to identify your dropdown menu item, give it a class or something that allows you to check if user clicks on a dropdown or not.
Then, on "click", do an action that show/hides the next list element. (jquery's got a "toggle()" function made for this kind of job)
On document load, set all your dropdown menus with display:none. To hide them. Then, on click on them, just use toggle() on them, or add them an attribute that makes them visible, such as an "active" class.
here is a short example on how you could handle this with jQuery : https://jsfiddle.net/83qgv1nb/21/
(this is just an example, there are lots of other examples or way to do this, I'm not pretending that my example here is the best way!)
if you do not use jQuery, then just check this link : Using Javascript to hide and show drop down menu and text field
update :
This is what you try to do with css i guess... : https://jsfiddle.net/83qgv1nb/27/
Related
I'm new here and new at HTML and CSS.
I've been trying to create a dropdown menu, and while the drop down menu shows up upon menu hover, it also shows up without menu hover. As soon as I move my cursor within where the dropdown should be appearing, it appears. Do you know what I'm doing wrong and how I should correct it? I hope I'm making sense...
Also, I am aware that the width of my menu expands as I expand the window size. Please ignore that, it doesn't do that in the main code I'm working on.
Thanks in advance!
.top-menu>ul {
background-color: #78a1bb;
font-size: 150%;
padding-left: 0px;
padding-right: 0px;
}
.top-menu>ul>li {
list-style: none;
display: inline-block;
padding: 5px 124px;
position: relative;
}
.top-menu>ul>li:hover {
background-color: #d6e2ea;
}
ul.sub-menu {
position: absolute;
width: 290px;
background-color: #d6e2ea;
list-style: none;
padding-left: 0px;
padding-top: 5px;
opacity: 0;
}
ul.sub-menu li {
font-size: 80%;
padding-top: 10px;
padding-left: 25px;
padding-bottom: 10px;
}
.top-menu li:hover .sub-menu {
opacity: 1;
left: 0px;
}
<nav class="top-menu">
<ul>
<li> A
<ul class="sub-menu">
<li>Sub a </li>
<li>Sub b </li>
<li>Sub c </li>
</ul>
</li>
<li> B </li>
<li> C </li>
</ul>
</nav>
Instead of use opacity to hide your sub-menu. You can use display: none to hide and display: block to show again.
If you just change the opacity, the element remains "under your mouse" and the CSS try to show and hide many times (your sub-menu is "flicking").
Using display: none the sub-menu disappears and your mouse doesn't hover it "forever".
I created a plunker with the right code. https://embed.plnkr.co/TZ7U0m19WijN0kIe6Xgl/
I'm working on a fancy menu of some sort, but cant seem to get my head around a problem currently facing. Here's a image to illustrate the problem:
The whole thing is built using a nav tag that has a ul with li children.
Basically the right box thingy has to always stay on the top row, right edge, and when the windows is shrunken or smaller, this position/behavior has to maintain, and the other regular menu items should collapse on the second row.
The 2 boxes have to maintain a order: the one on the left is the first li element, and the one on the right is the last li element
Here's what I've tried so far:
-position absolute wont cut it, because it will indeed stay on the right, but it may or may not overlay the other elements(current situation);
-floating it, will probably collapse with the other elements on the next row
-adding a padding right to the nav or ul tag, will work, however, the other menu items will always have a right margin that wont allow them to ever fall under the right boxy thing;
Heres a js fiddle to the problem(shrink the results window): menu issue
I'm open to any ideas, even changing the whole markup if that's the solution, or some fancy js if its working. Thank you!
The markup used:
<nav class="secondary-navigation main-section">
<ul class="align-left secondary-navigation-list">
<li class="menu-item-block">
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li>
Menu Item
</li>
<li class="menu-item-block menu-last-item-block">
</li>
</ul>
The css used:
a{
text-decoration: none;
color: #656565;
padding: 10px;
font-size: 1.4em;
line-height: 50px;
}
.menu-item-block{
width: 50px;
height: 50px;
background: #656565;
}
.menu-last-item-block{
position: absolute;
top: 0;
right: 0;
}
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
li{
float: left;
}
nav.secondary-navigation{
position: relative;
display: inline-block;
width: 100%;
}
nav.secondary-navigation:after{
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 5px;
background: #656565;
}
ul.secondary-navigation-list:after,
ul.secondary-navigation-list:before{
content: '';
position: absolute;
width: 5px;
height: 100%;
background: #656565;
}
ul.secondary-navigation-list:before{
left: 0;
}
ul.secondary-navigation-list:after{
right: 0;
}
You can do it by a little manipulation on the html and css:
change the order of the li so that the 2 special ones are on top
<ul class="align-left secondary-navigation-list">
<li class="menu-item-block">
</li>
<li class="menu-item-block menu-last-item-block">
</li>
<li>
Menu Item
</li>....
Change the css rule for secondary-navigation-list
.menu-last-item-block{
float:right;
}
see fiddle: http://jsfiddle.net/CLtCL/12/
I am not really into all those coding terms, so I am having some difficulties to find answer to my problem. Usually I am just copy paste existing code and try to make some adjustments to what I want. Anyway I am working on a navigation menu on a one-page website. So till now that works. However, I want to have a sub-menu. I tried some things, but I cannot really get what I want. What I want is when I click on a menu item, the sub-menu opens and activate the first sub-menu item.
I found an example: http://inthe7heaven.com/fb-john-doe/dark/
The photo section. I tried to replicate that, but I think the sub-menu is connected to the filtering function of the photogallery.
Can anybody give me some guidance in this?
HTML
<nav class="on_caption">
<ul class="pagination">
<li class="home current">Home</li>
<li class="">About EJ</li>
<li class="">Services</li>
<li class="photos">
Photos
<div id="filter" class="category_filter_list">
<span class="active_link" id="all">All</span>
<span id="cookies">Cookies</span>
<span id="bread">Bread</span>
<span id="baking">Baking</span>
</div>
</li>
<li class="">Classes</li>
<!--<li class="">Testimonials</li>-->
<li class="">Contact</li>
</ul>
</nav>
CSS
nav {
position: absolute;
z-index: 999;
right: 0;
top: 0;
width: 158px;
height: 600px;
display: block;
overflow: hidden;
behavior: url(js/PIE.htc);
}
nav.on_caption {
background: rgba(20,11,19,.6);
-pie-background: rgba(20,11,19,.6);
}
nav.on_caption a {
color: #d0ced0;
}
nav.off_caption {
background: rgba(20,11,19,.08);
-pie-background: rgba(20,11,19,.08);
}
nav.off_caption a {
color: #524b51;
}
nav a {
font-size: 1.143em;
text-transform: uppercase;
}
nav > a {
padding-left: 24px;
}
ul.pagination {
margin: 0;
padding: 0;
padding-bottom: 8px;
list-style:none;
}
ul.pagination li {
margin: 0px 0px 0px 0px;
clear: both;
padding: 8px 10px 0px 24px;
list-style: none;
}
ul.pagination li:first-child {
padding-top: 25px;
}
nav > a:hover,
nav ul.pagination li a:hover,
nav ul.pagination li.current a {
color: #90705B;
}
So I got this code based on the website I provided above. I want the same effect as in the photo section only then for a normal menu item that is not connected to a filter. That is, when the menu item is clicked, the menu gets extended with the sub-menu and the page goes to the first item in the sub-menu. In addition, the sub-menu item gets active.
I managed to get the sub-menu expand and collapse in jsfiddle using a tree-menu. I tested it in jsfiddle and there it works. However, it doesn't work in my website. The menu doesn't expand. The website I am using it in is a single page website. So the menu items are pointing to a section on the page. So, I guess that my href="sub-1" is not working because it's pointing at the 3rd section of the page.
Is there a simple work-around for this? I don't need any fancy jquery effects, it just needs to open.
Furthermore, when the parent item is clicked, the sub-menu needs to expand and needs to activate the first sub-item. How can I do this?
HTML
<nav class="on_caption">
<ul class="pagination">
<li class="home current">Home</li>
<li class="">About EJ</li>
<li class="">Services
<ul id="sub-1">
<li class="">Test</li>
<li class="">Test</li>
</ul>
</li>
<li class="">Photos</li>
<li class="">Classes</li>
<li class="">Contact</li>
</ul>
</nav>
CSS
.pagination > li ul {
display: none;
}
.pagination > li ul:target {
display: block;
}
Made some progress.
HTML
<nav class="on_caption">
<ul class="pagination">
<li class="home current">Home</li>
<li class="">About EJ</li>
<li class="">Services
<ul id="sub-1">
<li class="">Test</li>
<li class="">Test</li>
</ul>
</li>
<li class="">Photos</li>
<li class="">Classes</li>
<li class="">Contact</li>
</ul>
</nav>
CSS
.pagination > li ul {
display: none;
}
jQuery
jQuery(
function($)
{
$('.pagination a').click(function(){$(this).next('ul').toggle();});
}
);
This works now. When I click the menu item, the sub-menu gets expended. However, how do I let the sub-menu collapse again when another menu item is clicked? And how do I let the page automatically go to the first sub-menu item by default when the menu item is clicked?
I'm currently working on a pure CSS color palette that needs to be a link. I've created this palette by using an unordered list, which I then wrapped in a <a> tag. I have a suspicion that this is not very semantic though. What would be the correct way to achieve this?
HTML
<div class="color-palette">
Modern Feminine
<a href="#">
<ul class="color-chips group">
<li class="grey">#999999</li>
<li class="slate">#666666</li>
<li class="lilac">#99878D</li>
<li class="blush">#7E4A5C</li>
<li class="plum">#372129</li>
</ul><!--.color-chips group-->
</a>
</div><!--.color-palette-->
CSS
.color-palette {
width: 280px;
margin: 0 auto;
padding: 0;
}
ul.color-chips {
margin: 0 auto;
padding: 0;
}
ul.color-chips li {
float: left;
margin: 0;
}
ul.color-chips li {
float: left;
width: 55px;
height: 55px;
text-indent: -9999px;
}
You can't put a list inside an anchor.
You need to make each of the individual items in the list a seperate link.
<ul class="color-chips group">
<li class="grey">#999999</li>
<li class="slate">#666666</li>
<li class="lilac">#99878D</li>
<li class="blush">#7E4A5C</li>
<li class="plum">#372129</li>
</ul><!--.color-chips group-->
If you don't need links because you're not actually linking to anything (i.e. you're performing on-the-page operations) simply remove the anchors all together. You don't need them when attaching your Javascript onclick events.
<ul class="color-chips group">
<li class="grey">#999999</li>
<li class="slate">#666666</li>
<li class="lilac">#99878D</li>
<li class="blush">#7E4A5C</li>
<li class="plum">#372129</li>
</ul>
What would you like to do after your click? Do you use javascript event when click is fired?
Since you're already handling clicks with JS, I assume the anchor is purely cosmetic. In that case you can use CSS:
.color-chips:hover {
cursor:pointer;
}
Ok, so i have an unordered list with a background applied to it.
I also have list items with classes so
i can specify the width of each one individually.
Why can i not see the changes like width i added to the classes on each list?
although i do see it in Dreamweaver design view.
<ul id="graph">
<li class="1"><span>HTML</span></li>
<li class="2"><span>CSS</span></li>
<li class="3"><span>Javascript</span></li>
<li class="4"><span>SEO</span></li>
<li class="5"><span>Photoshop</span></li>
</ul>
#graph li {
list-style-type: none;
display: block;
background-image: url(../img/graph_bg.gif);
background-repeat: repeat-x;
margin-top: 20px;
}
#graph li .1 {
height: 35px;
display: block;
width: 85%;
}
etc , etc
I believe that 1, etc are not valid class names. I suspect they need to start with a letter.
Edit: on an unrelated note, is there any reason why you have <span> tags inside the <li> tags?