Archive for css

fixing IE7 layout problems

As I noted earlier, while IE6 displayed this site (in Nearly-Sprung) correctly, IE7 did not.

The reason is this: the bug in IE6 and previous that allowed the following CSS hack to work


* html .anelement { layout fixes }

has been fixed in IE7. However, many of the layout issues that were fixed in the escaped code have NOT been fixed. In my case the particular culprits were these:

/* Essential Layout (IE Fix) */
* html #leftsidebar {
        left: 150px;              /* RC fullwidth */
}

/* Hides from IE5-mac \*/
* html li {height: 1%;}
/* End hide from IE5-mac */

/* Hides from IE5-mac \*/
* html #postnavigation {width: 145px; height: 2px;}
/* End hide from IE5-mac */


IE7, like IE6, needs the left: setting, but as it no longer works with the * html escape (for an explanation of why this is, see the excellent article here) it is not getting these settings as it should. The result on my site was the left sidebar’s utter disappearance.

The workaround is to isolate the IE hacks into a separate .css file and call it with an escape that all IE derivatives still honor. (Wonder how long this escape will last…) While tedious, this is overall a better solution than embedding hacks within a css file. Such hacks can be relegated to a separate file which can later be removed when IE is finally fixed (these glasses seem awfully pink, don’t they?).

So, in general this is the way to fix such problems. I checked my css files for any instances of


* html

Some of these might be in a “holly hack,” which should be moved along with the rest of the markup.

I created a new css file, iehacks.css is fine, and dumped all the hacks into this file. Now, I removed all instances of * html (this is the crucial part, otherwise no improvement is seen for IE7). In my case, this new file wound up containing the following:


#leftsidebar {
        left: 150px;              /* RC fullwidth */
}

/* holly hacks to fix peekabo bugs in IE */

/* Hides from IE5-mac \*/
li {
        height: 1%;
}
/* End hide from IE5-mac */

/* Hides from IE5-mac \*/
#postnavigation {
        width: 145px; height: 2px;
}
/* End hide from IE5-mac */

(Note the holly hacks in the last two rules.) Now, I needed to modify my <head> element to include this css file, which was easily done via adding

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="iehacks.css" />
<![endif]-->

In WordPress, this meant modifying my header.php file (of course I made a backup copy of it first) as follows:


<!--[if IE]>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/iehacks.css" />
<![endif]-->

I added this just before the call to wp_head. This would make a VERY simple plugin; I could create one if people wish. But this is pretty straightforward as is.

Update
Probably the best way to do this, allowing for testing in IE7 before proceeding completely, is to copy the suspect elements over to the new css file. Since IE7 doesn’t work with the current css file anyway, it doesn’t hurt to leave the elements in place while getting the iehacks file to work. Add the [if IE] call to the headers and check in IE6, IE7. Once everything looks okay, then remove the suspect elements from the original css file, one by one.

del.icio.us:fixing IE7 layout problems  digg:fixing IE7 layout problems

Comments (5)

notes from cross browser compatibility

For tables,


border-spacing: 0px;

works fine in every browser (Opera (PC, Linux), Firefox (PC, Linux, Mac), Safari) except IE6 to eliminate the bit of padding around the table and its border and around each table cell. For IE6, it’s necessary to use

border-collapse: collapse;

which works all of the above browsers. I even checked Mac IE which didn’t recognize either, but it’s so dead in the water it can be ignored at this point.

According to W3, both seem to be valid markup (as opposed to made-up stuff introduced ad-hoc that no one should ever use).

This is the start box with no properties specified. Note the table background color peeking around the entire table and between each cell:

with no properties
row 1 row 1 row 1
row 2 row 2 row 2
row 3 row 3 row 3

With this next box, everyone but IE6 users should see a nicer alternating-row look:

with border-spacing property
row 1 row 1 row 1
row 2 row 2 row 2
row 3 row 3 row 3

With this one, everyone should see a nice alternating row color:

with border-collapse property
row 1 row 1 row 1
row 2 row 2 row 2
row 3 row 3 row 3

And now everyone (but the poor Mac IE users, of course) should see alternating rows:

with both properties
row 1 row 1 row 1
row 2 row 2 row 2
row 3 row 3 row 3
del.icio.us:notes from cross browser compatibility  digg:notes from cross browser compatibility

Comments (2)

detouring css through php

One thing that tends to drive me nuts when putting a css file together is repetition of the colours. CSS has no mechanism to define constants or variables and it can be pretty tiresome playing around with resetting the colours and such when tweaking a web page.

So I made mine into a php file. There’s a few tricks, but it’s very straightforward. First, you call it in your main html file (or output) as with any other css file, only with it’s name:


<link rel="stylesheet" href="k9web-css.php" type="text/css" media="screen" />

Now here’s the fun part. The first line in the php file must now be:


<?php header("Content-type: text/css");
/* this tells the browser this is a css file! */
?>

Otherwise the file is sent as text/html and I get unhappy junk printed out. With that out of the way, the top of the file can contain something like this:


<?php
/* define colours, etc here */
$darkgrey="#555";
$lightgrey="#ccc";
$offwhite="#f6f6f6";
$cream="#ffffe7";
$brightred="#ff0000";
$darkred="#aa0000";

/* change these to change color scheme */
$bgcolor=$cream;
$fontcolor=$darkgrey;
$linkcolor=$darkred;
$hoverlinkcolor=$brightred;
?>

Now I proceed with the rest of the css definitions as usual, but when I want to use a defintion, I pop it in like this:


a:hover {
        color: <?php echo $hoverlinkcolor ?>;
        text-decoration: underline;
}

Looks like someone else (actually many people; try googling on “variables in css”) was addressing the same problem. My solution is pretty straightforward, although it does require access to php, etc. This solution hides it but amounts to using php to parse and replace behind the scenes, so I think my solution is at least more direct…

del.icio.us:detouring css through php  digg:detouring css through php

Comments (4)

revenge of the css

Well, I’m still hard at work revising the entry page for SCLRR. I have a number of variations, here, here, here, and here. Of course there’s the usual stuff in dealing with a committee of people and a plurality of decisions. We’ll get there. Also the switch over between a shell account with a redirect for the domain (sooo late nineties…) to an actual hosted domain has gone fairly smoothly, although I expect I shall shortly hear from a multitude of volunteers who had their computers memorize their passwords so that they’ve long since forgotten what they are…

The real story is in those drop down menus. I got the idea from A List Apart which has a gorgeous css only (well mostly) drop down menu styling. It seemed like this would be the perfect solution to so many links as on the old one.

Oh dear. That “mostly” contains a drama in of itself. Because it seems that most browsers do just fine with the css definitions which basically involve defining the display to none for the li containers in the ul list (really, really elegant) and then changing the display back to block on hover.

Except of course our dear old friend Internet Explorer 6 doesn’t do hover when it’s not a link. Pish. So there’s a little javascript hackery that rewrites the hover routines on the fly for IE6. All well and good, I snarfed the css file examples, integrated them into the css and js files and went about happily buffing and polishing the newindex page.

Of course, the astute reader will recall that not only do I use Firefox, but I also work on Linux (Ubuntu, and yes I’m ecstatic that Dapper Drake comes out tomorrow, though I’ve been using the Dapper Beta for the last month and titch) so he or she will spot the looming cliff that I am oblivious to. I am also dealing with a crew of very non tech people, so they are all using IE6 hands down.

And of course it turns out that the dropdowns aren’t working at all in IE6. Figuring a conflict between css elements from the original css file with the new stuff, I copied just the example over and sure enough that worked. So I slowly added in all the decorative elements: the background, border, table, finally the multiple column…and it all works!!

So why doesn’t it work on the index?? I start to add in the actual copy (bidding farewell to the trusty lorem ipsum) piece by piece and it finally dawns on me that the javascript for the slideshow is conflicting with the javascript for the hover rewrite. At first I thought it was due to some IE6 weirdness about mixing inline and external js (the slideshow has some elements that must be inline because the perl script generates the values on the fly) but that wasn’t the case. I finally tracked it down to a conflict over the onLoad in windows. Seems that IE6 doesn’t like two of them. When I combined the calls in a single function, it demonstrated its further fussiness by working only when the two were called in a certain order. (I tested this in IE7, by the way, and it worked without the javascript: hallelujia, praise the lord and pass the ammunition.)

So, it was very wrong of me to blame all the problems on the css. I’ve learned that lesson…

del.icio.us:revenge of the css  digg:revenge of the css

Comments

Bad Behavior has blocked 441 access attempts in the last 7 days.