For some reason my menu items keep having some spacing left and right between the menu items..! While I'm kind of sure I havent programmed this..?
Anyone know why there is like 3 pixels spacing between my menu items?
http://jsfiddle.net/skunheal/ceFSJ/
HTML:
<div id="menu">
<ul id="nav">
<li class="page_item page-item-13">
Contact
</li>
<li class="page_item page-item-5 current_page_item">
Home
</li>
<li class="page_item page-item-7">
Nieuws
</li>
</ul>
</div>
CSS:
#nav, #subNav {
list-style: none;
padding-left: 0px;
margin: 0px;
}
#nav li, #subNav li {
display: inline;
padding:0px;
}
/* Currently selected page nav item (and parent) if applicable */
.current_page_item a,
.current_page_parent a {
text-decoration: none;
font-family:futura;;
color:#CCC;
}
.page_item a{
text-decoration: none;
font-family:futura;;
color:#FFFFFF;
display:inline-block;
background:#00C;
line-height:30px;
width:120px;
height:30px;
}
#menu{
height:30px;
text-align:center;
}
Thanx in advance,
Greetings,
Merijn!
You've set the display of lis to inline. So, the spaces between your li tags (the line-breaks and indentions) behave like spaces between words. Just remove the spaces and make it like this:
<div id="menu">
<ul id="nav">
<li class="page_item page-item-13">Contact</li><li class="page_item page-item-5 current_page_item">Home</li><li class="page_item page-item-7">Nieuws</li>
</ul>
</div>
You can also fix it with setting font size of ul to zero and setting it again on lis.
Try removing all the white space from between the <ul> and <li> items.
Either have them in a single line, or split over the lines like this...
<ul id="nav"><li class="page_item page-item-13">Contact</li
><li class="page_item page-item-5 current_page_item">Home</li
><li class="page_item page-item-7">Nieuws</li
></ul>
Update
Based on your JSFiddle... here is the same fiddle with the white space removed
Related
I'm building a css dropdown menu and have been unable to get the submenus to appear below their respective parent li elements. I've tried a bunch of the solutions suggested in response to similar questions but have been unable to get them to work.
Here's a sample of the menu I'm building:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Menu Test</title>
<link rel="stylesheet" href="menustyle.css" type="text/css">
</head>
<body>
<div id="menudiv">
<ul class="menu">
<li class="menuitem">Aluminum</li>
<ul class="submenu">
<li class="subitem">Round</li>
<li class="subitem">Sheet</li>
<li class="subitem">Plate</li>
</ul>
</li>
<li class="menuitem">Copper</li>
<ul class="submenu">
<li class="subitem">Round</li>
<li class="subitem">Sheet</li>
</ul>
<li class="menuitem">Steel</li>
</ul>
</div>
</body>
</html>
And here's the css:
#menudiv {
text-align:center;
}
ul.menu {
list-style-type:none;
}
li.menuitem {
position:relative;
display:inline-block;
}
ul.submenu {
display:none;
position:absolute;
}
.menuitem:hover+ul.submenu {
display:block;
}
I can move the submenus around by adding things like right:50px; to ul.submenu, but that moves all the submenus to the same location.
What am I missing here? Thanks!!
Here's a Fiddle.
First of all, the following markup structure :
<li class="menuitem">Aluminum</li>
<ul class="submenu">
<li class="subitem">Round</li>
<li class="subitem">Sheet</li>
<li class="subitem">Plate</li>
</ul>
is incorrect. It should be :
<li class="menuitem">Aluminum
<ul class="submenu">
<li class="subitem">Round</li>
<li class="subitem">Sheet</li>
<li class="subitem">Plate</li>
</ul>
</li>
Secondly, you could use a CSS reset for ul,li elements. For the sake of simplicity I've used :
* {
margin: 0;
padding: 0;
}
Now, coming to your question. the following classes needs to be changed :
.menuitem:hover+ul.submenu {
display:block;
}
to
.menuitem:hover > ul.submenu {
display:block;
}
and
ul.submenu {
display:none;
position:absolute;
top:0px;
right:50px;
}
to
ul.submenu {
display:none;
position:absolute;
}
You can then modify the following class (so that the child ul elements "fits-in" to the parent li):
li.menuitem {
position:relative;
display:inline-block;
}
to
li.menuitem {
position:relative;
display:inline-block;
padding: 5px 10px;
margin: 0 10px;
}
In summary, I guess this is what you are looking for :
* {
margin: 0;
padding: 0;
}
#menudiv {
text-align:center;
}
ul.menu {
display: inline-block;
list-style-type:none;
}
li.menuitem {
position:relative;
display:inline-block;
padding: 5px 10px;
margin: 0 10px;
}
ul.submenu {
display:none;
position:absolute;
}
.menuitem:hover > ul.submenu {
display:block;
}
<body>
<div id="menudiv">
<ul class="menu">
<li class="menuitem">Aluminum
<ul class="submenu">
<li class="subitem">Round</li>
<li class="subitem">Sheet</li>
<li class="subitem">Plate</li>
</ul>
</li>
<li class="menuitem">Copper
<ul class="submenu">
<li class="subitem">Round 2</li>
<li class="subitem">Sheet 2</li>
</ul>
<li class="menuitem">Steel</li>
</ul>
</div>
</body>
Hope this helps!!!
Try placing the <ul class="submenu"> inside the <li class="menuitem">. Then set the <li> to position:relative; and set the <ul> to position:absolute;left:0;. This will position the <ul> relative to its parent element, the <li>.
Here's a codepen example: http://codepen.io/anon/pen/WQdMjX
Your markup is incorrect for nesting a sub-list.
You're doing this:
<ul>
<li>text</li><!-- incorrect, don't close li here -->
<ul>
<li>sub</li>
</ul>
</li><!-- correct, though li is already closed -->
<li>text</li><!-- incorrect, don't close li here -->
<ul>
<li>sub</li>
</ul>
<!-- needs closing li here -->
<li>text</li>
</ul>
Instead do this:
<ul>
<li>text
<ul>
<li>sub</li>
</ul>
</li>
</ul>
Then update your CSS selector from .menuitem:hover + ul.submenu to .menuitem:hover > ul.submenu as you're no longer selecting a sibling element (+) but a child element (>).
You'll need to fine tune the positioning of your sub-menus from here but this should get you where you need to be.
Remember, when you are developing menus you need to make sure the link content is inside anchor tags, including the links at the top level navigation that launch the subnav. That way these links are natively focusable. You want to be able to reach these menu elements with a keyboard only since many with arthritis, Parkinson's disease, etc. may be unable to use a mouse (and you won't want to use tabindex to mimic this behaviour since screen-readers will look for anchor tags.)
There was a similar StackOverflow question yesterday: Absolutely positioned child's top edge pinned to the bottom edge of its parent that has unknown height?
You can also Bootstrap Dropdown CSS in a normal case too.
The same html/css is returning very different results... What's going on here?
I have included all of the relevant CSS and the entire HTML markup for the page so you can see the structure. You can find the html for the search bar down near the bottom of the included code where "search1.png" is.
I've already been having a problem with the drop-down menus rendering at slightly different sizes/positions between the two browsers and I suspect it is because they render the text in side the main navigation items in slightly different ways.
Any insight would be greatly appreciated!!
FIREFOX:
CHROME:
nav ul{
text-align:right;
font-size:0;
list-style-type: none;
}
nav ul li{
display:inline-block;
height:54px;
padding:0 20 0 20;
background:white;
color:black;
text-align: center;
vertical-align: middle;
line-height: 54px;
font-size:15;
}
nav ul li:hover{
background:#222;
color:white;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul ul {
position: absolute;
padding-top:15px;
padding-bottom:15px;
padding-left:0px;
background:#222;
z-index:100;
border-bottom-left-radius:5px;
border-bottom-right-radius:5px;
overflow:hidden;
}
/* SEARCH */
li.red:nth-child(7) > ul:nth-child(1){
width: 328px;
margin-left: -277px;
text-align: center;
margin-top: 54px;
vertical-align: middle;
padding-top:15px;
padding-bottom:15px;
position:relative;
}
HTML:
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>SENECA AV</title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<div id="top" class="bars"><img src="senecalogo1.png" alt="SENECA">
<nav>
<ul>
<li> PRODUCTS
<ul>
<li></li>
</ul>
</li>
<li> CATALOG
<ul class="left">
<li>STUFF</li>
<li>THINGS</li>
</ul>
</li>
<li> SHOP
</li>
<li class="red"> COMPANY
</li>
<li class="red"> HELP
<ul>
<li> Ask a question </li>
<li> Register your product </li>
<li> Returns/Exchanges </li>
<li> Warranty </li>
<li> FAQ </li>
</ul>
</li>
<li class="red"> TRADE
<ul>
<li> Open an account </li>
<li> Online Retailers </li>
<li> Retail Stores </li>
<li> Contract </li>
</ul>
</li>
<li class="red" style="padding:0 8 0 8;background-image:url('search1.png');width:43px;background-repeat:no-repeat;background-position:center;">
<ul>
<input type="text" value="item, number, SKU">
<input type="submit" value="search">
</ul>
</li>
<li class="red" style="padding:0 15 0 0;">
</li>
</ul>
</nav>
</div>
<div id="bottom" class="bars"></div>
</body>
</html>
After a bunch of fooling around I found the issue. It was slightly complicated which is probably why I couldn't see a solution sooner.
I was missing a DOCTYPE declaration at the top of the page.
Adding this instantly broke the page and made the entire navigation disappear because I wasn't properly declaring CSS size values. A quick look at the console explained which properties were at issue allowing me to fix them all one by one.
for example:
padding:0 20 0 20;
needs to be
padding:0px 20px 0px 20px;
Once all relevant properties had 'px' appended to their values the menu items reappeared.
Also,
nav ul ul {
line-height:15px;
}
needed to be added to get rid of the riduculous over-padding apparent in the Chrome example above which also appeared in Firefox once the DOCTYPE was added because...
line-height:54px;
was being inherited from the parent li (nav ul li)
I have a menubar made of li elements, each floating left to have them side-by-side.
This works on on most brwsers but not on my customer's firefox (mac version 26)
the li are a bit larger making them overflow at the end of the line (10px together probably)
Any idea why? I have a css reset and margin and padding are set to a value.
this is html:
<ul id="menu">
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=projets-realisations">projets-realisations</a>
<ul class="subMenu">
<li class="subMenuItem"><a class="subMenuItemLink" href="interface.php?type=architecture&page=projets-realisations-en-resume">En résumé</a></li>
<li class="subMenuItem"><a class="subMenuItemLink" href="interface.php?type=architecture&page=projets-realisations-az">De A à Z</a></li>
</ul>
</li>
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=portes-parquets-escaliers">Portes-parquets-escaliers</a> </li>
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=cuisines-salles-de-bain">cuisines-salles de bain</a> </li>
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=decoration-tentures">decoration-tentures</a> </li>
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=de-ville-en-ville">de ville en ville</a> </li>
<li class="menuItem"><a class="menuItemLink" href="interface.php?type=architecture&page=espace-animalier">espace animalier</a> </li>
</ul>
css:
.menuItem {float:left; cursor: default; position: relative; margin-left:4px; padding:0px; margin-right:0px;}
.menuItem:last-child {margin-right:-50px;}
.menuItemLink {line-height: 20px; color: #ffffff; text-transform: uppercase; font-size: 13px; padding-left:5px; padding-right: 5px; text-decoration: none;}
The margin-right -50 is just to mae sure the last elements doesn't goes on a new line...
Why is it miscalculated by his firefox? The strangest thing is I tried the same firefox version on a mac (different osversion) and don't have this issue.
You need to increase the right margin for menuItem
margin-right: 15px;
You can check the http://jsfiddle.net/raunakkathuria/vRns2/
If you don't need the list style add to .menu
list-style-type: none;
and display: inline-block to .menuItem then you don't have to play with margin
Tried all your suggestions, but didn't worked, after all replaced all paddings by combined margins, now everything is ok
I have a <ul> list on my website that contains some sub menus. It is structured in this way:
<div id="cssmenu">
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>RNG</span></a>
<ul>
<li><a href='#'><span>menu 1</span></a></li>
<li><a href='#'><span>menu 1</span></a></li>
<li class='last'><a href='#'><span>menu 1</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Altro</span></a>
<ul>
<li><a href='#'><span>kldajofa</span></a></li>
<li class='last'><a href='#'><span>Altro12</span></a></li>
</ul>
</li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
I have 4 <li> as you can see and I'd like to see them center-aligned with the width of the screen, but I don't know how to do it.
You can see a fiddle here that contains the CSS too. How can center align the names I have on my menu?
Assuming there are only 4 li - as in the example, set width:25%.
Working jsFiddle here
#cssmenu li {
float: left;
padding: 0px;
width: 25%;
}
I made a minor update so that the sub-nav menu items are also 25%..
jsFiddle here
There were set to width:225px;.
#cssmenu li ul {
width: 25%;
}
Considering you have only 4 menu items, you just need to add :
#cssmenu > ul > li { width:25%; }
This will set the width of the list items to 25%. And since the a are set to be displayed as blocks, they will fit the whole width of the li.
Note that we are using the direct child selector > because we don't want this effect to be applied to the menu lis inside the sub-menu. We only need that effect on the root level.
Other possible solution is to use flexbox which isn't well supported yet and cannot be used without polyfill.
If the li are display:inline-block you can apply text-align:center to the ul and the list items will center regardless of the number (provided there is room on the line).
The good news is that there are no clearing issues.
JSFiddle
I've just added width to li and it works now.
Check JsFiddle
#cssmenu li a {
background: #0D0D0D bottom right no-repeat;
display: block;
font-weight: normal;
line-height: 35px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
width:70px;
}
I'm trying to make a side-menu in wordpress, which is going nicely, but for some reason the css is being a pain and I can't seem to wrap my head around it.
The navigation looks like this:
<nav>
<ul id="sidebar-menu">
<li class="page_item page-item-8 current_page_item">Diensten</li>
<li class="page_item page-item-32">Dienst 1</li>
<li class="page_item page-item-33">Dienst 2</li>
<li class="page_item page-item-36">Dienst 3</li>
</ul>
</nav>
The css for this looks like this:
#left-side nav a:hover, #left-side nav .current_page_item{
border-left:10px #b8d276 solid;
border-right:none;
padding-left:10px;
font-style: italic;
}
Now when one of the items is "selected" (having the .current_page_item-tag) the hover is again applied, what shouldn't happen, it should just stay the same.
On the following page you can see it in action: http://www.consana.nl/en/diensten/
Any help would be appreciated!
Because <li> has default border-left and you are styling anchor elements.
#left-side nav li:hover, #left-side nav .current_page_item{
border-left:10px #b8d276 solid;
border-right:none;
padding-left:10px;
font-style: italic;
}