We've moved!

TechKnack.blogspot.com has officially moved to TechKnack.net. You should be redirected in 3-5 seconds. Thank you.

January 14, 2008

CSS trick - two background images

Add this post to Del.icio.us. Del.icio.us (0 saved)

Download Example

While using what I'm sure is my own idea of progressive enhancement on a web page, I came across an interesting situation: I wanted two background images, rather than one. My first background would be a general tiled image, to give the site's background a nice texture; the second a vertically-repeated image on the left-hand side, to be used in conjunction with a floating nav menu.

Now, while CSS3 is purported to support up to 8 background images -- no doubt to make rounded corners and other fancy borders easier for coders -- the problem is that, to the best of my knowledge, IE and FF don't yet support this feature. Besides that, IE6 and lower never will. And I'm not even sure this feature will be usable for what I want, anyway.

So, I had to have (ok, really, really wanted) the left-hand background, and, IMO, the page looked too bland without some texture on the general background. As I already had the structure of the page decided upon (and, as such, couldn't modify it for presentational purposes), I started looking at what I had to work with. There was obviously the body tag, but there was nothing much else to work with...besides the html tag itself.

I already had the vertical background applied to the body tag, so I started by removing the background color from body (so the html background could show through). I then applied the same background color and the new background image to the html tag:

html { background:#000 url("tiled.png"); } body { background:url("vertical.gif") repeat-y; background-position:75px top; }

And, whaddaya know, it worked! Unfortunately, it seems that declaring the html element's style in my CSS changes the basic behavior of the body element, making it more like a containing div. The result: there's a margin around the content, and the vertical background only goes to the end of the content. Yuck.

So, the first thing to do is fix the ugly margin. Easy enough: set body's margin to 0 , as well as body's padding for good measure. Next, fix body's background. Currently, the background stops at the end of the content area. Not a problem if the content causes the window to scroll, but not pretty if there's not enough content. I figure this should be easy enough to fix, just set body's height to 100%. This works well enough...in IE6. Strangely, FireFox 2 doesn't take so kindly to it. Changing the body's height to "auto" works alright, for both browsers, for overflowing content, but not for short content. A height of "auto" and a min-height of 100% works excellently in FireFox 2...but, again, IE6 doesn't know how to treat min-height. Good grief.

So, I enter the realm of CSS hacks. Using a min-height hack combined with advanced CSS selectors that aren't understood by IE6 and less, I combine the methods that worked for each browser into a series of rules that are "browser-filtered" - one browser uses one method, while another browser uses the next.

html { background:#000 url("tiled.png"); /* Height is 100%, so the body can be 100% */ height:100%; } body { background:url("vertical.gif") repeat-y; background-position:75px top; margin:0; padding:0; /* Height is 100%, so the tiled BG will tile all the way down the page, not just as far down as the page's content (when the content's height is less than the window's height) */ height:100%; } /* Hackety-hack-hack... FF2, with the above code, will only display the repeat-y image for as high as the window's viewport is; higher content (upon scrolling) will not have the bg. This "hack" makes the tiled background work properly in FF2. This type of "advanced selector" is not understood by IE6...dunno 'bout IE7. */ html>body { min-height:100%; height:auto; }

The common html code works fine on both browsers. It's only the body's height issue that needs resolved. The IE6 code is given in the body code; both browsers will see this and understand it. However, when they get to the html>body statement, IE6 says "wha??" and drops the rule, whereas FF2 says "ok..." and applies the appropriate styles to the body tag, overriding the earlier-mentioned height.

December 29, 2007

Backing up Thunderbird or Firefox profiles

Add this post to Del.icio.us. Del.icio.us (0 saved)

The mantra of the Linux world is "Always backup important data!!!" This is usually instructed directly before installing Linux onto a system, or otherwise doing anything that could even remotely corrupt anything. Better to be safe than sorry.

Backing up a Thunderbird or Firefox profile is important, too. Especially if you're like me, and it would take hours to get Firefox just perfect again after having your profile wiped (if, for example, the drive it was sitting on were to fall to minor corruption). Hunting down that perfect theme (what was it called again?), rounding up all those can't-live-without extensions...

Under Windows

Under Windows XP (and presumably Vista as well), the default profile for Firefox is found under C:\Documents and Settings\<user>\Application Data\Mozilla\Firefox\Profiles\XXXXXX.default, where that last XXXXX is a random string of numbers. Thunderbird's profile is located under C:\Documents and Settings\<user>\Application Data\Thunderbird\Profiles\XXXXXX.default. If you've used "firefox -ProfileManager" or "thunderbird -ProfileManager" to change your profiles around, these will be different.

Under X/K/Ubuntu

Under Kubuntu (and presumably most or all flavors of linux), Firefox's default profile is under ~/.mozilla/firefox/XXXXXX.Default User. For Thunderbird, it's ~/.mozilla-thunderbird/XXXXXXX.Default User.

Methods of backup

A quick google search can turn up lots of methods of backup, including MozBackup. While I haven't used this extension myself, I've no doubt that it works to some extent (or else it wouldn't have lasted as long as it has). If you prefer GUI solutions, by all means, try it out.

My preferred method, however, is to make a .7z archive of my profile directory (make sure TBird or FireFox is shut down before you zip the archive, though!) This essentially takes a snapshot of the program (including extensions, skins, even open tabs and windows if the "Show my windows and tabs from last time" option is set!); if your profile ever gets corrupted, you can simply unzip the "saved profile" over the current profile, restoring it to the "last known good configuration", to quote windows.

Another advantage to the zip-it-up method is that you can create "holes" in the profile. For example, with the "Show my windows and tabs from last time" option set, Firefox will leave a sessionstore.js file inside the profile directory; the next time Firefox opens, it reads this file and re-opens all your tabs from last session. Deleting this file from the zip archive creates a profile hole that the more up-to-date sessionstore.js can fit into. Very handy at times.