I love the jQuery UI stuff!
I like the navigation menu, but I can't seem to get it horizontal. I've got to be missing something that's a cinch.
Anyone know how to change the CSS? I tried this but it is for an older version and doesn't work, since there is no longer "clear" to keep them on top of each other.
Relevant CSS:
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
.ui-menu .ui-menu-item { margin: 0; padding: 0; zoom: 1; width: 100%; }
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
.ui-menu .ui-menu-item a.ui-state-focus,
.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
.ui-menu .ui-state-disabled a { cursor: default; }
Thanks for the help!
I admire all these efforts to convert a menu to a menubar because I detest trying to hack CSS. It just feels like I'm meddling with powers I can't possibly ever understand! I think it's much easier to add the menubar files available at the menubar branch of jquery ui.
I downloaded the full jquery ui css bundled file from the jquery ui download site
In the head of my document I put the jquery ui css file that contains everything (I'm on version 1.9.x at the moment) followed by the specific CSS file for the menubar widget downloaded from the menubar branch of jquery ui
<link type="text/css" href="css/jquery-ui.css" rel="stylesheet" />
<link type="text/css" href="css/jquery.ui.menubar.css" rel="stylesheet" />
Don't forget the images folder with all the little icons used by jQuery UI needs to be in the same folder as the jquery-ui.css file.
Then at the end the body I have:
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.0.custom.min.js"></script>
<script type="text/javascript" src="js/menubar/jquery.ui.menubar.js"></script>
That's a copy of an up-to-date version of jQuery, followed by a copy of the jQuery UI file, then the menubar module downloaded from the menubar branch of jquery ui
The menubar CSS file is refreshingly short:
.ui-menubar { list-style: none; margin: 0; padding-left: 0; }
.ui-menubar-item { float: left; }
.ui-menubar .ui-button { float: left; font-weight: normal; border-top-width: 0 !important; border-bottom-width: 0 !important; margin: 0; outline: none; }
.ui-menubar .ui-menubar-link { border-right: 1px dashed transparent; border-left: 1px dashed transparent; }
.ui-menubar .ui-menu { width: 200px; position: absolute; z-index: 9999; font-weight: normal; }
but the menubar JavaScript file is 328 lines - too long to quote here. With it, you can simply call menubar() like this example:
$("#menu").menubar({
autoExpand: true,
menuIcon: true,
buttons: true,
select: select
});
As I said, I admire all the attempts to hack the menu object to turn it into a horizontal bar, but I found all of them lacked some standard feature of a horizontal menu bar. I'm not sure why this widget is not bundled with jQuery UI yet, but presumably there are still some bugs to iron out. For instance, I tried it in IE 7 Quirks Mode and the positioning was strange, but it looks great in Firefox, Safari and IE 8+.
You can do this:
/* Clearfix for the menu */
.ui-menu:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
and also set:
.ui-menu .ui-menu-item {
display: inline-block;
float: left;
margin: 0;
padding: 0;
width: auto;
}
This post has inspired me to try the jQuery ui menu.
http://jsfiddle.net/7Bvap/
<ul id="nav">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a>
<ul>
<li><a href="#">Item 3-1</a>
<ul>
<li><a href="#">Item 3-11</a></li>
<li><a href="#">Item 3-12</a></li>
<li><a href="#">Item 3-13</a></li>
</ul>
</li>
<li><a href="#">Item 3-2</a></li>
<li><a href="#">Item 3-3</a></li>
<li><a href="#">Item 3-4</a></li>
<li><a href="#">Item 3-5</a></li>
</ul>
</li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
</ul>
.ui-menu {
overflow: hidden;
}
.ui-menu .ui-menu {
overflow: visible !important;
}
.ui-menu > li {
float: left;
display: block;
width: auto !important;
}
.ui-menu ul li {
display:block;
float:none;
}
.ui-menu ul li ul {
left:120px !important;
width:100%;
}
.ui-menu ul li ul li {
width:auto;
}
.ui-menu ul li ul li a {
float:left;
}
.ui-menu > li {
margin: 5px 5px !important;
padding: 0 0 !important;
}
.ui-menu > li > a {
float: left;
display: block;
clear: both;
overflow: hidden;
}
.ui-menu .ui-menu-icon {
margin-top: 0.3em !important;
}
.ui-menu .ui-menu .ui-menu li {
float: left;
display: block;
}
$( "#nav" ).menu({position: {at: "left bottom"}});
http://jsfiddle.net/vapD7/
<ul id="nav">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a>
<ul>
<li><a href="#">Item 3-1</a>
<ul>
<li><a href="#">Item 3-11</a></li>
<li><a href="#">Item 3-12</a></li>
<li><a href="#">Item 3-13</a></li>
</ul>
</li>
<li><a href="#">Item 3-2</a></li>
<li><a href="#">Item 3-3</a></li>
<li><a href="#">Item 3-4</a></li>
<li><a href="#">Item 3-5</a></li>
</ul>
</li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
</ul>
.ui-menu { list-style:none; padding: 2px; margin: 0; display:block; outline: none; }
.ui-menu .ui-menu { margin-top: -3px; position: absolute; }
.ui-menu .ui-menu-item {
display: inline-block;
float: left;
margin: 0;
padding: 0;
width: auto;
}
.ui-menu .ui-menu-divider { margin: 5px -2px 5px -2px; height: 0; font-size: 0; line-height: 0; border-width: 1px 0 0 0; }
.ui-menu .ui-menu-item a { text-decoration: none; display: block; padding: 2px .4em; line-height: 1.5; zoom: 1; font-weight: normal; }
.ui-menu .ui-menu-item a.ui-state-focus,
.ui-menu .ui-menu-item a.ui-state-active { font-weight: normal; margin: -1px; }
.ui-menu .ui-state-disabled { font-weight: normal; margin: .4em 0 .2em; line-height: 1.5; }
.ui-menu .ui-state-disabled a { cursor: default; }
.ui-menu:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
$( "#nav" ).menu({position: {at: "left bottom"}});
I just been for 3 days looking for a jquery UI and CSS solution, I merge some code I saw, fix a little, and finally (along the other codes) I could make it work!
http://jsfiddle.net/Moatilliatta/97m6ty1a/
<ul id="nav" class="testnav">
<li><a class="clk" href="#">Item 1</a></li>
<li><a class="clk" href="#">Item 2</a></li>
<li><a class="clk" href="#">Item 3</a>
<ul class="sub-menu">
<li><a href="#">Item 3-1</a>
<ul class="sub-menu">
<li><a href="#">Item 3-11</a></li>
<li><a href="#">Item 3-12</a>
<ul>
<li><a href="#">Item 3-111</a></li>
<li><a href="#">Item 3-112</a>
<ul>
<li><a href="#">Item 3-1111</a></li>
<li><a href="#">Item 3-1112</a></li>
<li><a href="#">Item 3-1113</a>
<ul>
<li><a href="#">Item 3-11131</a></li>
<li><a href="#">Item 3-11132</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Item 3-113</a></li>
</ul>
</li>
<li><a href="#">Item 3-13</a></li>
</ul>
</li>
<li><a href="#">Item 3-2</a>
<ul>
<li><a href="#."> Item 3-21 </a></li>
<li><a href="#."> Item 3-22 </a></li>
<li><a href="#."> Item 3-23 </a></li>
</ul>
</li>
<li><a href="#">Item 3-3</a></li>
<li><a href="#">Item 3-4</a></li>
<li><a href="#">Item 3-5</a></li>
</ul>
</li>
<li><a class="clk" href="#">Item 4</a>
<ul class="sub-menu">
<li><a href="#">Item 4-1</a>
<ul class="sub-menu">
<li><a href="#."> Item 4-11 </a></li>
<li><a href="#."> Item 4-12 </a></li>
<li><a href="#."> Item 4-13 </a>
<ul>
<li><a href="#."> Item 4-131 </a></li>
<li><a href="#."> Item 4-132 </a></li>
<li><a href="#."> Item 4-133 </a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Item 4-2</a></li>
<li><a href="#">Item 4-3</a></li>
</ul>
</li>
<li><a class="clk" href="#">Item 5</a></li>
</ul>
javascript
$(document).ready(function(){
var menu = "#nav";
var position = {my: "left top", at: "left bottom"};
$(menu).menu({
position: position,
blur: function() {
$(this).menu("option", "position", position);
},
focus: function(e, ui) {
if ($(menu).get(0) !== $(ui).get(0).item.parent().get(0)) {
$(this).menu("option", "position", {my: "left top", at: "right top"});
}
}
}); });
CSS
.ui-menu {width: auto;}.ui-menu:after {content: ".";display: block;clear: both;visibility: hidden;line-height: 0;height: 0;}.ui-menu .ui-menu-item {display: inline-block;margin: 0;padding: 0;width: auto;}#nav{text-align: center;font-size: 12px;}#nav li {display: inline-block;}#nav li a span.ui-icon-carat-1-e {float:right;position:static;margin-top:2px;width:16px;height:16px;background:url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -64px -16px;}#nav li ul li {width: 120px;border-bottom: 1px solid #ccc;}#nav li ul {width: 120px; }.ui-menu .ui-menu-item li a span.ui-icon-carat-1-e {background:url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -32px -16px !important;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With