I have a problem with the navigation bar. When I hover over About or Text on the nav bar it shows a spacing on the left side of the button, I want it the hover colour to contain the full width of the button.
https://jsfiddle.net/jdd3h0sf/3/
HTML:
<div id="nav">
<ul>
<li class="home">Home</li>
<li>About</li>
<li>Text ⌄
<ul class="submenu">
<li>One</li>
<li>Two</li>
<li>Three</li></li>
</ul>
<li>Work</li>
<li>Contact ⌄
<ul class="submenutwo">
<li>One</li>
<li>Two</li>
<li>Three</li></li>
</ul>
</ul>
CSS:
#nav {
background-color: #333;
height: 52px;
text-align: center;
margin: 0 auto;
letter-spacing: 1px;
text-transform: uppercase;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
}
#nav li {
border-right: 1.8px solid #191919;
height: auto;
width: 156.5px;
padding: 0;
margin: 0;
}
.home {
border-left: 1.8px solid #191919;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #444;
}
#nav ul li a, visted {
color: #ccc;
display: block;
padding: 15px;
margin: 0;
text-decoration: none;
}
#nav ul li a:hover {
color: #ccc;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #444;
border: 1px solid #333;
border-top: 0;
max-width: 169px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:visited {
color: #ccc;
}
#nav ul ul li a:hover {
color: #2980B9;
}
This is a part of display:inline-block;. If you want to keep them displayed inline-block, there are several different solutions (Read a css-Tricks article about it):
1 - Change your HTML format:
Change your <li>'s html like this:
<ul>
<li>
one</li><li>
two</li><li>
three</li>
</ul>
Or this:
<ul>
<li>one</li
><li>two</li
><li>three</li>
</ul>
Or even with comments, like this:
<ul>
<li>one</li><!--
--><li>two</li><!--
--><li>three</li>
</ul>
Or, just place all the li's on a single line:
<ul><li>one</li><li>two</li><li>three</li></li>
It is messy, yet effective.
2 - Negative margins:
Pretty straightforward:
li{
display: inline-block;
margin-right: -4px;
}
3 - Skip the closing tag:
This is actually perfectly fine in HTML5, li's do not have to have a closing tag.
<ul>
<li>one
<li>two
<li>three
</ul>
4 - Set the <ul>'s font size to 0:
ul {
font-size: 0;
}
ul li {
font-size: 16px;
}
5 - Or, just float the <li>'s:
Whatever floats your boat.
You are experiencing the dreaded inline-block spacing issue. In your fiddle, if you condense all of your li elements to be on the same line, the hover works as expected. The linked article outlines a few other options.
You can also just float the elements and that would resolve the issue.
#nav ul li {
float: left;
}
Related
Just learning HTML and CSS and wondering how I could have an expandable list within an expandable list. I have the problem that the second expandable list is already expanded when I click the first expandable list. Yo dawg, I heard you like expandable lists....
Here is my code:
<!DOCTYPE html>
<head>
<title>Sample</title>
</head>
<style>
body {
padding: 0;
margin: 0;
font-size: 18px;
font-family: Arial;
}
#nav {
background-color: black;
}
#navbar {
margin: auto;
width: 960px;
text-align:left;
}
#nav ul{
position: relative;
list-style-type: none;
padding:0;
margin: 0;
}
#nav ul li {
display: inline-block;
}
#nav ul li a {
text-decoration: none;
color: white;
padding: 15px;
display: block;
}
#nav ul li:hover {
background-color: silver;
}
#nav ul ul{
display: none;
margin: 0;
background-color: black;
position: absolute;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul li {
display:block;
}
#nav ul ul ul{
display: none;
position: absolute;
margin-left: 110px;
margin-top: -52px;
background-color: black;
}
#nav ul ul li:hover ul{
display: block;
}
#nav ul ul ul li {
display: block;
}
</style>
<body>
<div id="nav">
<div id="navbar">
<ul>
<li>Home</li>
<li>Contact</li>
<li>About</li>
<li>Social
<ul>
<li>Facebook</li>
<li>Twitter</li>
<li>YouTube
<ul>
<li>Our Page</li>
<li>Top Videos</li>
<li>Popular</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</body>
Use the child (direct descendant) selector > instead of the descendant selector
#nav ul>li:hover>ul {
display: block;
}
Demo
What you are currently doing is saying: when hovering over the li set any decendant ul, no matter what the depth, to display:block.
The new code says: when hovering over the li set any uls that are children (or direct descendants) of that li to display:block. Any uls nested deeper will be untouched.
I have created a CSS and HTML navigation menu that works in all browsers except IE6 - IE8. How can I make this work? I've attempted to make my css and html as small as possible to help with the compatibility but to no avail.
CSS and HTML
ul ul {
display: none;
}
ul li:hover > ul {
display: block;
}
ul {
background-color: #99CCFF;
background-color: rgb(153, 204, 255);
list-style-type: none;
position: relative;
display: inline-table;
font-family: 'Julius Sans One', sans-serif;
}
ul:after {
content: ""; clear: both; display: block;
}
ul li {
float: left;
display:none;
}
ul li:hover {
background: #6699CC;
}
ul li:hover a {
color: #000000;
}
ul li a {
display: block; padding: 25px 40px;
color: #000000; text-decoration: none;
}
ul ul {
background: #99CCFF; padding: 0;
position: absolute; top: 100%;
}
ul ul li {
display:inline;
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid #575f6a;
position: relative;
}
ul ul li a {
padding: 15px 40px;
color: #000000;
}
ul ul li a:hover {
background: #6699CC;
}
ul ul ul {
position: absolute; left: 100%; top:0;
}
<ul id="nav">
<li>Contact Us
<ul>
<li>Address</li>
<li>Rentals</li>
<li>Phone Numbers</li>
</ul>
</li>
<li>Mass
<ul>
<li>Readings</li>
<li>Bulletins</li>
<li>Catechism</li>
<li>Archdiocese of<br>Indiana</li>
<li>Confession</li>
<li>Mass Schedule</li>
</ul>
</li>
<li>Ministries
<ul>
<li>Pre-School</li>
<li>Day Care</li>
<li>CCD</li>
<li>Haiti<br>Ministry</li>
</ul>
</li>
<li>Info
<ul>
<li>Walking<br>Park</li>
<li>Councils &<br>Committees</li>
<li>Cemetery Rules</li>
<li>Bulletins</li>
<li>Catechism</li>
</ul>
<li>Activities
<ul>
<li>Labor Day<br>Festival</li>
<li>Bingo</li>
<li>Drawdown</li>
<li>MSGR Schmitz<br>Memorial Fund</li>
</ul>
</li>
</ul>
Looks like you have too many preceding ul selectors in your css rules.
<ul>
<li>
<ul> </ul>
</li>
<ul>
That is your basic structure. Try removing the extra ul from the css where there are more than 2 of them.
Second, I notice you're using an inline-table rule. Rules like these are often trouble with older versions of IE, so make sure to do a compatibility check on these types of rules. Here's another SO post as a reference to this:
display:inline-table
i'm creating a site for a bookstore and the designer wants to represent the menu as seperate piles of books. I have 4 piles with different amount of books (read menu items). I can create the menu with ul containing 4 li's (piles) which contain ul with li's (books). I have to stick to the ul and li notation because the menu will be created like that by Joomla.
The problem is that the books look like they float to the ceiling instead of lying on the shelf. How can i make the books lie down on the shelf?
Example: http://jsfiddle.net/cJ8an/
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: white;
background: red;
padding: 2px 10px;
}
a:hover {
color: black;
}
ul li {
float: left;
list-style: none;
}
ul li ul {
margin-right: 25px;
}
ul li ul li {
float: none;
margin-top: 5px;
}
hr {
clear: both;
height: 10px;
background: brown;
}
</style>
</head>
<body>
<ul>
<li>
<ul>
<li>HOME</li>
</ul>
</li>
<li>
<ul>
<li>BOEKENTIPS</li>
<li>MEER DAN BOEKEN</li>
<li>NIEUWS</li>
</ul>
</li>
<li>
<ul>
<li>LEZERSBLOG</li>
<li>BESTELFORMULIER</li>
<li>VERTELTHEATER</li>
<li>ANTROPOSOFIE</li>
</ul>
</li>
<li>
<ul>
<li>CONTACT</li>
<li>SCHOLEN</li>
<li>KINDEROPVANG</li>
</ul>
</li>
</ul>
<hr id="bookshelf" />
</body>
</html>
display:table used in a clever way seems to have worked. This will need some tweaking, but I'm sure you can take it from here. Good luck. http://jsfiddle.net/tmpQM/
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: white;
background: red;
padding: 2px 10px;
}
a:hover {
color: black;
}
ul {
display:table;
}
ul li {
display:table-cell;
list-style: none;
vertical-align:bottom;
}
ul li ul {
margin-right: 25px;
display:block;
}
ul li ul li {
float: none;
margin-top: 5px;
display:inline-block;
}
hr {
clear: both;
height: 10px;
background: brown;
}
I have originally created my navigation in Chrome in which the outcome fits perfectly to my needs. I have then found out that Mozilla Firefox won't output the same result, the drop-down menus under Member Action and Admin Related will display vertically instead on horizontally as i wanted. However my biggest dissapointment was testing the navigation in Internet Explorer which won't even show the drop-down menus.
I would really appreciate someone checking the below code and your feedback, Thanks.
Solved the problem by changing one of the lines in css;
navigation ul li {float: left; list-style:none; }
HTML
<div id="navigationContainer">
<div id="navigation">
<ul>
<li class="borderleft">Home </li>
<li>Register </li>
<li>Search cars</li>
<li>Display all cars</li>
<li>Member Actions
<ul> <!-- Open drop down menu -->
<li class="bordertop">Login</li>
<li class="floatLeft">Member Area</li>
<li>Reservation</li>
<li>Contact us</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car</li>
<li>Delete a car</li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>
CSS
* {padding: 0%; margin 0%; } /* Overwrites the browser stylesheet */
#navigationContainer {background:url(images/navi.png); width:100%;position: relative; white-space:nowrap; word-spacing:0; }
#navigation {width:1200px; height:65px; position: relative; font-family: Arial; margin: 2px auto; font-size: 125%; }
#navigation ul { list-style-type: none; }
#navigation ul li {float: left; position: relative; }
#navigation ul li a { border-right: 2px solid #e9e9e9; padding: 20px;
display: block; margin: 0 auto; text-align: center; color: black; text-decoration: none; }
#navigation ul li a:hover { background: blue; color: white; }
#navigation ul li ul { display: none; }
#navigation ul li:hover ul {display: block; position: absolute; }
#navigation ul li ul li {float:left; position:relative; }
#navigation ul li:hover ul li a { background: #12aeef; color: white; position:relative; margin: 0px auto; border-bottom: 1px solid white; border-right: 1px solid white; width: 119px; }
#navigation ul li:hover ul li a:hover { background: blue;}
.bordertop { border-top: 1px solid white; }
.borderleft { border-left: 2px solid #e9e9e9;}
Try this
http://jsfiddle.net/Vf3AJ/
Example from: http://www.cssnewbie.com/example/css-dropdown-menu/horizontal.html
EDITED
Misread horizontal for vertical. tested in IE10, FF, and Chrome
As a side note: horizontal menus have serious issues depending on the width of the viewers screen.
CSS
nav {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
nav li {
list-style: none;
float: left;
}
nav li a {
display: block;
padding: 3px 8px;
text-transform: uppercase;
text-decoration: none;
color: #999;
font-weight: bold;
}
nav li a:hover {
background: blue;
color: white;
}
nav li ul {
display: none;
}
nav li:hover ul, nav li.hover ul {
position: absolute;
display: inline;
left: 0;
width: 100%;
margin: 0;
padding: 0;
}
nav li:hover li, nav li.hover li {
float: left;
}
nav li:hover li a, navbar li.hover li a {
color: #000;
}
nav li li a:hover {
color: white;
}
HTML
<div id="navigationContainer">
<nav id="navigation">
<ul>
<li class="borderleft">Home
</li>
<li>Register
</li>
<li>Search cars
</li>
<li>Display all cars
</li>
<li>Member Actions
<ul>
<!-- Open drop down menu -->
<li class="bordertop">Login
</li>
<!-- A bordertop class is given to this listed element in order to style a top border for in in the external CSS file. -->
<li class="floatLeft">Member Area
</li>
<li>Reservation
</li>
</ul>
</li>
<li>Contact us
</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car
</li>
<li>Delete a car
</li>
</ul>
</li>
</ul>
</nav>
</div>
I have a drop down menu list made in css and plain HTMl. It works fine but it rolls under my image slider , and I can see on a part of the menu when i hover on any of my menu. I think z-index property is missing somewhere. But I used in my ul li tag but no use.
html
<ul id="menu">
<li>Home</li>
<li>About Us
<ul>
<li>The Team</li>
<li>History</li>
<li>Vision</li>
</ul>
</li>
<li>Products
<ul>
<li>Cozy Couch</li>
<li>Great Table</li>
<li>Small Chair</li>
<li>Shiny Shelf</li>
<li>Invisible Nothing</li>
</ul>
</li>
<li>Contact
<ul>
<li>Online</li>
<li>Right Here</li>
<li>Somewhere Else</li>
</ul>
</li>
</ul>
css
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul { display: none; }
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover { background: #617F8A; }
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #617F8A; }
li:hover li a:hover { background: #95A9B1; }
image slider has z-index property from java-script. so it will take high priority.
You need to give z-index to your navigation also.
Is your image slider having jQuery?
Than you have to put z-index in li ul li{z-index:999px;}.
If you add z-index to the following class.
li:hover ul {
display: block;
position: absolute;
z-index:1000;
}
Also make sure that the z-index for the menu is having higher property.