html archives
“CSS is the weakest link in the web developers toolbox. The problem goes deeper than CSS’s lack of variables. Unlike the “function” in programming, CSS has no fundamental building block.”
Chris Eppstein, the author of Compass writes up a solid argument for the need of abstraction in stylesheets. I’ve been toying around with Compass and the Sass language over the past few weeks and things look very promising.

posted by john on Monday, Sep 21, 2009

Firescope is a free Firefox add-on from Sitepoint that puts a Reference tab into Firebug. This tab gives an overview of the level of browser support for a selected element and any styles applied to it, plus a link to more information on Sitepoint about elements and attributes. Looks very handy for troubleshooting… Download took about 3 seconds, plus a re-start of Firefox.

posted by ted on Wednesday, Feb 18, 2009

case study

Hot and graceful jQuery dropcaps

Dropcaps are a staple of magazine and newspaper design, but aren’t always the easiest to implement on the web. Using this little jQuery and CSS tutorial, you can easily add hot little dropcaps to your web articles without bothering your developers. This method will also let you sleep at night knowing your caps will degrade gracefully, displaying just fine in browsers without CSS or JavaScript enabled.

Please note, this tutorial is for those who are familiar with jQuery and CSS. No basics taught here. Also nerd alert.

Here we have a flippin’ sweet dropcap on an article page for the new Combating Pornography website we’re building (launching early 2009).

Tadd recently noted that he’s been using some nice CSS 2 selectors in the new General Conference design. In his example, he’s styling the initial character of the article with CSS typography. Noble indeed.

However, I am more of a type snob and wanted my dropcap to be set in Caecilia, matching some other type found throughout this new site.

(Yes, this means saving 26 images of dropcaps in Photoshop. Luckily this took me all of 10 mins. As for translated sites, more on that below.)

So our task is to style the initial character with a background image, with hand-adjustable pixel spacing around each individual letter, and in a way that degrades as gracefully as Audrey Hepburn if she were a nerded-out website.

I also don’t want to bother the developers (who read this blog – hi Mindie!) to put a <span> around the initial character, and I really don’t want to beg them to throw a different class on that span depending on which letter of the alphabet that character is.

Sound like a daunting task? It’s not.

HTML it up

First let’s make sure the HTML is set up nice and easy:

Here we have the initial paragraph from Michael Gardner’s article on Hope, Healing, and Dealing with Addiction (here is the full comp so you have some context). No spans, no special classes. Easy fo’sheezy on the developers.

jQuery action

Next we hook up our page with some jQuery, and start the show.

<head>

<script src="scripts/jquery.js" type="text/javascript"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){ 

});
</script>
</head>

Inside our jQuery block, we’ll first grab the first paragraph in our article (in my case, inside my “body” div), and add a class of “dropcap” so we can remove the indent and refer to it later:

$(document).ready(function(){ 
    p1= $("#body p:first");
    p1.addClass("dropcap");
});

Next, we need to grab the text from the first paragraph. We do this by taking the actual paragraph element from our p1 object, and asking it for its content using a standard JavaScript function, “textContent.” We also want to strip out any leading spaces or quotes, using some regular expression magic:

$(document).ready(function(){ 
    p1= $("#body p:first");
    p1.addClass("dropcap");
    p= p1[0].textContent.replace(/^\s+/, "").replace(/^"/, "").replace(/^'/, "");
});

Next we need the initial character from that paragraph (whic we know is alpha-numeric), using the standard function “charAt.”

$(document).ready(function(){ 
    p1= $("#body p:first");
    p1.addClass("dropcap");
    p= p1[0].textContent.replace(/^\s+/, "").replace(/^"/, "").replace(/^'/, "");
    c= p.charAt(0);
});

Now comes the money. In one statement, we will replace the html inside our jQuery object (p1) with a new block of code that wraps the initial character in a span, adds a class of “dropcap-” + the initial letter (don’t forget the lowercase), and adds a style with a background image for that specific letter. Check it.

$(document).ready(function(){ 
    p1= $("#body p:first");
    p1.addClass("dropcap");
    p= p1[0].textContent.replace(/^\s+/, "").replace(/^"/, "").replace(/^'/, "");
    c= p.charAt(0);
    p1.html('<span class="dropcap-' 
        + c.toLowerCase() 
        + '" style="background-image: url(images/drop-' 
        + c.toLowerCase() 
        + '.jpg)">' 
        + c 
        + '</span>' 
        + p.substring(1, p.length));
});

Beautiful. The resulting HTML:

CSS magic

The code above adds a specific class and (gasp!) an element-level style for one reason: keep it simple for the developers (and me).

By giving each letter its own unique class, I can adjust the pixel padding as I see fit. By defining the background image on the element level, I don’t need dozens of lines of code in my CSS file to define each letter class and each letter background. jQuery does it for me.

In our CSS file, I have the following block of code to manage the paragraph:

/* dropcaps */
#body .dropcap{
    text-indent: 0;
}
.dropcap-a, 
.dropcap-b, 
.dropcap-c, 
.dropcap-d, 
.dropcap-e, 
.dropcap-f, 
.dropcap-g, 
.dropcap-h, 
.dropcap-i, 
.dropcap-j, 
.dropcap-k, 
.dropcap-l, 
.dropcap-m, 
.dropcap-n, 
.dropcap-o, 
.dropcap-p, 
.dropcap-q, 
.dropcap-r, 
.dropcap-s, 
.dropcap-t, 
.dropcap-u, 
.dropcap-v, 
.dropcap-w, 
.dropcap-x, 
.dropcap-y, 
.dropcap-z {
    width: 75px;
    height: 80px;
    display: block;
    text-indent: -5000px;
    float: left;
    margin-top: 5px;
    background: transparent top center no-repeat;
}

.dropcap-a{ width: 95px;}
.dropcap-d{ width: 85px;}
.dropcap-h{ width: 85px;}
.dropcap-i{ width: 56px;}
.dropcap-j{ width: 56px; height: 85px;}
.dropcap-k{ width: 85px;}
.dropcap-m{ width: 100px;}
.dropcap-n{ width: 85px;}
.dropcap-q{ width: 85px; height: 90px;}
.dropcap-u{ width: 85px;}
.dropcap-v{ width: 85px;}
.dropcap-w{ width: 120px;}
.dropcap-x{ width: 85px;}
.dropcap-y{ width: 85px;}

I’ve removed the text-indent on this first paragraph, and defined the basic styles for each dropcap, including custom pixel widths for a few.

This method ensures that for anything not defined, like a Chinese or Spanish character, the styles won’t apply and you still have a perfectly fine-looking page no matter what your first letter is. It also means that if you were so inclined, you can define styles and images for any character (as long as your server / target browser supports those characters):

Not only is this saving me hassle, this is saving a decent amount of Java (or Ruby or PHP) code for our developers, and enables me to hand over an even more complete prototype.

Big ups to Pete Lasko, who nerded out with me and helped with some of the code.

posted by jason on Tuesday, Dec 02, 2008

case study

The Accessibility Checklist
I Vowed I’d Never Write

Update: The below checklist is now available in German.

I have said on numerous occasions that there is no simple checklist that, when followed, will give you an accessible site without fail. There are simply too many variables. But, what do you do when you want to create accessible pages and you have dozens or even hundreds of developers who (like most of their peers) have little to no experience with accessibility? What do you do when it just simply isn’t practical to have someone review all of your pages? In short, how do you insure that a very large organization creates pages that can be accessed by the largest audience possible without drastically increasing your budget? This is one of the questions we have been (and continue to) struggle with.

I believe that in order to solve this problem, we will need to take a multi-faceted approach. However, one element which seems inevitable is training for our designers and developers. I don’t think it’s reasonable (no matter how much I would like to try) to make our devs and designers into accessibility experts, so what can we do? If we can’t yet achieve excellent accessibility, what about simply doing better than we are doing now?

When I wrote the below checklist, I attempted to answer the question, “What concise pieces of advice can I give to designers that will have the greatest impact on accessibility in the majority of cases?”

Again, this list is not the perfect solution, nor is it the only solution, but I believe it is a good first step, and it gives our developers and designers a place to start from.

It is my hope that most of the below points should be easily understood, but on our internal WIKI, we will also be providing links from most checkpoints to supporting documentation that gives more details. For everyone else, I recommend WebAIM or failing that, Google.

A printable version is available here.

Accessibility Checklist

Markup

Visual Appearance and Content

Dynamic Content

Images and Multimedia

Forms

Testing

posted by cannona on Friday, Jun 06, 2008

The wbr tag saved my bacon today when a long email address was breaking a narrow column layout. This looks like another HTML tag I hadn’t ever used, but probably should have. I looked all around for a non-java-script CSS solution, but this little non-validating tag was the best I could do. See the linked Quirksmode article for a nice discussion of the “incompatibility soup” of solutions to this problem.

posted by ted on Wednesday, May 14, 2008

And a companion SEOmoz link: 5 HTML elements you probably never use, but perhaps should . (Note that with both of these the author and commenters do not suggest indiscriminate adoption; test it, test it, test it. But some cool stuff to explore nonetheless. Do check the comments by the way—lots of additional goodies, tips, and warnings there.)

posted by ted on Thursday, Apr 24, 2008

Why once wrote about the travesty of the textarea. Let us revisit this, and reflect that in 4 years things have not improved much.

Textarea You Are A Sunken Nothing

posted by pete on Tuesday, Apr 01, 2008

For you CSS junkies, you may find this article very handy.

posted by foster on Tuesday, Jul 17, 2007

A tip from Gilbert: when designing forms with horizontal labels in a liquid layout, prevent your required *’s from wrapping by placing a &nbsp; (instead of a normal space) between the word and star, like this:

posted by jason on Wednesday, Jan 17, 2007

Bulletproof HTML: 37 Steps to Perfect Markup
This is a great article for not only seasoned veterans to refresh and remember why we code the way we do, but for novices as well, just a great resource on the very fundamentals of HTML

posted by rob on Sunday, Oct 29, 2006