Category Archives: Style

StyleSheets, design and related issues.

Handy CSS

As I promised over two weeks ago, I’ve written some useful CSS that I’m going to share with you all. The first is used to identify links using relationships like rel="nofollow" and rel="tag", the second for identifying the language of a document being linked to, the third can be used either as a substitute for rel="external" on external links, or for identifying links to a particular site, and the fourth and final is Hixie’s Cat Attack Hack.

They’re not all new, some of you have probably seen or used similar variants before. However, that doesn’t make them any less useful, which is why I’m publishing them.

Relationships

The rel attribute is supposed to indicate a semantic link relationship from one resource to another. However, it has been very much abused lately for non-semantic, functional uses designed for a particular user agent (namely, search engines). The relationships I’m specifically referring to are Google’s nofollow, which I argued strongly against, and Technorati’s tag. (I know, I know, my current blog has them both cause they’re embedded in WordPress by default with no easy way to turn them off, but they will both be getting removed later).

a[rel~="nofollow"]::after {
    content: "\2620";
    color: #933;
    font-size: x-small;
}
a[rel~="tag"]::after {
    content: url(http://www.technorati.com/favicon.ico);
}

These make use of the attribute selector for space separated lists of values. Any a element with a relationship containing those values will be matched. Links with the nofollow relationship will be followed by a dark red skull and crossbones (?) and those with the tag relationship will be followed by the Technocrati icon. For the adventurous, you may wish to convert the Technorati icon to a data: URI; but if you do remember to either quote the data: URI or escape the special characters. See the CSS <uri> value for more information.

The nofollow style is a slight variation of the suggestion I found listed with the Nofollow Finder Greasmonkey script, and a slightly less irritating variation of Phil Ringnalda’s blinking lime.

Language

The hreflang attribute in HTML is used to indicate the language of the document being linked to; however, most user agents do absolutely nothing with it that is helpful for the user. So, basically, the only people that have used it in the past are people that actually care about semantics. Well, I’ve come up with a useful way to make use of it to identify links pointing to a document in a language I won’t be able to understand. Since I only understand English and because I don’t need to be explicitly told when a document is in English, those links won’t be indicated with this CSS.

:link[hreflang]:not([hreflang|=en])::after {
    content: " [" attr(hreflang) "]";
    font-size: xx-small;
    font-weight: 100;
    vertical-align: super;
}

Again, this makes use of the attribute selectors, as well as the commonly used :link pseudo-class. This first attribute selector matches any link with that attribute and the second matches when the attribute has a hyphen separated list of values beginning with en. The negation pseudo-class: :not(…) is a functional notation taking a simple selector.

Unlike the previous examples, this one is designed for use in an author stylesheet, not a user stylesheet. Many people make use of the non-standard rel=”external” relationship to indicate a link to an external site. However, adding that to each and every link is time consuming and and unnecessary. This style rule will place an north east arrow ( ?) after any link on your site to an external site.

[href^="http://"]:not([href*="lachy.id.au"])::after {
    content: "\2197";
}

It works by selecting any link with the href attribute beginning with “http://“, but does not contain your domain name. It uses two separate attribute selectors so that it will match when the URI uses the www. or not. So, the above will match not match either <a href=http://lachy.id.au…"> or <a href=http://www.lachy.id.au…">. If, you want to actually highlight links to a certain site, then just remove the negation pseudo-class, leaving just the two attribute selectors.

Hixie’s Cat Attack Hack

Anyone that regularly reads Hixie’s Natural Log will be aware of Hixie’s obsession with cats and those of us using Firefox will have noticed something very strange happenning with the autoscroll icon. When used, the normal autoscroll icon becomes extra large, there’s a picture of a cat in the background and the cursor becomes a pointer.

That trick, which I will call Hixie’s Cat Attack, makes use of the way Firefox inserts the autoscroll image as a direct descendant of the html element. This, which I will call Hixie’s Cat Attack Hack, simply reverses the effects of Hixie’s Cat Attack. This CSS, like the first two, should be placed in userContent.css in your profile directory.

html>img {
    width: 28px !important;
    height: 28px !important;
    background: none !important;
    cursor: normal !important;
}

Volunteer Wanted: CSS Artist

I’m looking for someone that can help me out with the Firefox 5 Minute Challenge that I’ve been working on over at SpreadFirefox. The CSS has been started, but still needs a lot of work, and I don’t have the time, nor the ability to get it working properly anytime soon, so I’m asking one of my loyal readers would like to volunteer to complete the CSS for me. Not only would you be doing a huge favour for me, but you’d be contributing to a great cause – Spreading Firefox!

If you can help out, leave a comment with your contact details or e-mail me <lachlan.hunt (AT) spreadfirefox.com>. Most of the files you’ll need are already available for you to work with, just download them and get started. I can send you all the source files if you need to re-create any of the images for any reason (eg. to fix image sizes, especially for the header and logo), and for the few images that aren’t up yet.

Note: One thing you should take note of is that file paths in the markup and CSS do not include file extensions because this server is set up with multiviews to handle the alternate languages and file formats. If you’re not developing it on a testing server with multiviews enabled, then you’ll need to add the file extensions or the browser won’t find the files.

Since IE users are the target audience for the page, it needs to work fairly well in it. It doesn’t need to be pixel perfect, but needs to be visually appealing for any IE users. It should work perfectly in Firefox because it would be fairly embarrassing to promote Firefox with a page the doesn’t work in it. If possible, I’d like it to work in IE 5.x, but that’s not a priority – aim for IE6 at least.

iiNet Standards Redesign

Recently, and to my surprise, iiNet have redesigned their entire site. Not only that, but it validates as XHTML 1.0 Transitional, separates presentation from structure (no tables for layout!), makes reasonably good use of alt text (it’s not perfect, but it’s quite good), fairly accessible use of JavaScript (no serious problems caused with it disabled) and even makes good use of sIFR!

iiNet have discussed this re-branding from a marketing perspective. That’s fair enough, a typical customer isn’t going to want to hear about their new found standards compliant and accessible design methods. So, in the process of congratulating them for this fine effort, I’ll take a look at exactly what they have done.

Structure and Presentation

Disabling stylesheets quickly reveals that they have actually put in a lot of effort into this redesign from the previous. The old design was a typical table layout with spacer gifs, invalid markup and a few pages just didn’t work correctly in anything but IE. With the redesign, they’ve used reasonably semantic markup – headings use <hn> elements, paragraphs use <p>, navigation menus and other lists use <li> and there’s no use of presentational class names or ids.

They have, unfortunately, used a few style attributes, but not many. Most of the presentation is specified in an external stylesheet. Ideally, they would use a semantic class name on those few elements that currently use the style attribute, but the damage caused is minimal

As I mentioned earlier, the markup does validate as XHTML 1.0 Transitional, with the exception of one image missing an alt attribute on this page discussing their re-branding. However, it is a presentational image, and only requires an empty alt="" attribute anyway. The home page nearly validate as Strict, however the only errors seem to be structural, due to <input> elements being directly inside a <form> element, the use of a name attribute in a <form> element and the use of a target attribute, which I strongly discourage. They’ve also used an invalid value: target="_new". The HTML 4.01 Specification states:

Except for the reserved names listed below, frame target names (%FrameTarget; in the DTD) must begin with an alphabetic character (a-zA-Z). User agents should ignore all other target names.

This means, that except for the special defined values, _blank, _self, _parent and _top, the value must begin with an alphabetic character. Thus, _new is invalid, even though the validator does not detect it. But, you must keep in mind that the validator is just a tool, and cannot check every conformance requirement, only those specifiable with the DTD. So, technically, they should be using _blank, but ideally, they should remove the target attribute completely, since the user should decide when they want a new window, not the author.

XHTML vs HTML Markup

Update: One thing I forgot to mention earlier, and hence why I’m adding this update, is that technically, they should not be using XHTML since they are serving it as text/html, and doing so is considered harmful. If they’re going to use XHTML, they should be using content negotiation to deliver it correctly as application/xhtml+xml to descent UAs that support it, and text/html to IE, and other legacy UAs that don’t. However, as many of you will know, this issue has been discussed recently. Some say it’s OK, other’s (like myself) think it should be avoided, and other’s insist that it should not be done. These people categorised into either the Stict or Transitional Party.

If they’re not going to serve XHTML properly, then they may as well use HTML 4.01 Strict. I recommend they change to Strict, because Transitional actually triggers Almost Standards Mode in Mozilla. It is near enough to standards compliance, but it adds a small quirk that should not be there, and only exists to support the thousands of pages that depend on IE’s bugginess, yet still use a valid DOCTYPE.

Images and Alt Text

As mentioned, there is one image that I found without alt text, but other than that, they seem to have actually done a reasonable job. Although, ideally, (in this case) the images should have exactly the same text as the images do, however, they have used text with a similar meaning, and viewing without images doesn’t loose too much.

For example, one image they have at the moment, states christmas broadband specials. Free Setup + Modem. Save up to $199.95. However, they have set alt="christmas special - free setup/modem". It misses the price, but it still passes a message that is close enough, especially compared with the vast majority of sites that use very poor, or no alt text whatsoever.

They have made use of Image replacement techniques for the navigation items, though not in the most accessible way. However, that’s limitation with CSS and image replacement techniques in general. iiNet have done image replacement by setting the background image on the <a> element for each link, so that hover effects still work in IE, and set the font to 1px, white to effectively hide it from view. However, like many image replacement techniqes, this is inneffective in the rare case that images are disabled, but CSS is enabled.

For many the headings, they have made use of sIFR, which was designed and developed to be accessible in the majority of cases. It has known limitations, but so far, is the most accessible image replacement technique available.

JavaScript

The site does make some use of JavaScript, however the site does not require it. With JavaScript disabled, the only issue I found was that the what’s webmail and what’s toolbox links don’t work. They are JavaScript links with the purpose of showing additional information about the webmail and toolbox services. Ideally, with JavaScript disabled, that information should be visible by default, but the additional information is not that much, and can be obtained by disabling stylesheets also. The links should also be added using JavaScript, so that useless links do not appear for users with JavaScript and/or CSS disabled, but again, it’s a minor issue.

So, in conclusion, I would like to congratulate iiNet for taking the initiative to move towards standards compliance, and for actually hiring a web developer that knows what they’re doing. Well Done!