Monday, January 25, 2010

IE8 bugs in Windows 7 but not in Windows XP?

In the space of the last two days we've come across two completely different IE8 bugs (one in a Facebook app and the other on a new website) that occur in Windows 7 - but that are not happening in IE8 on a Windows XP machine.

Oh my lawd. Not only do we have to continue bug-fixing in IE6 and IE7 (when will that ever end?), but now we're seeing IE8 bugs that didn't exist in XP, but are showing up in the supposedly newer and better Windows 7. Microsoft really are deeply, deeply crap, aren't they?

I was able to fix the Facebook app bug (sight unseen because I don't have a Win7 machine) by applying the same bug fix to IE8 that I used on IE6 and IE7. In this instance it was a HasLayout issue, which is normally fixed with zoom:1 - and which I fixed with the old Holly Hack in Facebook cos Facebook returns errors for zoom.

Anyway, in this case a) the fix for IE6/7 worked for IE8 and b) it was the kind of fix that you can include for IE8 in Win7 that won't break IE8 where it's not needed in WinXP.

But what if I'd needed a fix for, say, the duplicate characters bug that requires a negative margin of -3px on the opposite margin to the direction of the float? If you include it in a compliant browser like FireFox it can break the layout in some situations, which is one reason why we put IE fixes in conditional stylesheets. But how do you include a conditional stylesheet for IE8 in Win7 without also including it for IE8 in WinXP? As far as I know that's not possible. I smell trouble!

The second instance of the Win7-bug occurred in a website we're building that has a bunch of jQuery in it for sliding images. At the moment I have absolutely no clue why it's happening, nor can I see it because it's not happening in WinXP. My first approach will be to see if I have any fixes already in place for IE6 or IE7, and add them to the conditional stylesheet for IE8. Maybe that'll work. I just hope it doesn't break IE8 in WinXP, assuming it works at all.

Has anyone else come across this IE8/Win7 issue?


Technorati tags: , , , , , , , , , , , , , , .

Saturday, January 09, 2010

A CSS/jQuery solution for creating multi-column lists

I seem to have found a solution for one of those front-end developer "Holy Grail" challenges - getting an unordered list to rearrange itself into two (or more) columns if the content of the first column gets too long.

Before I explain how to do it, I should point out that the vast majority of this solution is already out there in the form of a neat jQuery plugin called Columnizer jQuery written by Adam Wulf. I had nothing to do with the creation of it - I just stumbled upon it when I was googling for a solution, and wondered if I could adapt it for my particular layout problem. I added a bit of additional jQuery so it would do exactly what I wanted, and to my complete astonishment - it worked. Amazing!

There are a bunch of CSS-only solutions for multi-column lists which kinda sorta work - as long as you have a static list and can attach classes to various individual <li> tags. They generally work on the principle of moving some of the list items to a different position on the page using CSS - so that the list remains intact within the HTML, but appears to be broken up into multiple columns when viewed in your browser.

The CSS Swag: Multi-Column Lists article at A List Apart is one of the best examples of this, and in fact shows a whole bunch of different ways of achieving this goal.

However (and it's a big "however") - none of these solutions will work with a dynamically-generated list where you don't know from page to page how many items will be in that list, and where you can't add your own individual classes or IDs to each <li> in advance.

A perfect example of this situation - and the one I was wrestling with - is when you're building a set of templates which will be integrated into a CMS, and the unordered list in question is the subnav - which has to fit into a fixed-height space.

Here's what the subnav in my design normally looks like:

Single-column subnav list.
But... I do not know how many pages the client will end up creating within each subsection of their new website. What I do know is that the number of list items in each subnav menu will vary from section to section, and will be generated automatically by the CMS (which means I can't add classes or IDs).

So this is what I want it to do when the number of items in the list gets too long for the fixed-height space to contain them all:

2-column subnav list.
One thing to note: you need to be sure that your client isn't going to use massively long names for their pages, as these will generally translate into massively long links in the subnav, in which case you will soon run out of room - especially in the 2-column layout. You can pre-empt this by training them to use short page names and/or re-name them for the subnav. Most CMSs will let you do this - Silverstripe, for example, which is what we're using for this site - has an additional field in each page where you can define the text you want to be used as the subnav link. Very sensible.

Adam Wulf's plugin is designed to automatically lay out your content in newspaper column format. You can specify either column width and/or height or a static number of columns. I noticed that one of the lines of code in his jQuery was

$('li').addClass("dontsplit");
...which made me think he might have included something to ensure that lists which get split into two different columns still work properly - and he has! Clever man. We're 90% of the way there already!

I have nowhere near the technical expertise required to write my own jQuery plugins - or even to understand all the code within a plugin - but I do have enough of an understanding of jQuery to be able to utilise what others have created and adapt it to my own requirements - sometimes.

I'm not even going to try and explain how Adam's plugin works - because I don't actually know - I'm simply going to highlight the bits you need to make this list do its thing, and then show you the bit of jQuery I added which makes the list do one thing when it's short - and another when it's long.

Here's how I did it...

Read the full post