I am using wordpress on my site, marblesandmore.com, and have a theme that I currently am adjusting.
The website is using a menu function build in to wordpress and the items use cufon and css.
The problem is the following:
- the last 2 items have an offset...?
- This is only visible in chrome and IE.
The php used:
<div id="menu">
<?php $menuClass = 'nav superfish clearfix';
$menuID = 'secondary-menu';
$secondaryNav = '';
if (function_exists('wp_nav_menu')) {
$secondaryNav = wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'container' => '', 'fallback_cb' => '', 'menu_class' => $menuClass, 'menu_id' => $menuID, 'echo' => false, 'walker' => new description_walker() ) );
};
if ($secondaryNav == '') { ?>
<ul id="<?php echo $menuID; ?>" class="<?php echo $menuClass; ?>">
<?php if (get_option('estore_swap_navbar') == 'false') { ?>
<?php show_categories_menu($menuClass,false); ?>
<?php } else { ?>
<?php if (get_option('estore_home_link') == 'on') { ?>
<li <?php if (is_home()) echo('class="current_page_item"') ?>><?php esc_html_e('Home','eStore') ?></li>
<?php }; ?>
<?php show_page_menu($menuClass,false,false); ?>
<?php } ?>
</ul> <!-- end ul#nav -->
<?php }
else echo($secondaryNav); ?>
</div> <!-- #menu -->
Css:
ul#secondary-menu { padding: 24px 0px 0px 23px; margin-top:24px; }
ul#secondary-menu li { padding-right: 20px; }
ul#secondary-menu li.current_page_item > a > strong, ul#secondary-menu li.current-menu-item > a > strong { color:#ede7c2; }
ul#secondary-menu li a strong { color:#000000; text-transform: lowercase; font-size:16px; font-weight:normal; text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3); margin-bottom:-3px; }
ul#secondary-menu li a span { color: #828282; font-family: arsmaquettepro,Helvetica, sans-serif; /*text-shadow: 1px 1px 1px #2d2d2d;*/ }
ul#secondary-menu li a:hover { text-decoration: none; }
ul#secondary-menu li a:hover strong { color: #ede7c2; }
ul#secondary-menu li a:hover span, ul#secondary-menu li > a > span { color: #7b786a; }
There should be no difference between the first 4 items and the next 2.
Any idea what causes the offset?
Marblesandmore.com
EDIT: The answer below appears to be right, so the solution has to be in the css of the submenu:
ul#secondary-menu ul { width: 178px; background: url(images/secondary-dropdown.png) repeat-y; padding: 3px 0px 15px; box-shadow: 3px 6px 7px 1px rgba(0, 0, 0, 0.5); -moz-box-shadow:3px 6px 7px 1px rgba(0, 0, 0, 0.5); -webkit-box-shadow: 3px 6px 7px 1px rgba(0, 0, 0, 0.5); border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-top-left-radius: 0px; -moz-border-radius-topleft: 0px; -webkit-border-top-left-radius: 0px; border-top-right-radius: 0px; -moz-border-radius-topright: 0px; -webkit-border-top-right-radius: 0px; border: 1px solid #ffffff; border-top: none; }
ul#secondary-menu li:hover ul, ul#secondary-menu li.sfHover ul { left:0px; top:43px; }
ul#secondary-menu li:hover ul ul, ul#secondary-menu li.sfHover ul ul { left:173px; top:-3px; border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; border: 1px solid #232323; }
ul#secondary-menu ul li { background: url(images/secondary-dropdown-bottom.png) repeat-x bottom left; padding: 0px 0px 2px 2px; }
ul#secondary-menu ul li a { display: block; padding: 9px 3px 9px 28px; width: 145px; /*font-weight: bold; */font-size:14px; color: #000000; font-family: arsmaquettepro, Helvetica, Arial, sans-serif; /*text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3); background: url(images/secondary-dropdown-bullet.png) no-repeat 15px 17px;*/ }
ul#secondary-menu ul li a:hover { background-color: #383838; color: #ede7c2; }
I think your problem may be is caused by:
margin-bottom:-3px;
in
ul#secondary-menu li a strong
selector.
I can't see your page, so im not sure about that answer.
The last 2 object only have a 16px height while the other menu objects got 18px.
edit: Sorry i just realized how bad this answer is without telling you where the problem is.. Will try to check it.
i think it has something to do with the fact that the last 2 menu items has no submenus, somehow those ul tags for the submenus seem to add 2px to the height.
Ok, this is not a "nice" solution, rather ugly to be honest, but i think it works. You can just target the 2 last items in the menu by using their id's and adding a margin at the top.
#menu-item-3606, #menu-item-3604 {
margin-top: 2px;
}
just remember that if u ever change those menu items in any way, they will have new identifiers so you would need to change the id's in the css. As I said, not a good solution but it works.
There would also be problem if you for some reason added submenus to these two menu items.
#Bart van Sleeuwen Please Remove this class from style.css
ul#secondary-menu li#menu-item-3604 strong { color:#666666; }
ul#secondary-menu li#menu-item-3606 strong { color:#666666; }
and Find the li class in html
<li id="menu-item-3604" class="menu-item menu-item-type-post_type menu-item-object-page">
change it to like this
<li id="menu-item-3604" class="menu-item menu-item-type-custom menu-item-object-custom">
Related
I am trying to create a multi level submenu.
I can display just one sub level menu with this code.
How to increase the code to insert a system with parent id ?
There my code than I am trying to develop.
<style>
* {
margin: 0;
padding: 0;
}
body {
font-family: "Comic Sans MS", cursive;
font-size: 15px;
color: #232323;
}
#head {
background: #f9f9f9;
height: 100px;
padding-top: 15px;
border-bottom: 1px solid #d5dce8;
}
.wrap {
width: 1000px;
margin: 0 auto;
}
#head h1
{
float:left;
}
#head a
{
float:right;
}
input,select
{
width:300px;
height:35px;
}
/* nav menu */
#nav {
margin: 0;
padding: 0;
list-style: none;
border-left: 1px solid #d5dce8;
border-right: 1px solid #d5dce8;
border-bottom: 1px solid #d5dce8;
border-bottom-left-radius: 4px;
-moz-border-radius-bottomleft: 4px;
-webkit-border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
-moz-border-radius-bottomright: 4px;
-webkit-border-bottom-right-radius: 4px;
height: 50px;
padding-left: 15px;
padding-right: 15px;
background: #f9f9f9;
}
#nav li {
float: left;
display: block;
background: none;
position: relative;
z-index: 999;
margin: 0 1px;
}
#nav li a {
display: block;
padding: 0;
font-weight: 700;
line-height: 50px;
text-decoration: none;
color: #818ba3;
zoom: 1;
border-left: 1px solid transparent;
border-right: 1px solid transparent;
padding: 0px 12px;
}
#nav li a:hover, #nav li a.hov {
background-color: #fff;
border-left: 1px solid #d5dce8;
border-right: 1px solid #d5dce8;
color: #576482;
}
/* subnav */
#nav ul {
position: absolute;
left: 1px;
display: none;
margin: 0;
padding: 0;
list-style: none;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
-o-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
padding-bottom: 3px;
}
#nav ul li {
width: 180px;
float: left;
border-top: 1px solid #fff;
text-align: left;
}
#nav ul li:hover {
border-left: 0px solid transparent;
border-right: 0px solid transparent;
}
#nav ul a {
display: block;
height: 20px;
line-height: 20px;
padding: 8px 5px;
color: #666;
border-bottom: 1px solid transparent;
text-transform: uppercase;
color: #797979;
font-weight: normal;
}
#nav ul a:hover {
text-decoration: none;
border-right-color: transparent;
border-left-color: transparent;
background: transparent;
color: #4e4e4e;
}
</style>
<script type="text/javascript">
$(document).ready(function()
{
$('#nav li').hover(function()
{
$('ul', this).slideDown('fast');
}, function()
{
$('ul', this).slideUp('fast');
});
});
</script>
<div class="wrap">
<ul id="nav">
<?php
// Select all entries from the menu table
$Qmenus = $Db->prepare('SELECT a.id,
a.link,
a.parent,
a.class,
a.sort_order,
amd.label
FROM :table_administrator_menu a,
:table_administrator_menu_description amd
where a.id = amd.id
and amd.language_id = :language_id
ORDER BY a.parent,
a.sort_order
');
$Qmenus->bindInt(':language_id', $OSCOM_Language->getId());
$Qmenus->execute();
while($Qmenus->fetch()){
?>
<li class="<?php $Qmenus->value('class'); ?>"><?php echo $Qmenus->value('label'); ?>
<?php
// Select all entries from the menu table
$QsubMenus = $Db->prepare('SELECT sm.id,
sm.link,
sm.parent,
sm.class,
smd.label,
sm.sort_order
FROM :table_administrator_sub_menu sm,
:table_administrator_sub_menu_description smd
where sm.sub_menu_id = smd.sub_menu_id
and smd.language_id = :language_id
order by sm.parent,
sm.sort_order
');
$QsubMenus->bindInt(':language_id', $OSCOM_Language->getId());
$QsubMenus->execute()
?>
<ul>
<?php
while($QsubMenus->fetch()) {
?>
<li class="<?php $QsubMenus->value('class'); ?>"><?php echo $QsubMenus->value('label'); ?></li><?php
}
?>
</ul>
</li>
<?php
}
?>
</ul>
</div>
I have a menu with some css on it.
I activate it when the page is active
<li <?php echo (strpos(current_url(), 'history') !== false) ? "class='active'" : ""; ?>>
History
</li>
I also have css for menu it self when is hover and focus
.side-nav li a:hover,
.side-nav li a:focus {
outline: none;
background-color: #f8f8f8 !important;
font-weight: bold;
border-left: 6px solid #337AB7;
-webkit-box-shadow: -4px 4px 6px -4px #a5a5a5;
box-shadow: -4px 4px 6px -4px #a5a5a5;
}
And class active is
.side-nav li.active{
background-color: #f8f8f8 !important;
font-weight: bold;
border-left: 6px solid #337AB7;
-webkit-box-shadow: -4px 4px 6px -4px #a5a5a5;
box-shadow: -4px 4px 6px -4px #a5a5a5;
}
My problem is when active class is active and i hover over the menu bar i have 2 borders on that element.
How can i remove the second border when element is active?
Your problem is, that you are accessing two different elements with your css. With the first definition you are accessing the pseudo-selectors :focus and :hover on any a element within a li element in your .side-nav. With the second definition you are only accessing the li element, and not the contained a element. Defining your .active class as follows should fix your problem:
.side-nav li.active a {
background-color: #f8f8f8 !important;
font-weight: bold;
border-left: 6px solid #337AB7;
-webkit-box-shadow: -4px 4px 6px -4px #a5a5a5;
box-shadow: -4px 4px 6px -4px #a5a5a5;
}
Can anyone suggest what might be the problem on my flickering menu bar?
Please suggest anything that will make the flickering of menu bar stop.
Thanks much!
#mainmenu{
margin-bottom: 2.5em;
}
.menubar{
position: fixed;
top:0;
left:0;
max-height:10em;
width:100%;
list-style: none;
background-color:#333333;
text-align: left;
margin:0;
padding: 0;
z-index: 1;
border-bottom: 1px solid #ccc;
}
.menubar .first {
margin-left: 1em;
}
.menubar li{
position: relative;
display: inline-block;
width:15em;
text-align: center;
font-family: 'Oswald', sans-serif;
font-size: 1em;
border-bottom: none;
cursor: pointer;
}
.menubar li:hover{
background-color:#6666ff;
}
.menubar a{
display: block;
padding: 0.5em 0.5em 0.5em 0.5em;
text-decoration: none;
color:#ffffff;
}
/* for submenus */
.menubar .first .submenubar {
padding: 0;
position: absolute;
top:2em;
left:0;
width:auto;
display: none;
-webkit-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
-moz-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
}
.menubar li .submenubar li {
text-align: left;
list-style-type: none;
background-color:brown;
display: block;
color:#fff;
}
.menubar > li > .submenubar > li:hover {
background-color:black;
}
.menubar li:hover .submenubar{
display: block;
}
See this JsFiddle for my complete code.
I suspect that one of 2 things are happening.
Is the whole header "flickering" when you go to a new page? If so,
that's because you are building an html page from your php on the
server and then rendering the page again. Sometimes this will flash.
Sucks.
The sub-menu appears to "flicker" because it's broken and when you
try and hove over it, it disappears.
If it's 1, you can use caching to try and lessen the chances of this happening, or you can learn how to use ajax, or a js framework to build single page apps, but that's a lot of work.
If it's 2, then this code I'll include below, and this fiddle - will set you up with some more solid code to work with.
My real advice, is to just never use drop-down menus. They are a terrible interface pattern.
HTML
<nav class='container navigation'>
<div class='inner-w'>
<ul class='menu'>
<li>
<a href='#'>Top-level menu item 1</a>
<ul class='sub-menu'>
<li><a href='#'>Sub-menu item 1</a></li>
<li><a href='#'>Sub-menu item 2</a></li>
<li><a href='#'>Sub-menu item 3</a></li>
<li><a href='#'>Sub-menu item 4</a></li>
</ul>
</li>
<li><a href='#'>Top-level menu item 2</a></li>
<li>
<a href='#'>Top-level menu item 3</a>
<ul class='sub-menu'>
<li><a href='#'>Sub-menu item 1</a></li>
<li><a href='#'>Sub-menu item 2</a></li>
</ul>
</li>
<li><a href='#'>Top-level menu item 4</a></li>
</ul>
</div>
</nav>
CSS
/* global-structure */
.container {
width: 100%;
float: left;
}
.container .inner-w {
margin-right: auto; margin-left: auto;
max-width: 900px; /* arbitrary */
/* this should have a clear-fix */
}
/* menu styles */
.menu, .menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
}
.menu > li { /* just the top-level li */
position: relative;
/* so the sub-menu can be positioned to this */
border-right: 1px solid rgba(0,0,0,.3)
}
.menu > li:last-child {
border-right: 0;
}
.menu a {
display: block;
padding: .8rem .5rem;
background: #eee;
min-width: 160px;
color: inherit;
text-decoration: none;
}
.sub-menu {
position: absolute;
top: 100%;
left: 0;
height: 0;
width: 0; /* just hide it visually */
overflow: hidden;
z-index: 5; /* arbitrary, keep them small though... */
}
.sub-menu li {
clear: left;
border-bottom: 1px solid rgba(0,0,0,.3)
}
.sub-menu li:last-child {
border-bottom: 0;
}
.sub-menu a {
background: #ccc;
}
.sub-menu a:hover {
background: #aaa;
}
.menu > li:hover .sub-menu {
height: auto;
width: auto;
}
If I was absolutely forced to write a drop-down menu, It would have to be like this: http://codepen.io/sheriffderek/pen/qdBryb/?editors=010
this is my menu code in html which works fine, all classes and database references works fine only sliding down does not work
<script src="<?php echo JS ?>main.js"></script>
<nav id="top_nav" class=" clearfix">
<ul class="container clearfix">
<?php
foreach ($meni as $kat): ?>
<li role="">
<a href="<?php echo base_url()?> ">
<?php echo $kat['title']; ?>
</a>
<ul class="top_nav_lv2 clearfix">
<?php foreach ($pod_meni as $pat) : ?>
<?php if($pat['meni_id'] == $kat['id_meni']): ?>
<li>
<?php echo $pat['title'] ?>
</li>
<!-- KRAJ IF USLOVA -->
<?php endif; ?>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</nav>
<!-- END OF NAV -->
sliding down does not work and there is no error report
heres my js code
var meni = $('#top_nav');
meni.on('mouseenter', 'li', function(){
document.find('ul').style.display = 'block';
($(this).find('ul').stop().slideDown('fast'));
})
.on('mouseleave', 'li', function(){
($(this).find('ul').stop().slideUp('fast'));
});
and here is css
#top_nav{float: right;width: 61%}
nav ul {margin-top: 0}
nav ul li {float: left;display: inline-block;padding: 39px 20px 40px 20px;border-right: 1px solid transparent;position: relative;}
nav ul li:hover{background: url(../../img/resursi/meni_hover.png);border-right: 1px solid white;-moz-box-shadow: inset 6px 0 7px -7px #000;-webkit-box-shadow: inset 6px 0 7px -7px #000;box-shadow: inset 6px 0 7px -7px #000;}
.current {background: url(../../img/resursi/meni_hover.png);border-right: 1px solid white;-moz-box-shadow: inset 6px 0 7px -7px #000;-webkit-box-shadow: inset 6px 0 7px -7px #000;box-shadow: inset 6px 0 7px -7px #000;}
nav ul li a {color:#666666 ;text-decoration: none;font-family: georgia;}
nav ul li a:hover { color:#d10000 ;}
nav ul.top_nav_lv2 {clear: both; margin: 0; padding: 0px 0 0 0 ; display: none; background: red;position: absolute;left: 0; top:0px; z-index: 100;}
nav ul.top_nav_lv2 li {display: block; margin:0 0px 0 0px; padding: 0px 0 0px 10px;font-size: 14px;width: 140px; z-index: 1000;border-bottom: 2px solid transparent;}
nav ul.top_nav_lv2 li:hover {border-bottom: 2px solid transparent;background: rgba(255,255,255,0.07);}
nav ul.top_nav_lv2 li a {float: left; width: 120px; border-bottom: 2px solid transparent;padding: 8px 0 8px 10px;}
nav ul.top_nav_lv2 li a:hover {border-bottom: 2px solid rgba(255,255,255,0.6);}
This line is useless :
document.find('ul').style.display = 'block';
in :
meni.on('mouseenter', 'li', function(){
document.find('ul').style.display = 'block';
($(this).find('ul').stop().slideDown('fast'));
})
Try to comment It, this should work.
And for esthetic matter:
nav ul.top_nav_lv2{
top:80px;
}
I am having trouble with the layout of a website I'm making.
I'm not very good with CSS.
So the trouble I'm having is that I want to have a horizontal menu bar that I want to center in my website. This menu can have dropdown children.
The implementation is in jQuery.
So this is the HTML code of my menu bar :
<ul class='dropdown'>
<li><a href='index.php'>Home</a></li>
<li><a href='#'>Incident</a>
<ul class='sub_menu'>
<li><a href='index.php?action=new'>New</a></li>
<li><a href='index.php?action=edit'>Edit</a></li>
<li><a href='index.php?action=manage'>Manage</a></li>
</ul>
</li>
<li><a href='action_logout.php'>Log out</a></li>
</ul>
and this is the CSS that is being implemented :
* { margin: 0; padding: 0; }
body { font: 14px Helvetica, Sans-Serif; margin: 15px; }
a { text-decoration: none; }
ul { width: 800px; list-style: none; text-align: center; margin: auto; padding: 2px 2px;}
p { margin: 15px 0; }
/*
LEVEL ONE
*/
ul.dropdown { position: relative; }
ul.dropdown li { display: inline; font-weight: bold; background: #ccc; padding: 2px 2px; border-bottom: 1px solid #777; }
ul.dropdown a:hover { color: #000; }
ul.dropdown a:active { color: #ffa500; }
ul.dropdown li a { display: inline; padding: 2px 8px; border-right: 1px solid #777; border-bottom: 1px solid #777;
color: #222; }
ul.dropdown li:last-child a { border-right: none; } /* Doesn't work in IE */
ul.dropdown li.hover,
ul.dropdown li:hover { background: #F3D673; color: black; position: relative; }
ul.dropdown li.hover a { color: black; }
/*
LEVEL TWO
*/
ul.dropdown ul { width: 175px; visibility: hidden; position: absolute; top: 100%; left: 0; text-align: left; }
ul.dropdown ul li { font-weight: normal; background: #f6f6f6; color: #000;
border-bottom: 1px solid #ccc; float: none; }
/* IE 6 & 7 Needs Inline Block */
ul.dropdown ul li a { border-right: none; width: 100%; display: inline-block; }
An Example can be seen here.
I did manage to center my menu bar after all. However there seems to be a little gap between Home and Incident menus and I've no idea how to get rid of it.
Any ideas?
Thank you in advance.
Somehow you managed to put whitespace outside <li> element, here is absolutely same code with whitespace removed:
http://jsfiddle.net/fPAFs/1/
How about this: http://dabblet.com/gist/2520870
Your code was a mess.
<style>
* {
padding: 0;
margin: 0;
}
body {
font-family: helvetica, serif;
font-size: 14px;
}
ul {
list-style-type: none;
}
.dropdown {
text-align: center;
font-size: 0;
margin: 15px;
}
ul.dropdown ul {
width: 220px;
visibility: hidden;
position: absolute;
top: 1.8em;
left: 0;
}
ul.dropdown ul li a {
font-weight: normal;
background: #f6f6f6;
color: #000;
border-bottom: 1px solid #ccc;
float: none;
}
.dropdown > li {
display: inline-block;
height: 1.2em;
font-size: 14px;
position: relative;
}
.dropdown li a {
display: block;
background: rgb(204, 204, 204);
border-bottom: rgb(119, 119, 119) 1px solid;
border-right: rgb(119, 119, 119) 1px solid;
padding: 0.3em;
color: rgb(0, 0, 0);
text-decoration: none;
font-weight: bold;
}
.dropdown li a:hover {
background: rgb(243, 214, 115);
}
</style>
<ul class='dropdown'>
<li><a href='index.php'>Home</a></li>
<li><a href='#'>Incident</a>
<ul class='sub_menu'>
<li><a href='index.php?action=new'>New</a></li>
<li><a href='index.php?action=edit'>Edit</a></li>
<li><a href='index.php?action=manage'>Manage</a></li>
</ul>
</li>
<li><a href='action_logout.php'>Log out</a></li>
</ul>
Try this new code. Though I urge you to not try and implement someone else's code without understanding it first!