Very Style CSS Mega Menu
I am looking at creating a navigation menu similar in style to Very.co.uk
Can anyone point me in the right direction开发者_Go百科 as far as where to start and best practices?
Thanks
Try Mega Drop Down Menus w/ CSS & jQuery
Its got a good tutorial and a demo.
Something like this is the basic idea...
Demo: http://jsfiddle.net/hgZGS/
jQuery...
$('#menu span').hide();
$('#menu li').hover(function() {
var offset = $(this).offset();
$(this).find('span').css('marginLeft', offset.left + 'px');
$(this).find('span').show();
var offsetRight = offset.left + $(this).find('span').width();
var ww = $(window).width();
var fixed = offset.left + $(this).width() - $(this).find('span').width();
if (offsetRight > ww) {
$(this).find('span').css('marginLeft', fixed + 'px');
}
else {
$(this).find('span').css('marginLeft', offset.left + 'px');
}
}, function() {
$(this).find('span').hide();
});
CSS...
#menu {
margin: 20px;
}
#menu LI {
display: block;
float: left;
border-right: 1px solid #fff;
background-color: #ccc;
padding: 5px;
cursor: pointer;
}
#menu SPAN {
display: block;
position: absolute;
width: 200px;
height: 100px;
background-color: #E2E2E2;
left: 0px;
margin-top: 5px;
padding: 5px;
}
HTML...
<ul id="menu">
<li>The Quick<span>Quick</span></li>
<li>Brown<span>Brown</span></li>
<li>Fox<span>Fox</span></li>
<li>Jumps<span>Jumps</span></li>
<li>Over<span>Over</span></li>
<li>Then<span>The</span></li>
<li>Tall<span>Tall</span></li>
<li>White<span>White</span></li>
<li>Fence<span>Fence</span></li>
</ul>
best start is to make a structure like
<ul>
<li><a href="">Menu</a><div class="subnav">any popunder content</div></li>
...
</ul>
then, make <li> a relative left floating block and .subnav an absolute positioning:
ul li { float: left; display: block; position: relative }
ul li .subnav { display: none; position: absolute; top: 0; left: 0 }
/* you may need to edit top and left to fit your needs */
then via css you can do:
ul li:hover .subnav { display: block }
and duplicate via jquery for old school browsers
$('ul li').hover(
function() { $(this).find('.subnav').css('display', 'block') },
function() { $(this).find('.subnav').css('display', 'none') }
);
that may be the beginning for your studies :)
精彩评论