nooshu - Matt Hobbs' Web Development Blog

Kneeling on the shoulders of giants

Category: CSS

Post related to Cascading Style Sheets and other frontend development.

NASA Picture of the Day CSS Design Challenge

A website I check on a regular basis is the NASA’s Astronomy Picture of the Day, a superb site if you’re interested in the Cosmos; it publishes a new picture each day with an explanation written by a professional astronomer. Amazing stuff… apart from the design is… just horrible! If you want an example of what the web looked like back in the mid nineties, then take a look.

Now I doubt restyling the website is high up on NASA’s priority list, but there’s no reason a user can’t do it for them (only on their own machine of-course). All you need is Firefox and a custom CSS file.

The CSS file you will need is called userContent.css, and it resides in your Firefox profile under the ‘chrome’ directory. To find your profile directory look under ‘Help’ > ‘Troubleshooting information…’, there you will see a button to open the profile directory (Note: I wouldn’t change much in here, it can break your profile!). If you still can’t find it you can always look here. You may not have a userContent.css by default, so feel free to create a blank one.

This is when the fun starts, first you want to add this code snippet:

1
2
3
@-moz-document domain(antwrp.gsfc.nasa.gov) {
    /* Page specific CSS here */   
}

This is a Mozilla specific property that will allow you to include CSS for pages on a specific domain; note the ‘antwrp.gsfc.nasa.gov’. Feel free to add as little or as much CSS as you want until you are happy with the page layout. Here’s a sample from the userContent.css file I created:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@-moz-document domain(antwrp.gsfc.nasa.gov) {
    /* authors and editors */
    body > hr ~ center:nth-child(5) {font-size: 0.69em;}
    /* all b's */
    body > hr ~ center:nth-child(5) b {
        margin: 8px 0 0;
        font-size: 1em;
        line-height: 1.4;
        }
    /* first b */
    body > hr ~ center:nth-child(5) b:nth-child(1) {margin: 32px 0 0;}
    /* all a's */
    body > hr ~ center:nth-child(5) a {font-size: 1em;}
}

To make the page look in any way presentable I’ve had to rely heavily on the new CSS3 selectors available in most modern browsers; as the state of the mark-up on the pages is truly awful. I guess it all adds to the challenge though, it’s certainly a great way to learn CSS3.

Here are a couple of before and after images I created, nothing spectacular but hopefully it looks slightly better:

Nasa picture archive, before and after.

Before and after screenshot of the archive page.

Nasa picture of the day, before after

Before and after screenshot of the daily picture page.

The ‘index’ page was a page to far for me, I have no idea what the developer was trying to do with the mark-up, it’s overuse of tables for layout really doesn’t help either. On the end I got bored but feel free to dive in and take a look.

It’s also worth mentioning that it is possible to customise the style of any website using a Firefox plug-in called Stylish, you can view many examples of it’s usage on userstyles.org.

Here’s the link to download the userContent.css I created, I’d love to see what other designs people can come up with using some CSS3 and NASA’s horendus mark-up!

Useful websites for a Front-End Web Developer

Over the past few days I’ve compiled a list of websites I use quite frequently that really help speed up the Web Development process. The sites won’t build your pages for you but they can certainly help when it comes to debugging and problem solving.

Clean CSS

I have been using Clean CSS for a few years now to clean up and optimise my CSS. The tool will give you a break down of where you can be making optimisations and also point out potential issues with invalid properties. You can either apply the changes manually, as it gives you a line number (my prefered method) or you can download the output as a file. I must admit I only use it every so often as I’ve merged most of the optimisations into my working process.

An exception to that rule is when working with other peoples CSS, it’s always my first port of call. There’s even the ability to create your own template, so the CSS can be formatted just as you like it when it comes out the other end.

CleanCSS GUI

The CleanCSS interface simple to use with lots of options to play with.

Snipplr

Snipplr has been around for a couple of years now, it’s a excellent place to store all those little snippets of code that you often use. You can view other peoples snippets too, so if you’re looking to a solution to a problem there’s no need to re-invent the wheel; look see if someone else has a solution.

The only real issue I have with Snipplr is the amount of spam it receives, which is a real pity as it’s such a useful tool. Maybe that’s something the developers can look into fixing.

Em Calculator

For a few years now I’ve been setting my font sizes using the relative unit em’s rather than pixels or points. This was due to the fact that if you set your font size in pixels, IE6 users can’t increase the font size due to IE6 being… erm… a truly awful browser; not good at all for accessibility. Luckily IE6 is gradually fading away and IE7+ all scale font sizes properly, so in the future this tool won’t be needed.

The problem with using relative font sizes comes when you have a nested elements. Say you have an unordered list with its font size set to 12px (0.75em) and you want one of your list items to be set to 10px (0.63em). Since we are using relative font sizes the 0.75em has an effect on the lower list items. If you simply set the the list item to 0.63em the text size will be tiny because you are asking the browser to set a size of 0.63em of 0.75em. Not what we wanted at all! This is where Em Calculator comes in useful as it does all the calculations for you. You actually needed to set the list item to 0.83em….duh!

Em Calculator interface for quick relative font size calculations

An example of how Em Calculator works with my example unordered list.

jsFiddle

I’ve mentioned jsFiddle before, it’s a tool that allows you experiment with HTML, CSS and JavaScript and see the results on the same page. In the past couple of days they’ve added a new version of Processing and the RaphaelJS library. A link to my previous post on jsFiddle is available here.

HTML Entity Character Lookup

If you’ve ever had to build a set of multi-lingual HTML emails you will know how tedious it can be to encode all characters so they are valid HTML. Lucky with HTML Entity Character Lookup by LeftLogic it’s simple. Copy and paste the character you want to encode into the tool and it will give you encoded version; do a quick search and replace then you’re done.

HTML Entity Character Lookup by Leftlogic

Quickly lookup character entity's using Leftlogics tool.

For OS X users there’s also a dashboard widget you can use for easy access.

CSS Sprite Generator

Using the sprites method can speed up your page load time by minimising the number of HTTP Requests a users browser has to make to the server. It involves consolidating all your little icons and background images into one file, then moving that one image around using the background-position property.

You could do this manually in Photoshop, or you could get an on-line tool to do it for you. CSS Sprite Generator is my favourite of the sprite generators available. Simply ZIP up the files you want to sprite, upload them to the tool and it will return one large image and all the relevant CSS background-positions for you to copy / paste into your CSS file.

It’s particularly useful when it comes to site navigations. Having the off, on and hover states all in one background image means the user doesn’t see that ugly flash of unstyled content as hovering over the navigation bar, since all states are loaded when the user first hits the page.

Are there any others I’m missing? Post a reply if there are others you use.

jsFiddle: My new favourite website

Every so often you come across a site that is so amazingly obvious that you think “why didn’t I think of that!”, jsFiddle is one of those sites. It allows you to paste your HTML, CSS and JavaScript code, and view the result all in the same page…simple! There are other sites out there that do the same such as Jsbin, but they just don’t do it as well.

My favourite feature that really stands out is being able to include one of the many popular JavaScript library’s by simple toggling a drop-down box; it even has different versions of each library to choose from. This is a really handy feature if you are a plug-in developer; keep your plug-in code in jsFiddle and quickly see if the latest version of the library breaks it.

jsFiddle code snippet GUI

Quickly view your code change at the touch of a button

Library’s included so far are:

  • Mootools Core
  • jQuery
  • Prototype
  • YUI
  • BBC Glow
  • Dojo
  • Processing.js

A couple of other features available are the easy to access code examples for each library and ability to run Ajax requests directly in the page. It’s like a mini IDE in your browser, all it needs now is an error console; maybe that is on their to-do list. If you don’t use JavaScript library’s and just want vanilla JavaScript, they have that option too.

As an example I’ve added my charactersLeft jQuery plug-in to jsFiddle, take a look here. Very cool huh!

Currently on page 2 of 212