CSS horizontal drop menu (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


Scotty -> CSS horizontal drop menu (4/28/2008 14:52:52)

I just noticed our drop menu is not working properly in Internet Explorer...www.loghomestore.com.
With firefox, everything is fine, in Explorer there are white lines/spaces between some of the items...example, hover over tools and you can slide down the first two items, then you get to a space before the next item "drilling", and that's as far as you can go.
What did I do wrong?...and is this a function of my opening pages/editing with WSIWG editor (Kompozer).
Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu (4/28/2008 15:45:18)

Might be the IE whitespace bug. Just to experiment, try removing the whitespace after one list item that's causing a problem like this:

....
<li><a href="whatever.html">Linky</a>
</li><li><a href="whatever.html">Linky</a>
...


etc

What you're doing is effectively removing the whitespace after the closing LI. It may not work but it's worth a go.

You've got a lot of coding errors in there - it's hard to be sure what's causing an issue and what's not with that amount of errors - very difficult to track down solutions.




Scotty -> RE: CSS horizontal drop menu (4/28/2008 22:40:51)

It worked...so far.
First I set up a 'compliant' page.
www.loghomestore.com/compliant.html.
Ran the w3c test and got a passing grade :)
Then I took the first section of the horizontal css drop menu "books" and removed the 'white spaces' by moving the <li> up one line to be next to </li>...thus </li><li>, for it and all it's sub menus...and it works in Firefox and IE.
Anyone have time to look in Opera or ?...what other browsers should I check?
Regards, Scotty

Update: I'm part way through this process and it looks like it's going to royally confuse IE...it's starting to show blank boxes, slow loading boxes, boxes which shouldn't (yet) be open.
I'll keep slogging, however I'm wondering if I should revert back to our previous js drop menu?
Anyone successfully using a horizontal css drop menu in IE? What flavor is it?
Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu (4/29/2008 2:07:53)

I've successfully used the accessible son of suckerfish and the Helix dropdowns.

Most (all) CSS menus have a little extra javascript because otherwise they won't work in IE6 and under. It's question of how much really. As long as you've got pure HTML links then you're ok. Problems arise when you get those Javascript menus with scripted links etc.

Anyway - the issue looks to be the Whitespace Bug and there are a few solutions around one of which is to remove the whitespace between all the list items in the menu.

Here's a TEST PAGE where I've done that and it works fine in IE7, FF and Opera (no dropdowns in IE6 as expected).

It's not handy to edit like this as you've basically got the lot on one line so maybe one of the other cures would be better for you. But if you're using a WYSIWYG editor anyway... Be careful with those editors - they can re-arrange your code for you which would put the whitespace right back in. I'd take a copy of the menu in a text file just in case. The version on the link you posted last had all the normal whitespace there still.





Scotty -> RE: CSS horizontal drop menu problem in IE (4/29/2008 21:24:04)

With tailspins' permission I loaded the fix and viola...drop downs work in current IE. You musta been a fighter pilot in a previous incarnation...that was quick.
Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (4/30/2008 6:58:53)

Ok - 2 things.

Firstly - yes removing the whitespace works but on a menu that size I wouldn't use it - it'll be a nightmare to edit. I used it primarily to show that it was the whitespace bug causing the issue. There are better ways of fixing it.

In the test page I've posted I've changed the menu back to the properly indented form to make life easier to edit it and I've added two little rules for your CSS:

#navigation li li a { display: inline-block; }
#navigation li li a { display: block; }


Put these after all your other #navigation rules in the stylesheet. This fixes it for IE7. Oddly - in IE6 and under the whitespace bug wasn't showing... go figure.

Just copy and paste the navigation list back into your page from my test page.

Secondly, to make the dropdowns drop down in IE6 and under, copy the following code into a blank page of Notepad or whatever and save it as csshover.htc - upload it to your webserver.

<attach event="ondocumentready" handler="parseStylesheets" />
<script>
/**
 * Whatever:hover - V1.42.060206 - hover & active
 * ------------------------------------------------------------
 * (c) 2005 - Peter Nederlof
 * Peterned - http://www.xs4all.nl/~peterned/
 * License  - http://creativecommons.org/licenses/LGPL/2.1/
 *
 * Whatever:hover is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Whatever:hover is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Credits and thanks to:
 * Arnoud Berendsen, Martin Reurings, Robert Hanson
 *
 * howto: body { behavior:url("csshover.htc"); }
 * ------------------------------------------------------------
 */

var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
   onhover:{on:'onmouseover', off:'onmouseout'},
   onactive:{on:'onmousedown', off:'onmouseup'}
}

function parseStylesheets() {
   if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
   window.attachEvent('onunload', unhookHoverEvents);
   var sheets = doc.styleSheets, l = sheets.length;
   for(var i=0; i<l; i++)
      parseStylesheet(sheets);
}
   function parseStylesheet(sheet) {
      if(sheet.imports) {
         try {
            var imports = sheet.imports, l = imports.length;
            for(var i=0; i<l; i++) parseStylesheet(sheet.imports);
         } catch(securityException){}
      }

      try {
         var rules = (currentSheet = sheet).rules, l = rules.length;
         for(var j=0; j<l; j++) parseCSSRule(rules[j]);
      } catch(securityException){}
   }

   function parseCSSRule(rule) {
      var select = rule.selectorText, style = rule.style.cssText;
      if(!csshoverReg.test(select) || !style) return;

      var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
      var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
      var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
      var affected = select.replace(/:(hover|active).*$/, '');
      var elements = getElementsBySelect(affected);
      if(elements.length == 0) return;

      currentSheet.addRule(newSelect, style);
      for(var i=0; i<elements.length; i++)
         new HoverElement(elements, className, activators[pseudo]);
   }

function HoverElement(node, className, events) {
   if(!node.hovers) node.hovers = {};
   if(node.hovers[className]) return;
   node.hovers[className] = true;
   hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
   hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
}
   function hookHoverEvent(node, type, handler) {
      node.attachEvent(type, handler);
      hoverEvents[hoverEvents.length] = {
         node:node, type:type, handler:handler
      };
   }

   function unhookHoverEvents() {
      for(var e,i=0; i<hoverEvents.length; i++) {
         e = hoverEvents;
         e.node.detachEvent(e.type, e.handler);
      }
   }

function getElementsBySelect(rule) {
   var parts, nodes = [doc];
   parts = rule.split(' ');
   for(var i=0; i<parts.length; i++) {
      nodes = getSelectedNodes(parts, nodes);
   }  return nodes;
}
   function getSelectedNodes(select, elements) {
      var result, node, nodes = [];
      var identify = (/\#([a-z0-9_-]+)/i).exec(select);
      if(identify) {
         var element = doc.getElementById(identify[1]);
         return element? [element]:nodes;
      }

      var classname = (/\.([a-z0-9_-]+)/i).exec(select);
      var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
      var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
      for(var i=0; i<elements.length; i++) {
         result = tagName? elements.all.tags(tagName):elements.all;
         for(var j=0; j<result.length; j++) {
            node = result[j];
            if(classReg && !classReg.test(node.className)) continue;
            nodes[nodes.length] = node;
         }
      }

      return nodes;
   }
</script>


This code comes from here: http://www.xs4all.nl/~peterned/csshover.html

Now at the bottom of your stylesheet add this:

body { behavior:url("csshover.htc");   }

Making sure the path to the file from the stylesheet is correct - i.e. in this case it's in the same directory (in the example I've got all the rules in the document head).

And that's it.

The example will look a little odd because I've stuck all your CSS rules into the document head so all the paths to the images etc will be off - so ignore that.




Scotty -> RE: CSS horizontal drop menu problem in IE (6/18/2008 23:45:59)

quote:

Secondly, to make the dropdowns drop down in IE6 and under, copy the following code into a blank page of Notepad or whatever and save it as csshover.htc


Do I save as htc? or htm?...How do I open if htc?
Planting grapes in our 'spare time'...taking me awhile to get back to this.

Regards, Scotty
Go Obama!




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/19/2008 2:07:22)

Yes as .htc

You shouldn't need to open it but if you want to you can open it in Notepad.




Scotty -> RE: CSS horizontal drop menu problem in IE (6/21/2008 12:43:29)

Okay...I installed everything as I understood it to be...isn't working...do you have time to take a look?

Grapes are growing faster than we can prune and train...should end up with some great Pinot Noir (I think in France this is called Burgandy).

Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/21/2008 14:41:02)

I think the path to the .htc file is incorrect in the stylesheet - it's looking for it within the same directory as the stylesheet so you'll need to either move it there or change the path to reflect where it actually is.




Scotty -> RE: CSS horizontal drop menu problem in IE (6/21/2008 20:55:06)

I have the stylesheet 'Main' in the css folder
(that's where I had also put csshover.htc).

To rename it to reside in the css folder it would be:
body { behavior:url("main/csshover.htc"); } ?

I tried editing the stylesheet (Main) with that...no luck.
What am I missing?

Windy and warm here today.
Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/22/2008 2:46:17)

If it's in the same folder then it should just be "csshover.htc" but the thing is, from the URL posted above I can't find it in the same folder as the stylesheet either... odd!




Scotty -> RE: CSS horizontal drop menu problem in IE (6/22/2008 18:52:31)

So, how about I place it in a different location?

To rename it to reside in the media folder (Media folder is 1 level up from css folder, css is the folder that both main (stylesheet), and csshover.htc currently reside in.
So would that address be:
body { behavior:url("media/csshover.htc"); }

Thanks for the time.

Regards, Scotty




Scotty -> RE: CSS horizontal drop menu problem in IE (6/23/2008 0:11:36)

Tailslide; I got to thinking about what you said regarding not seeing the csshover.htc in the folder with Main (Stylesheet).

I went to a Browser then:

I typed in: http://www.loghomestore.com/media/css/main : and this I could open

then I tried: http://www.loghomestore.com/media/css/csshover.htc : and this apparently doesn't exist...but wait...I see a little ~ sign at the end of csshover.htc, so I slide the column width bar over and lo and behold, it says 'csshover.htc.htc...my my my...so a quick rename and I try it in Firefox...and it opens...woopee!
Then I try it in IE6...it opens a blank screen/page...and the drop still doesn't work.

Am I getting closer?

Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/23/2008 7:35:03)

Now you see why I avoid dropdowns a lot of the time!!

I think I fixed it - least it works for me locally now.

Add this line in:
#navigation li li a:link { padding: 0 18px 0 .4em }


under
#navigation li li a padding: 0 18px 0 .4em }


For reasons unknown IE seems to often need both "Whatever a" and "Whatever a:link" to get stuff working - it should do the same basic thing but...




Scotty -> RE: CSS horizontal drop menu problem in IE (6/23/2008 10:24:35)

quote:

#navigation li li a:link { padding: 0 18px 0 .4em }


Tailslide; I added this to the Main/Stylesheet file...Doesn't seem to be working yet...I'll look again in a few hours to see if I saved it wrong.

You mentioned previously how much fun drop menus can be...geez louise...my old java script menu was a piece of cake...but I figure if I use css I'll eventually learn to like it.

My pardner, Tracy Mae, is starting to mumble about needing a 'Scotland fix'...wouldn't be surprised to see her and her mum, head to Edinburgh next spring...once a Scot, always a Scot.

Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/23/2008 10:58:46)

Definitely working for me - here's a TEST PAGE Check out the bit I changed in the stylesheet.

Haven't been to Scotland in years and years - shame since we get free flights! It's so hard to arrange leave for my husband (we've only just had this summer's holiday which is in July confirmed as OK by his company! How are you supposed to plan anything like that?)




Scotty -> RE: CSS horizontal drop menu problem in IE (6/25/2008 22:36:34)

Explain to me please the concept behind
<a linkindex="1"...etc.
Is this the 'bit' you changed in the stylesheet?

Going to 95 degrees F this weekend...might finally dig out the hammock.

Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/26/2008 2:23:25)

Oh god no don't ask me to explain!!! I changed the link rule for the sub lists.

Where you've got:

#navigation li li a { padding: 0 18px 0 .4em }


I added the rule:

#navigation li li a:link { padding: 0 18px 0 .4em }


Ok so far as I know... when you use an "a" rule for a link that applies to all links on the page (or of that id etc) but an "a:link" only applies to uncached, unclicked links - so when you use this you have to also use the other link rules - visited, focus, hover and active to ensure that all states are dealt with. Also, an a:link can also override plain old a's.

I tend to use a:link rather than straight a's and sometimes find that IE6 in particular will ignore a:link without an added, identical a rule - sort of kick starts it. Weird. This appears to be the opposite way around.




Scotty -> RE: CSS horizontal drop menu problem in IE (6/27/2008 23:58:12)

Geez...I went to your 'test' page (and thankyou muchly for that), and followed it to
'scottycss.css', which I then pasted into and renamed 'main', assuming our drop menu should now work in IE6 as it's the same stylesheet that works in your TEST.
Nope...am I part way there?

Regards, Scotty




Tailslide -> RE: CSS horizontal drop menu problem in IE (6/28/2008 2:42:29)

!!!

Check the path to the hover file - I had it in the same directory as both the css file and the html file.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0703125