My website's demo navigation bar is like this in here https://jsfiddle.net/xzfy2ee2/.
Since the options for 'Faunas' is continuing to grow, I think it may be better to create a side menu. So I used all sorts of css :hover to achieve the result.
Although the functionality is robust enough, there is a wired grey line just after 'Asia' when I move the mouse onto 'Faunas' and calls out the dropdown menu. It's still there when I move the mouse onto 'Asia' to show the side menu 'Japan'.
The HTML/CSS for the navigation bar is shown here:
#nav a:hover
{
color: Silver;
}
#nav ul
{
list-style-type:none;
}
#nav ul li
{
display: inline-block;
}
#nav ul li:hover ul
{
display:block;
}
#nav ul ul
{
display: none;
position: absolute;
background-color: #888888;
border: 2.5px solid #A0A0A0;
border-top:0;
margin-left: 0px;
margin-right:2px;
min-width:80px;
}
#nav ul ul li
{
display: block;
}
#nav ul ul ul li
{
display: none;
position: absolute;
background-color: #888888;
border: 0px solid #A0A0A0;
border-top:0;
margin-left:115px;
margin-right:2px;
margin-top:-20px;
padding-right:5px;
min-width:80px;
}
#nav ul ul li:hover ul li
{
display:block;
}
#nav ul ul ul li:hover
{
display:block;
}
<div id="nav">
<ul>
<li>Home</li>
<li>Faunas
<ul style ="width:160px">
<li style="border-bottom:1px solid white;margin-bottom:3px">About</li>
<li style="border-bottom:1px solid white;margin-bottom:7px">World</li>
<li style="border-bottom:1px solid white;margin-bottom:2px">
Asia
<ul>
<li>Japan</li>
</ul>
</li>
<li>Albania</li>
<li>Bulgaria</li>
<li>Chile</li>
<li>Colombia</li>
<li>France</li>
<li>Italy</li>
<li>Japan</li>
<li>Macedonia</li>
<li>Poland</li>
<li>Serbia</li>
<li>Slovenia</li>
<li>South Africa</li>
<li>United Kingdom</li>
<li>United States</li>
</ul>
</li>
</ul>
</div>
I didn't find anything to do with the gray line. I wonder what exactly is the line there? And is there any way to remove it?
you have unnecessary border: 2.5px solid #A0A0A0; applied to #nav ul ul (which covers both 1st and 2nd level dropdowns)
here's working jsfiddle https://jsfiddle.net/Lt4udmpt/
#nav ul ul
{
display: none;
position: absolute;
background-color: #888888;
border-bottom: 2.5px solid #A0A0A0;
border-top:0;
margin-left: 0px;
margin-right:2px;
min-width:80px;
}
In this part of code border-bottom: 2.5px solid #A0A0A0; is the problem! It is causing the child ul tag to have border too!
Solution:
In css:
Border removed from #nav ul ul and added border to specific second ul
#nav ul ul
{
display: none;
position: absolute;
background-color: #888888;
border-bottom: 2.5px solid #A0A0A0;
border-top:0;
margin-left: 0px;
margin-right:2px;
min-width:80px;
}
#nav ul #second
{
border: 2.5px solid red;
}
In Html:
Assign an id to the ul
<ul id="second" style ="width:160px" >
If you just don't need the boder than delete border-bottom: 2.5px solid #A0A0A0; this line from #nav ul ul
update at jsfiddle
Looks like the #nav ul ul border-bottom element is the culprit.
#nav ul ul
{
border-bottom: 2.5px solid #A0A0A0; <-----delete
}
Related
When I hover over the Menu it shows the dropdown menu.
I want it to happen on click.
I tried it but it didnt work for me.
This is my code:
HTML:
<div class="responsive-menu">
<ul>
<li>Menu
<ul>
<li>Zomer</li>
<li>Herfst</li>
<li>Winter</li>
<li>Lente</li>
</ul>
</li>
</ul>
</div>
CSS:
li {
list-style-type:none;
}
.responsive-menu {
display:block;
background-color:black;
color:white;
text-align:center;
padding:10px;
font-size:200%;
}
.responsive-menu ul li ul li {
padding:10px;
border-bottom:solid 1px white;
border-top:solid 1px white;
}
.responsive-menu ul li ul {
display:none;
font-size:60%;
padding-top:30px;
}
.responsive-menu ul li:hover ul {
display:block;
}
Here is a link to JSFiddle.
Instead of the :hover pseudo-class you should use the :focus pseudo-class.
.responsive-menu ul li:focus ul {
display:block;
}
To let the li gain focus it needs a tabindex attribute
<li tabindex="9999">Menu
http://jsfiddle.net/t78mf7jb/1/
amend
For not having the focus effect from browser add a outline:none style on the li
.responsive-menu ul li:focus {
outline: none;
}
http://jsfiddle.net/t78mf7jb/3/
HerrSerkers answer is a good answer, but there is another if you're willing to change your markup a little. You can simulate a click by using checkbox with it's label, like:
li {
list-style-type: none;
}
.responsive-menu {
display: block;
background-color: black;
color: white;
text-align: center;
padding: 10px;
font-size: 200%;
}
.responsive-menu ul li ul li {
padding: 10px;
border-bottom: solid 1px white;
border-top: solid 1px white;
}
.responsive-menu ul li ul {
display: none;
font-size: 60%;
padding-top: 30px;
}
#trigger {
display: none;
}
#trigger:checked + .responsive-menu ul li:hover ul {
display: block;
}
<input type="checkbox" id="trigger" />
<div class="responsive-menu">
<ul>
<li>
<label for="trigger">Menu</label>
<ul>
<li>Zomer</li>
<li>Herfst</li>
<li>Winter</li>
<li>Lente</li>
</ul>
</li>
</ul>
</div>
JSFiddle
Update - as HerrSerker pointed out, there is a flaw regarding closing the menu - check his fiddle with a fix.
I am creating a vertical navigation menu using ul and li I want to make span the full width of ul so I can have underline for each menu item (like this site (http://www.steffenallen.com/index.php))
However, there is a space in li that prevents it from spanning across the parent ul. Could someone tell me how the above website did it? Or, what I need to do?
<nav>
<ul class='menu'>
<li class="menuItem">
About
</li>
<li class="menuItem"> Album
<ul class="submenu">
<li class="submenu-Item">Nepal </li>
<li class="submenu-Item">Seattle</li>
<li class="submenu-Item">South Korea</li>
</ul>
</li>
<li class="menuItem"> Contact </li>
<!-- <li> </li> -->
</ul>
My CSS is
ul,li{
list-style: none;
display: block;
}
ul.menu{
width: 170px;
/*position: absolute;*/
/*width: 100%;*/
/*margin-left: -20px;*/
border: 1px solid orange;
}
ul.submenu{
/*position: absolute;*/
/*left: -999px;*/
/*visibility: hidden;*/
display: none;
}
li{
width:140px;
margin: 0;
padding: 0;
/*width:100%;*/
border-left: 1px blue solid;
border-right: 1px blue solid;
}
span{
display: block;
}
li a, li span {
/*width: 170px;*/
/*width: 100%;*/
border-bottom: #cbcbcb 1px solid;
}
li.menuItem, li.submenu-Item{
text-align: right;
margin: 1em 0em 1em 0em;
}
li.menuitem > a{
color: #808080;
}
li a:hover{
color: steelblue;
}
li.menuItem a.current{
background-color: orange;
}
ul.menu:first-child{
margin-top: 0
}
First things first, your CSS is not well-written and hence a little difficult to understand.
The main problem in your code happens to be the default CSS that is being applied. You can remove that as follows:
ul, li {
margin: 0;
padding: 0;
}
However, I'd suggest you simplify your CSS code as follows. This will still achieve what you are looking for all the while making your code more elegant and easily readable. Please see the code below :
ul, li {
margin:0px;
padding:0px;
}
ul.menu {
border: 1px solid Orange;
width:200px;
}
ul.menu li {
display:block;
list-style-type:none;
}
ul.menu li a {
border-bottom:1px solid #ccc;
display:block;
text-align:right;
text-decoration: none;
}
ul.menu li ul {
display:none;
}
ul.menu li:hover > ul {
display:block;
}
ul.menu li ul li:last-child {
border-bottom:none;
}
See this working below :
ul, li {
margin:0px;
padding:0px;
}
ul.menu {
border: 1px solid Orange;
width:200px;
}
ul.menu li {
display:block;
list-style-type:none;
}
ul.menu li a {
border-bottom:1px solid #ccc;
display:block;
text-align:right;
text-decoration: none;
}
ul.menu li ul {
display:none;
}
ul.menu li:hover > ul {
display:block;
}
ul.menu li ul li:last-child {
border-bottom:none;
}
<nav>
<ul class='menu'>
<li class="menuItem"> About
</li>
<li class="menuItem"> Album
<ul class="submenu">
<li class="submenu-Item">Nepal
</li>
<li class="submenu-Item">Seattle
</li>
<li class="submenu-Item">South Korea
</li>
</ul>
</li>
<li class="menuItem"> Contact
</li>
<!-- <li> </li> -->
</ul>
Hope this helps!!!
On the left side there is the default margin/padding of ULs, so just remove that. It's 40px and depends on browser if margin or padding is used.
ul, li {margin-left: 0; padding-left: 0;}
The space on the right side is caused by your widths, list has 170px, items just 140px.
http://jsfiddle.net/8q9chvbh/
Here I have my website: http://gyazo.com/56e069ebf8b5bd61ee30523886180b88
There are a number of issues with the nav bar.
1.You can see that the text or nav bar is not horizontally centered, as indicated by the hover (which is equal on top and bottom)
2.There is to much space in between the text, (and this spacing is the only way I've found works without the text moving around when highlighting or hovering.
So for 1. is there a way I can make the text or the nav bar (not sure what is the cause) centre so the hover looks more equal (horizontally)
For 2. Is there a way I can close the gap between the text, while still keeping the same padding settings, and so it doesn't move the text around when I use the hover function.
I've also added a jsfiddle if that helps: http://jsfiddle.net/d1a5eshs/
HTML FOR NAV BAR
<!--TOP NAV BAR SECTION-->
<div id="nav_bar">
<ul>
<li>HOME
</li>
<li>STATUS
</li>
<li>INFO
</li>
<li>GAMEMODES
<ul>
<li>SURVIVAL
</li>
<li><br>PURE-PVP
</li>
<li><br>GAMESWORLD
</li>
</ul>
</li>
<li>RULES
</li>
<li>VOTE
</li>
<li>CONTACT
</li>
</ul
CSS FOR NAV BAR
/*TOP NAV BAR SECTION*/
#nav_bar {
background-color: #a22b2f;
padding:1px;
box-shadow: 0px 2px
height:45px;
}
#nav_bar ul li {
display: inline-block;
}
#nav_bar ul li a {
color: white;
text-decoration:none;
font-weight:bold;
font-size:15px;
margin-left:10px;
padding-bottom:13px;
padding-top:17px;
padding-left:10px;
padding-right:10px;
margin-bottom:30px;
}
#nav_bar ul li ul {
display: none;
}
#nav_bar>ul>li>a:hover {
background:#8c1b1f;
padding-bottom:13px;
padding-top:13px;
padding-left:10px;
padding-right:10px;
}
#nav_bar>ul>li>ul>li>a:hover {
background:#c9c9c9;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
#nav_bar ul li:hover ul {
display: block;
position: absolute;
padding: 0px;
background: #e2e2e2;
padding-top:10px;
padding-bottom:10px;
padding-left:0px;
padding-right:10px;
border: 1px solid black;
border-radius:5px;
}
#nav_bar ul li:hover ul li {
display: block;
}
#nav_bar ul li:hover ul li a {
color: black;
font-size:12px;
font-weight:bol;
margin-left:-20px;
padding-bottom:5px;
padding-top:5px;
padding-left:5px;
padding-right:5px;
}
There were several spacing issues and also there were several duplicate styles and a few mistakes, but I think I fixed all your issues. http://jsfiddle.net/d1a5eshs/1/.
Here's my version of your navigation bar: http://jsfiddle.net/zo541am2/. I trimmed and simplified both your HTML and CSS code.
HTML:
<nav>
<ul>
<li>HOME</li>
<li>STATUS</li>
<li>INFO</li>
<li>GAMEMODES
<ul>
<li>SURVIVAL</li>
<li>PURE-PVP</li>
<li>GAMESWORLD</li>
</ul>
</li>
<li>RULES</li>
<li>VOTE</li>
<li>CONTACT</li>
</ul>
</nav>
CSS:
* {
margin: 0;
padding: 0;
}
body {
padding: 10px;
}
nav {
background-color: #a22b2f;
box-shadow: 0px 2px 10px;
}
ul {
list-style-type: none;
}
nav > ul {
display: table;
margin: 0 auto;
min-width: 650px;
text-align: center;
}
nav > ul > li {
display: inline-block;
position: relative;
}
nav > ul > li > a {
display: block;
color: #fff;
text-decoration: none;
font: bold 15px/3 Serif;
padding: 0 15px;
}
nav ul ul {
display: none;
position: absolute;
min-width: 100%;
background: #e2e2e2;
border: 1px solid gray;
border-radius: 2px;
}
nav > ul > li:hover > a {
background: #8c1b1f;
}
nav ul ul li a {
display: block;
color: black;
font: bold 12px/3 Sans-Serif;
text-decoration: none;
}
nav ul ul > li:hover > a {
background: #c9c9c9;
}
nav > ul > li:hover > ul {
display: block;
}
I need some smart-people help. I've wracked my brain on this and I am close, but just cannot get my sub-sub menu items to drop to the right on hover.
I probably have conflicting or reiterative css, but I've removed parts and put back other parts, and... I just need to see if something jumps out to you guys, I'm sure it will.. - I feel like I'm close but.. no cigar. I took two menus and tried to use parts of each (had ability to do 2 column and other had sub menus) so I know this can be simplified way more.
I'd really appreciate it - I know its a mess at this point, there's more than needed for this simple section of html I have drilled down to, but if you can just see where the problem is -- I'm looking for the uls for Toy 1 and Toy 3 to drop down on hover. Thanks.
html
<!-- drop menu-->
<ul id="menu">
<li>TOYS
<div class="menu-container-1">
<ul class="column-1">
<li><span>Toy 1</span>
<ul>
<li>sub menu basic 1</li>
</ul>
</li>
<li>Toy 2</li>
<li><span>Toy 3</span>
<ul>
<li>sub menu basic 3</li>
</ul>
</li>
<li>Toy 4</li>
</ul>
</div>
</li>
</ul>
and here is the css:
#menu li {
float:left;
display:block;
position:relative;
text-align:center;
padding:4px 18px;
margin:0px 27px 0 0;
border:none; }
#menu li:hover {
border-width:0 0 0 1px;border-style:solid;border-color:#F1F7FC;
padding:4px 18px 4px 17px;
display:block; }
#menu li a {
font-family:Arial, Helvetica, sans-serif;
font-size:16px/1.8em;
color: #000;
display:block;
outline:0;
text-decoration:none;
font-weight:500; }
#menu li:hover a {
color:#161616; }
/* menu containers here */
#menu .menu-container-1,#menu .menu-container-2,#menu .menu-container-3,#menu .menu-container-4 {
margin:4px auto;
float:left;
position:absolute;
left:-999em;
text-align:left;
padding:10px 5px 3px 5px;
border:1px solid #D8E9F8; /* border around dropdown */
border-top:none;
/* rounded corners */
border-radius:0 5px 5px 5px;
-moz-border-radius:0 5px 5px 5px;
-webkit-border-radius:0 5px 5px 5px;
/* gradient */
background:#ffffff;
background: -moz-linear-gradient(center top, #ffffff, #FAFCFE) repeat scroll 0 0 transparent;
background:-webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#FAFCFE));
box-shadow:inset .4px -2px 3px 2px #EFFFFF; }
#menu .menu-container-1 {
width:165px; }
#menu .menu-container-2 {
width:340px; }
#menu li:hover .menu-container-1, #menu li:hover .menu-container-2, #menu li:hover .menu-container-3, #menu li:hover .menu-container-4 {
top:auto;left:-1px; }
/* columns */
#menu .column-1, #menu .column-2 {
display:inline; float:left;position:relative;margin:0;}
/*added 7/9 for span arrow sub menu */
#menu span{
display:block;overflow:visible;background-position:right center;background-repeat:no-repeat;padding-right:0px;}
#menu ul span{
background-image:url("https://www.kqimageserver.com/other/arrowsub.png");padding-right:12px;}
/*thought might be sub menu */
#menu ul ul {
position:absolute;left:80%;top:0;}
#menu .column-1 {
width:165px;}
#menu ul li ul li{ display:none;}
#menu ul li ul li ul li hover>* {display:block; }
/* attempts to get sub menu to show on hover */
#menu .column-1 ul li ul li:hover>*{
display:block;position:absolute;left:80%;top:0;}
#menu li:hover div a {
box-shadow: 0 1px 0 #eeeeee, 0 2px 0 #eeeeee; /*lines between list items */
color: #000;
font-size: 13px;
padding-left: 6px;
font-weight:500;
width: 159px; }
#menu li:hover div a:hover {
background: -moz-linear-gradient(#04ACEC, #0186BA) repeat scroll 0 0 transparent;
background:-webkit-gradient(linear, left top, left bottom, from(#04ACEC), to(#0186BA));
color: #000;
background:#deeff7;}
#menu li ul {
/*box-shadow: 0 1px 0 #111111, 0 2px 0 #777777; */
list-style:none;
padding:0;
margin-bottom:7px;}
#menu li ul li {
float: none;
font-size: 12px;
line-height: 24px;
margin: 0;
padding: 0;
position: relative;
text-align: left;
width: 130px;}
#menu li ul li:hover {
background: none;
border: medium none;
margin: 0;
padding: 0; }
Here is a js-fiddle
http://jsfiddle.net/tousif123/TfhLb/
Try
removing
#menu ul li ul li {
display: none;
}
and adding
ul.column-1 li ul
{
display:none;
}
ul.column-1 li:hover ul
{
display:block;
}
Heres a js-fiddle
http://jsfiddle.net/tousif123/brBj5/
You just bave a bad selector for your block display:
#menu ul li ul li ul li hover>* {display:block; }
It should read
#menu ul li:hover ul li { display: block; }
Using display:none and display:block isn't very accessible.
Ultimately, if you have the time and patience the best thing to do is to use the clip technique. It will hide content when it isn't needed, but also keep it accessible:
http://developer.yahoo.com/blogs/ydn/clip-hidden-content-better-accessibility-53456.html
New to CSS. I have a nav menu bar and I am trying to fill the background color (blue) in the drop down menu under "portfolio" when you hover over it. Any ideas? I think its because of that absolute?
CSS:
#nav, #nav ul {
float: left;
list-style: none;
box-shadow: 0px 1px 7px #000000;
background-color: #F5F1DE;
border-radius: 5px 5px 0px 0px;
z-index: 100;
}
#nav li a {
display: block;
padding: 16px;
text-decoration: none;
font-weight: bold;
color: black;
border-left: 1px solid #ccc;
font-size: 1em;
}
#nav li a:hover {
color: black;
background-color: #bbecff;
}
#nav li {
float: left;
}
#nav li ul {
position: absolute;
width: 11em;
left: -999em;
border-radius: 1px;
}
#nav li:hover ul, #nav li.sfhover ul {
left: auto;
}
HTML:
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Packages</li>
<li>Portfolio
<ul>
<li>Weddings</li>
<li>Special Events</li>
<li>Holidays</li>
<li>Fresh Flowers</li>
<li>Balloon Sculptures</li>
</ul>
</li>
<li>Contact</li>
</ul>
Add float:left only for first child of ul.Update your following line of css:
#nav li {float: left;}
to
#nav > li {float: left;}
Here is the fiddle
Try this, hope it will work for u
add the CSS
#nav li ul{
background:#0066CC;
}
give background color to the following
#nav li:hover ul, #nav li.sfhover ul
#nav li:hover ul, #nav li.sfhover ul {
background-color: #bbecff;
}
But with that said: Why don't you apply the background-color to the submenu ul directly?
U may also try this, I hav given an id to respective li
<li id=blueColor>
<li>Weddings</li>
<li>Special Events</li>
<li>Holidays</li>
<li>Fresh Flowers</li>
<li>Balloon Sculptures</li>
</ul>
In CSS
#blueColor:hover{
backgroung-color:blue
}