Joomla! Discussion Forums



It is currently Thu Nov 26, 2009 10:30 am (All times are UTC )

 


Forum rules

Please submit all new Tips and Tricks to: http://docs.joomla.org/Category:Tips_and_tricks



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ] 
Author Message
Posted: Wed Nov 30, 2005 10:41 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Fri Aug 26, 2005 1:31 am
Posts: 1246
Creating a CSS Drop down Menu


OK, if you have read my SEO FAQ, you might have noticed I am biased a little against flash and JavaScript. I like to emphasize W3C valid code and lean pages, neither of which is helped by these two approaches. “But what about menus?” I hear you ask, don’t they need one of these two?

Well, there are a number of techniques you can use with CSS to get more visually attractive menus, all of them use unordered lists (bulleted lists to you and me) to create the menu. Let’s look at one,  a drop down menu.

A few people (OK, one) wondered how I got a drop down menu on a recent site;

www.thrutheturnstiles.co.uk

The menu is what has been coined “suckerfish” (don’t ask me why), its pure CSS, very lean, hack free and just as 12 lines of JavaScript to bail out Microdoze IE.

You can see a demo here:
www.htmldog.com/articles/suckerfish/dropdowns/example/

You can find guides to how the thing works at a couple of sites:
www.htmldog.com/articles/suckerfish/dropdowns/
www.alistapart.com/articles/dropdowns/

Now, you might have noticed that you need your menu outputted as a good clean list. Well it just so happens that there is a module out there to do this, and we’ll need it. Its called extended_menu, you can find it here:
de.siteof.de/extended-menu.html

So, grab the module and install. Now let’s set it up. It’s easiest if you give it a menu and module class suffix. I used “mainnav” (you’ll see in the CSS below). A couple of other settings you will need:
Menu style: Tree List
Expand Menu: Yes

So put the menu where you want it, then to the CSS. This is a little tricky, it took me some trial and error to get the effects I wanted, but you can just skip that part and use mine  ;D.

Code:
#twocols{ /*the columns that gets dropped down over yours might be different*/
z-index:20;
}
#leftcol{  /*the columns that gets dropped down over yours might be different*/
z-index:10;
}
.moduletablemainnav{ /* I have absolutely positioned the module, you might have a different scheme*/
position:absolute;
top:187px;
left:20px;
z-index:100;
font:0.9em Verdana, Arial, Helvetica, sans-serif;
margin:0;
padding:0;
}
#mainlevelmainnav,#mainlevelmainnav ul{
float:left;
list-style:none;
line-height:1em;
background:transparent;
font-weight:700;
margin:0;
padding:0;
}
#mainlevelmainnav a{
display:block;
color:#f90;
text-decoration:none;
margin-right:15px;
padding:0.3em;
}
#mainlevelmainnav li{
float:left;
padding:0;
}
#mainlevelmainnav li ul{
position:absolute;
left:-999em;
height:auto;
width:11em;
font-weight:400;
background:#36f;
border:#00C 1px solid;
margin:0;
}
#mainlevelmainnav li li{
width:11em;
}
#mainlevelmainnav li ul a{
width:11em;
color:#fff;
font-size:0.9em;
line-height:1em;
font-weight:400;
}
#mainlevelmainnav li:hover ul ul,#mainlevelmainnav li:hover ul ul ul,#mainlevelmainnav li.sfhover ul ul,#mainlevelmainnav li.sfhover ul ul ul{
left:-999em;
}
#mainlevelmainnav li:hover ul,#mainlevelmainnav li li:hover ul,#mainlevelmainnav li li li:hover ul,#mainlevelmainnav li.sfhover ul,#mainlevelmainnav li li.sfhover ul,#mainlevelmainnav li li li.sfhover ul{
left:auto;
z-index:6000;
}
#mainlevelmainnav li li:hover,#mainlevelmainnav li li.sfhover{
background:#039 url(../images/soccerball.gif) 98% 50% no-repeat;
}


Now, just make sure you have the z-indexes set up properly, also remember to have a z-index, the element needs some sort of positioning, if not absolute then relative.

Last but not least you need to add the JavaScript for IE into the head of the template index.php (or a js file), it doesn’t like the :hover.

Code:
<script type="text/javascript"><!--//--><![CDATA[//><!--

sfHover = function() {
   var sfEls = document.getElementById("mainlevelmainnav").getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
         this.className+=" sfhover";
      }
      sfEls[i].onmouseout=function() {
         this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
      }
   }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]></script>



Hopefully, follow this and Bob’s your Uncle you should have clean valid drop downs for your menu. Enjoy!

_________________
Joomlashack - Professional Hand Coded Joomla Templates
www.joomlashack.com/professional-joomla-templates
Fully Managed Joomla Hosting
www.joomlashack.com/joomla-hosting


Last edited by Tonie on Fri Sep 28, 2007 7:06 pm, edited 1 time in total.

Top
   
 
Posted: Wed Oct 03, 2007 1:24 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Oct 03, 2007 1:09 pm
Posts: 36
Location: Jersey, Channel Islands
am just experimenting with an accessible joomla template utilising the extended suckerfish menu and noticed a couple of ommissions/errors in ya post when starting out afresh..

to get your css to work, the class suffix of the anchors needs to be defined in the menu.ini file, changing it from '-suckerfish-horizontal' to 'mainnav' in order to get the 'mainlevelmainnav' classes..

also, you have listed the 'mainlevelmainnav' class as an id in your css so the hashes need to be changed to full stops to get your css to work propa.. i haven't got that far, but i presume that this will also impinge on the javascript which is using 'getelementbyid' (javascript ain't my strong point tho so i may be wrong about that)..

luv ya work over at compassdesigns btw :)

---------------------------------------------------------------------------

http://hypertexture.net/

_________________
http://hypertexture.net/


Top
  E-mail  
 
Posted: Wed Oct 03, 2007 2:48 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Oct 03, 2007 1:09 pm
Posts: 36
Location: Jersey, Channel Islands
also, the float:left; attribute on .mainlevelmainnav,.mainlevelmainnav ul seems to cause problems in internet explorer 7 whereby the menu is offset to the right of the parent li.. removing this float attribute and adding it to the immediate parent div (.menumainnav) seems to sort it :)

_________________
http://hypertexture.net/


Top
  E-mail  
 
Posted: Tue Oct 23, 2007 1:29 am 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Tue Oct 23, 2007 12:53 am
Posts: 1
I too have the problem with the sub-menus being offset one item to the right (in IE7), but moving the "float: left" entry didn't seem to help. Everything else seems to be working fine (I didn't have to change the selectors  to full-stops from # signs), but this issue is causing me much frustration.

Any ideas?
Imbert


Top
  E-mail  
 
Posted: Wed Nov 28, 2007 10:06 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Nov 18, 2007 9:49 pm
Posts: 41
thanks for this css drop down menu Tutorials! this help me more!

_________________
http://joomlatp.com :free joomla templates,free joomla themes,free joomla 1.5 templates


Top
   
 
Posted: Fri Dec 07, 2007 7:13 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Feb 11, 2006 8:13 am
Posts: 14
Great Post
Nice thinking

Thank you!

_________________
.: http://www.Web-Design.gr :. .: http://www.Travel365.gr :.


Top
  E-mail  
 
Posted: Tue Dec 11, 2007 8:43 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Dec 08, 2007 8:23 pm
Posts: 21
compass,

You made an excellent post but I've encountered a problem and have provided details here.

I have copied 'verbatim' your css into mainnav.css, uploaded into the css folder and added this line to the index.php page.

Code:
<link href="templates/citydealer/css/mainnav.css" rel="stylesheet" type="text/css"/>


I have copied 'verbatim' your javascript code into mainnav.js, uploaded into the javascript folder and added this line to the index.php page.

Code:
<link href="templates/citydealer/javascript/mainnav.js"  type="text/javascript">


I've added this to my index.php file where I want the menu to appear.

Code:
      
<!-- class="moduletablemainnav" - don't use unless you have to -->
  <table width="810" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr><td> <span class="mainlevelmainnav">
            <?php mosLoadModules ( 'user9' ); ?>
          </span></td>
    </tr>
  </table>


I didn't include the class moduletablemainnav in the table tag as it would require repositioning changes but if need be, I can insert an image to force the height of the top level menu navigation row and change the exact positioning to place it.

Here is the top part of the Extended Menu module:

Image

and the main part of the bottom options

Image

Here is how it appears after the changes:

Image

It is appearing expanded and I did setup the module following your instructions:
Menu style: Tree List
Expand Menu: Yes

I'm not concerned with formatting, coloring, exact positioning of the menu.  I'm only concerned why the entire expanded menu is shown instead of just the top row with the cascading options appearing once one of the top nav links is hovered over.

Can you determine what I have done wrong? 


Top
  E-mail  
 
Posted: Wed Dec 12, 2007 2:14 am 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Fri Aug 26, 2005 1:31 am
Posts: 1246
hmmmm

One thing is make sure you are using FF, as it correctly renders without the js, so that will remove that problem.

If it still does it in FF, the problem is the CSS is not correctly hiding the submenus

_________________
Joomlashack - Professional Hand Coded Joomla Templates
www.joomlashack.com/professional-joomla-templates
Fully Managed Joomla Hosting
www.joomlashack.com/joomla-hosting


Top
   
 
Posted: Wed Dec 12, 2007 4:58 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Dec 08, 2007 8:23 pm
Posts: 21
Compass,

Firefox 2.0.0.11

I left IE as my personal choice about 18 months ago.

But I do test all my pages in both as IE is still the dominant browser. MS is still a bulldog of a company as it can force it's view on a lot of people and disregard those who try to set standards for everyone to go by including the 'real' inventor of the internet.


Top
  E-mail  
 
Posted: Thu Dec 13, 2007 6:33 am 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Thu Dec 13, 2007 6:28 am
Posts: 2
I think is' s great.

_________________
www.herixylo.gr


Top
  E-mail  
 
Posted: Mon Dec 17, 2007 1:11 pm 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Thu Oct 18, 2007 5:04 pm
Posts: 4
Thanks compass - this is a great tutorial - really helped me out. Just couldn't work out how to implement a drop down with the extended menu module before reading this.

It hasn't all been plain sailing though - I have a problem with the menu actually dropping downward. The idea is to have the top level items across the top of the page with the menus dropping down vertically underneath each one over the top of other content when you mouse over. At the moment, the submenu items display horizontally underneath the top level item.

I'm not great with CSS (as you've probably guessed) but I have a feeling this may be something to do with my template layout and z-indexes.

Any wise words would be much appreciated - if you need links, code etc.. let me know.

Thanks


Top
  E-mail  
 
Posted: Thu Dec 27, 2007 9:52 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Dec 24, 2007 11:48 am
Posts: 16
can someone please make a summary how to setup all those settings that work correctly. following from 1st page untill now just make my headache worst.  ???


Top
   
 
Posted: Sun Jan 06, 2008 12:27 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Dec 16, 2007 3:37 pm
Posts: 10
can anyone help me with ja wezen template, I just want to put samo drop down menu but I don't know how I am a beginner
can anyone help me pleeeeassseeee :(


Top
  E-mail  
 
Posted: Fri Jan 18, 2008 11:41 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Mar 23, 2007 2:00 pm
Posts: 36
This is brilliant. Thankyou.

Is it possible to show the sublevel links horizontal or inline rather than vertically?

Many thanks again.


Top
  E-mail  
 
Posted: Sat Jan 19, 2008 8:34 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Jan 11, 2008 3:33 am
Posts: 5
LukeDouglas wrote:
compass,

You made an excellent post but I've encountered a problem and have provided details here.

I have copied 'verbatim' your css into mainnav.css, uploaded into the css folder and added this line to the index.php page.

Code:
<link href="templates/citydealer/css/mainnav.css" rel="stylesheet" type="text/css"/>


I have copied 'verbatim' your javascript code into mainnav.js, uploaded into the javascript folder and added this line to the index.php page.

Code:
<link href="templates/citydealer/javascript/mainnav.js"  type="text/javascript">


I've added this to my index.php file where I want the menu to appear.

Code:
      
<!-- class="moduletablemainnav" - don't use unless you have to -->
  <table width="810" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr><td> <span class="mainlevelmainnav">
            <?php mosLoadModules ( 'user9' ); ?>
          </span></td>
    </tr>
  </table>


I didn't include the class moduletablemainnav in the table tag as it would require repositioning changes but if need be, I can insert an image to force the height of the top level menu navigation row and change the exact positioning to place it.

Here is the top part of the Extended Menu module:

Image

and the main part of the bottom options

Image

Here is how it appears after the changes:

Image

It is appearing expanded and I did setup the module following your instructions:
Menu style: Tree List
Expand Menu: Yes

I'm not concerned with formatting, coloring, exact positioning of the menu.  I'm only concerned why the entire expanded menu is shown instead of just the top row with the cascading options appearing once one of the top nav links is hovered over.

Can you determine what I have done wrong? 


Great ,,,Thank You

_________________
Please read signature rules: viewtopic.php?f=8&t=65


Top
  E-mail  
 
Posted: Wed Jan 23, 2008 2:05 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Nov 29, 2007 9:02 am
Posts: 79
Hi Compass,

I'm having problem in my drop down menu. The sub menus appear into one direction only.

The menu is positioned in the middle of the page. Please Visit the link to see.
http://websolutions.worldpartner.com/logposetravel/

Thanks.

here are the codes.
I used mainlevel as ID because I inspect the site using firebug then I've found that the ID of links is that.

#mainlevel {
  list-style: none;
  margin: 0px;
  padding: 0px;
  border: 0px solid #ff0000;
}



#mainlevel ul {
  float: left;
  list-style: none;
  margin: 0px;
  padding: 0px;
}

#mainlevel a {
  float: left;
  vertical-align: middle;
  font-family: Trebuchet MS,verdana;
  font-size: 12px;
  font-weight: normal;
  color: #ffffff;
  text-align: center;
  text-decoration: none;
  padding-top: 0px;
  padding-left: 15px;
  padding-right: 15px;
  /* height: 31px; */
  line-height: 22px; 
  width: auto;
  border: 0px solid #ff0000;
}

#mainlevel a:hover {
  text-decoration: none;
  color: #e1dcaf;
  /* height: 31px; */
}

#mainlevel li {
  float: left;
  margin: 0px;
  padding: 0px;
}

#mainlevel li ul {
  position:absolute;
  left:-999em;
  width: 125px;
  margin:0px;
  padding:0px;
  color: #000000;
  line-height: 14px;
  /* background: #b9b950; */
  background: #a0b40f;
}

#mainlevel li li {
  width: 125px;
  margin: 0px;
  padding: 0px;
}

/* submenu normal inner background */
/* eto yung pag-hover mo sa main menu, lalabas yung submenus na dropdown */
#mainlevel li ul a {
  position: relative;
  top: 0px;
  left: 0px;
  background: #a0b40f;
  text-align: left;
  text-indent: 10px;
  /* margin-left:10px; */
  padding: 0px;
  padding-top: 4px;
  padding-bottom: 4px;
  height: 17px;
  line-height: 17px;
  width: 125px;
}

/* hover properties ng submenu */

#mainlevel li ul a:hover {
  height: 17px;
  line-height: 17px;
  color: #327828;
}

#mainlevel li:hover ul ul,#mainlevel li:hover ul ul ul,#mainlevel li.sfhover ul ul,#mainlevel li.sfhover ul ul ul
{
  left:-999em;
  line-height: 14px;
  padding-bottom: 0px;
}

/* submenu normal outer background - ito ang submenu */

#mainlevel li:hover ul,#mainlevel li li:hover ul,#mainlevel li li li:hover ul,#mainlevelv li.sfhover ul,#mainlevel li li.sfhover ul,#mainlevel li li li.sfhover ul {
  /* position: absolute; */
  margin: 0px;
  padding: 0px;
  width: 125px;
  border: 1px solid #fafafa;
  z-index: 6000;
  left: 85px;
  width: 125px;
  top: 32px;
}

/* submenu hover outer background - eto yung pag hover mo sa submenu */

#mainlevel li li:hover,#mainlevel li li.sfhover {
  margin: 0px;
  padding: 0px;
  width: 125px;
  height: 25px;
  line-height: 25px;
}

Thanks Again


Top
   
 
Posted: Thu Feb 07, 2008 12:19 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Fri Feb 01, 2008 9:18 am
Posts: 11
Hi all great stuff... Just one thing.

I am using a template called JA Rochea and it magically creates the main nav menus at the top of the site from the main menu listings that are actually situated on the left hand side of the template.

So my question is, I am a novice to this. I have managed ot get the menus on another site I ran as a demo to for the menus and ext_menu worked fine on that site but gets no results on this problem as the area I need to publish the menu to does not really exist as a module in teh back end of Joomla...

Can somebody help me please! in any way as I am at the end of my ideas!


Top
   
 
Posted: Thu Feb 07, 2008 6:20 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sun Nov 18, 2007 3:48 am
Posts: 11
Drop down menus are great.

Is there any chance that drop down menus might appear as a module, mambot or another plugin?

I am fairly new to Joomla and definately not comfortable with CSS, but accessing this functionality in the backoffice would be fantastic.

Might this be part of 1.5 templates? 

Your help would be appreciated.

Kurt


Top
  E-mail  
 
Posted: Fri Feb 08, 2008 12:59 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Jan 09, 2008 6:35 am
Posts: 8
Dear all,

I've tried this out, and i could only make it work on the left side, but when i chose position "top" instead of "left" , I don't see any thing. I would like to show it in the Topmenu. What should i do? Please tell me the options i should choose when i create the mainnav in module!

I am using joomla 1.5.


Thank you,

Keomony


Top
  E-mail  
 
Posted: Mon Feb 11, 2008 4:43 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Mon Feb 11, 2008 2:17 pm
Posts: 9
CSS drop-down's work fine in my Firefox + Web Developer ext. (for debugging) setup, but seem to be slightly buggy in IE 7.
I suspect this is related to how IE determines cursor position vs. element position, but that's just a guess.

_________________
Signature rules: http://forum.joomla.org/index.php/topic,65.0.html


Top
  E-mail  
 
Posted: Fri Feb 15, 2008 8:50 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Dec 21, 2005 8:18 pm
Posts: 10
Is it possible to make the menu appear vertically down the side of the page?


Top
  E-mail  
 
Posted: Mon Feb 18, 2008 5:16 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Jan 03, 2007 6:35 am
Posts: 39
Take a look at this:
http://www.redmeetsblue.com.au/rmbclient/wajeep/index.php?option=com_content&task=view&id=27&Itemid=61
Just wanted to know why the submenu for the 'Home' button isn't dis/appearing on mouse out/on rollover?

The link to my menu CSS is
http://www.redmeetsblue.com.au/rmbclient/wajeep/templates/chrysler/css/menu.css

The link to my menu js is
http://www.redmeetsblue.com.au/rmbclient/wajeep/templates/chrylser/js/menu.js

_________________
Graphic & Website Design
Red Meets Blue Design Branding Agency
http://www.redmeetsblue.com.au


Top
  E-mail  
 
Posted: Mon Feb 18, 2008 1:29 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Wed Jan 09, 2008 6:35 am
Posts: 8
Dear all,

Finally, I could make the drop down menu for the top menu with some changes on CSS file. But in IE is sth else. even I separate the css in to two, one for FF and another one for IE. But I still can't get the right thing. I am using IE6. Who has any idea how to deal with this problem?


I am wondering whether we can use Ajax for this drop down menu. For example, when a menu is clicked, the content of that menu will be displayed in the page without reloading the whole page.
Can we do that in Joomla?


Keomony


Top
  E-mail  
 
Posted: Mon Feb 18, 2008 8:55 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Mon Jul 23, 2007 5:04 pm
Posts: 144
Location: Hawaii
I installed extended menu and added css code to my template.css file and added few lines of code to my template index.php. Why am I getting this funny bullet marks in front of my menu items?
Please help me to get rid off those.


You do not have the required permissions to view the files attached to this post.


Top
  E-mail  
 
Posted: Tue Feb 26, 2008 4:50 pm 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Tue Feb 26, 2008 4:10 pm
Posts: 0
Seriously. Was this menu only created to work in FF and Safari? In IE7 theres a bug that pushes the dropdown to the right, IE6 doesnt even open. I just cant get it to work in IE, I know its a broken browser but its the dominant one.



Hupertexture wrote:

"also, the float:left; attribute on .mainlevelmainnav,.mainlevelmainnav ul seems to cause problems in internet explorer 7 whereby the menu is offset to the right of the parent li.. removing this float attribute and adding it to the immediate parent div (.menumainnav) seems to sort it"


This does not help. And where is this div class located "parent div (.menumainnav)", I dont see it anywhere in this menu's CSS ? I heard the author of this thing also made a alot of mistakes in CSS.


Top
  E-mail  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group