Menú con tabs con CSS, jQuery y Mootools

23/Oct/2008 248

Esos menúes tipo tabs ó con subniveles tanto horizontales como verticales, son muy útiles al momento de desplegar grandes cantidades de navegación sin ser invasivos con el espacio. Puedes arquitecturar toda la estructura de tu sitio de manera tal que el usuario pueda encontrar fácilmente la información que desee, sólo con ir descubriendo con el mouse las subsecciones que están contenidas dentro del árbol general de navegación.

SafariFirefoxOperaInternet Explorer 6Internet Explorer 7

Por suerte hacer estos tipos de menúes es bastante fácil: basta con tener claro cómo funcionan los menúes con listas e ir anidando unas dentro de otras; incluso sólo con CSS es suficiente para hacerla funcionar, pero lamentablemente el peor browser de la historia universal (IE6) no soporta pseudo-classes en selectores que no sean links (<a>). Así que lo mejor y que más soporte cross-browser nos entrega es utilizar Javascript en este proceso. Y qué mejor que utilizar jQuery ó Mootools, 2 de los frameworks con los que me gusta jugar.

En este artículo veremos el proceso para crear un menú con tabs y cómo hacerlo funcionar mediante CSS y con la ayuda de Javascript.

Como mencionaba, un menú con tabs se compone básicamente de listas anidadas sobre otras listas. El HTML sería el siguiente:

<ul id="menu">
<li><a href="#">Uno</a></li>
<li class="cabeza"><a href="#">Dos</a>
<ul>
<li><a href="#">Dos.Uno</a></li>
<li><a href="#">Dos.Dos</a></li>
<li><a href="#">Dos.Tres</a></li>
</ul>
</li>
<li><a href="#">Tres</a></li>
<li class="cabeza"><a href="#">Cuatro</a>
<ul>
<li><a href="#">Cuatro.Uno</a></li>
<li><a href="#">Cuatro.Dos</a></li>
</ul>
</li>
</ul>

Ver ejemplo del HTML

Si el mundo fuera hermoso y no existiera IE6, nos bastaría con un poco de CSS y selectores avanzados de atributos para hacerlo funcionar:

ul {
list-style: none;
}
ul li {
float: left;
width: 100px;
text-align: center;
}
li.cabeza>ul {
display: none;
}
li.cabeza:hover>ul {
display: block;
}

Ver ejemplo con CSS

Para mejorar el manejo del despliegue de los subniveles, le coloqué una class="cabeza" a cada elemento de lista (<li>) que contenga cada nuevo subnivel. Ahora es más fácil diferenciarlas con CSS ó Javascript, como mostraré a continuación. Primero, con jQuery:

$(document).ready(function(){
// primero escondemos todos los subniveles
$('li.cabeza > ul').hide();
// luego le agregamos el evento de mouseover y mouseout mediante hover de jQuery
$('li.cabeza').hover(
function() {
$('ul', this).show();
},
function() {
$('ul', this).hide();
});
});

Ver ejemplo jQuery

Muy simple. Ahora, con Mootools (1.11):

window.addEvent('domready', function() { 
// creamos una variable 'list' que será el selector <li> con class="cabeza", ya que la usaremos más de una vez.
var list = $$('li.cabeza');
// luego escondemos cada <ul> que esté contenido dentro de li.cabeza mediante display: none
list.getElement('ul').setStyle('display', 'none');
// ahora agregamos los eventos de mouseenter y mouseout respectivos
list.each(function(el) {
el.addEvent('mouseenter', function(){
$(this).getElement('ul').setStyle('display', 'block');
});
el.addEvent('mouseleave', function(){
$(this).getElement('ul').setStyle('display', 'none');
});
});
});

Ver ejemplo Mootools

Finalmente si usas un browser bueno, cualquier de los 3 métodos funcionará igual; viene de ti implementarlo de la mejor forma para que tus usuarios que aún usen IE6 para visitar tu sitio puedan disfrutar de una buena navegación y del contenido que ofrece.

Comentarios

  1. Jefferybed [#]

    viagra alternatives
    buy cheap generic viagra female viagra pills viagra online purchase viagra online in canada viagra sales best canadian online pharmacy reviews what happens if a girl takes viagra canadian tadalafil online drugstore cialis for daily use
    walmart prescription prices cialis canada pharmacy walmart drug prices without insurance http://www.northwestpharmacy.com viagra for sale

  2. Umpoqn [#]

    prednisone pills – purchase prednisone from india can you purchase prednisone for dogs without a prescription

  3. Ycnadi [#]

    prednisone 50 mg buy – prednisone 5mg price in india where can i buy prednisone online without a prescription

  4. Vzhbhj [#]

    sildenafil 200mg price – sildenafil 100mg australia what is sildenafil

  5. Szalfn [#]

    female viagra brand name – sildenafil 90mg viagra 300mg

  6. RogerPSync [#]

    discount canadian pharmacies
    cialis generic to canada viagra sales where to buy viagra buying viagra online viagra pro cialis – canada canadian pharmacy online cialis canada viagra purchase online cialis canadian pharmacy
    generic cialis viagra online pharmacy drugstore in canada viagra results discount meds

  7. StevenFal [#]

    how to get viagra without a prescription
    cialis canadian pharmacy canada pharmacies online viagra cheap viagra online canada pharmacy over the counter viagra canadian viagra online pharmacy low price cialis online pharmacy usa canadian levitra viagra purchase canadian pills
    list of canada online pharmacies cialis or generic canada pink viagra buy canadian drugs without prescription cheap viagra online canada pharmacy

  8. RogerPSync [#]

    generic viagra india
    drug store online generic viagra rx cialis without prescription canada northwestpharmacy.com scam best canadian drugstore viagra in canada northwestpharmacy.com scam purchase viagra professional cheap canadian drugs canadadrugsonline.com
    us pharmacy cialis viagra from canada generic pharmacy cialis from canada? canadian pharcharmy

  9. Lloydneoky [#]

    viagra without a doctor prescription usa
    online pharmacy canada substitute viagra canadian viagra online canadian pharmacy cialis 20mg liquid viagra buy drugs in canada cialis in canada ed medications getcanadiandrugs.com generic pharmacy india
    canada prescription canadian pharmaceutical viagra at canadian pharmacy canadian pharmacy cialis generic buy cialis online canada pharmacy

  10. tondutt [#]

    Propecia

  11. web hosting their [#]

    This is a topic which is close to my heart… Best wishes!
    Where are your contact details though?

  12. is web hosting [#]

    Incredible points. Great arguments. Keep up the amazing effort.

  13. j.mp [#]

    I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% positive.
    Any recommendations or advice would be greatly appreciated.

    Cheers

  14. t.co [#]

    I know this if off topic but I’m looking into starting
    my own blog and was curious what all is needed to
    get setup? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive.
    Any tips or advice would be greatly appreciated. Kudos

  15. Lloydneoky [#]

    canada drugs
    cialis lowest price do you need a prescription for cialis cialis without a doctor’s prescription how viagra works viagra canada pharmacy natural viagra alternatives alternative to viagra canada rx pfizer viagra cilas
    generic cialis canada india pharmacy viagra walmart rx prices what does viagra do canada prescriptions

  16. hydroxychloroquineMt [#]

    chloroquine phosphate tablets chloroquine phosphate generic name hydroxychloronique

  17. ivermectin1.com [#]

    ivermectin over the counter uk Menu con tabs con CSS, jQuery y Mootools | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ ivermectin tablets dosage

  18. gay dating phoenix k [#]

    biggest gay dating sites https://gay-singles-dating.com/

  19. PeterCed [#]

    cost viagra
    viagra plus cialis-canadian pharmacy drugs canada viagra alternatives no prescription viagra generic viagra reviews best online pharmacies buy viagra usa buy cialis canada canada pharmacies online prescriptions
    canadian pills pfizer viagra canadian pharmacies generic drugs online brand viagra online canada pharmacy buy cheap viagra

  20. MarvinFuh [#]

    best treatments for ed
    online drugstore buying drugs from canada canadian pharmacy cialis for daily use purchasing viagra from canada viagra online canada india generic viagra viagra results prescription drugs from canada buy viagra now canada pharmacies online viagra
    viagra prices buy cialis canada viagra metoprolol canada drugs online

  21. gay cop dating [#]

    crossword gay dating site https://gayonlinedating.net/

  22. FelipeHaw [#]

    canadian levitra
    viagra cost order cialis in canada canadian pharmacy store cialis-canada buy viagra online uk buying viagra online brand viagra online canada pharmacy international drug mart viagra online order alternatives to viagra
    cialis- canadian pharmacy viagra sales when will viagra go generic generic cialis medications.com

  23. for quest bars [#]

    Stunning story there. What happened after? Take care!
    quest bars http://j.mp/3C2tkMR quest bars

  24. app.gumroad.com [#]

    We are a group of volunteers and starting a brand new scheme in our
    community. Your website offered us with valuable info to work on. You have done a
    formidable activity and our whole community will
    probably be thankful to you. asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

  25. gay dating blogs [#]

    the rise of dating sites gay https://datinggayservices.com/

  26. gay dating symbols [#]

    bangalore gay dating site https://gaydatinglosangeles.com/

  27. gay text dating [#]

    gay teen boys dating https://dating-gaym.com/

  28. ivermectin1.com [#]

    ivermectin brand Menu con tabs con CSS, jQuery y Mootools | CSSLab | Laboratorio de ideas web http://ivermectin1.com/ ivermectin for humans over the counter skin

  29. http://bit.ly/ [#]

    bookmarked!!, I like your website! cheap
    flights http://1704milesapart.tumblr.com/ cheap flights

  30. MarvinFuh [#]

    canadian drug stores
    buy cialis online cheap viagra online canadian drug stores viagra soft is there a generic cialis viagra expiration date free trial of viagra canadapharmacyonline.com canada walmart cialis online pharmacy
    metoprolol viagra costs price viagra prescriptions from canada canada prescriptions

  31. coub.com [#]

    I like the valuable information you provide in your articles.

    I’ll bookmark your weblog and check again here regularly.

    I am quite certain I will learn many new stuff right here!
    Best of luck for the next! scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

  32. www.iherb.com [#]

    I was curious if you ever thought of changing the layout of
    your website? Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect
    with it better. Youve got an awful lot of text for only having one or 2 pictures.
    Maybe you could space it out better? quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

  33. bitly.com [#]

    Hey! Do you use Twitter? I’d like to follow you if that would be okay.

    I’m definitely enjoying your blog and look forward to
    new posts. scoliosis surgery https://0401mm.tumblr.com/ scoliosis
    surgery

  34. fexofenadine hydrochloride [#]

    side effects of fexofenadine – http://allergyd.com

  35. does zyrtec cause drowsiness [#]

    cetirizine withdrawal symptoms – http://allergyd.com

  36. pharmaceptica.com [#]

    tens 7000 erectile https://www.pharmaceptica.com/

  37. pbvdvyig [#]

    4zvV2p tznfhyinwzmj, [url=http://gjxyqamghjlu.com/]gjxyqamghjlu[/url], [link=http://vbwfumizhxcp.com/]vbwfumizhxcp[/link], http://ixildvnyiwji.com/

  38. ivermectin over the counter [#]

    Accustomed Low-down Far this offshoot
    https://ivermectinsts.com ivermectin paste
    https://ivermectinst.com ivermectin uk
    https://stromectolivermect.com ivermectin for sale
    https://ivermectinstrom.com ivermectin 6 mg
    https://ivermectstromect.com ivermectin tablets for humans

  39. buyprednisone [#]

    side effects for prednisone prednisolone for dogs

  40. accutane [#]

    side effects of accutane roaccutane side effects

  41. pharmaceptica.com [#]

    chloroquine amazon https://www.pharmaceptica.com/

  42. bactrim antibiotic [#]

    co trimoxazole bactrim bactrim ds

  43. stromectolforte.com [#]

    thuốc stromectol https://stromectolforte.com/ stromektolvätska ivermectin over counter

  44. bactrim generic [#]

    sulfamethoxazole trimethoprim trimoxazole antibiotics

  45. stromectolforte.com [#]

    ivermectin tablets https://stromectolforte.com/ ivermectin for humans ivermectina

  46. ivermectin usa [#]

    white mold on wood health risks http://ivermectinsl.com – ivermectin

  47. stromectol [#]

    Global Information Here this product
    https://ivermectstromect.com stromectol
    https://ivermectstromect.com ivermectin for humans
    https://stromectolivermect.com ivermectin for sale
    https://ivermectinstrom.com ivermectin 3 mg
    https://stromectolivermect.com stromectol

CSSLab