Advanced CSS Styling and the CannyBill redesign project

It’s not everyday that I get to work with a client that completely gets why it’s important to push the progressive enrichment boundaries by using HTML5 and the kind of advanced CSS styling that I teach at my workshops. Luckily, the CannyBill team do more than get it. I’d like to share a little of the HTML5 and CSS that I’m using for this project.

HTML5

Over the last few months, as I've learned more about HTML5, I've wondered about the advantages that I might gain by using it. Recently I realised that the question shouldn't be why use HTML5 but why not? From what I've learned from reading and by talking to people, the only reason that I can find not to use it is that without JavaScript, HTML5's added elements (section, article, aside, figure etc.) cannot be styled in Internet Explorer.

While this stays a minor concern, I'll accept this irritation because content remains fully accessible without JavaScript. Major plusses for using HTML5 on the CannyBill project and others I have in the works are the new elements and particularly the way that it allows me to wrap an anchor around multiple block-level elements, for example in the list of applications for CannyBill.

<a href="#">
<h3><img src="avatar-malarkey.jpg" alt="" class="photo" />
<span class="fn">Andy Clarke</span> sells his tutorial subscriptions</h3>
<p>Designer and author Andy Clarke uses CannyBill to sell subscriptions 
to his online tutorial master classes.</p>
</a>

Although I still prefer to write markup using an XHTML syntax, closing elements using a trailing slash, HTML5 is refreshing simple to write.

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>CannyBill</title>
<meta charset=utf-8 />
</head>
<body>
</body>
</html>

I have used HTML5's new elements extensively during the redesign where I feel that they add more focussed semantics.

<header> for both the branding header of a whole page and also as a header for each article in the blog/discussions pages, <nav> to denote navigation (usually wrapped around both a descriptive heading and an accompanying list of links, <section> to separate different topics (but not as a generic container for content (that is still the job of a division)) and <figure> with it's dt and dd semantics for captioning images and video.

To work around these issues with the new elements, I am relying on Modernizr to create these new elements in the DOM for Internet Explorer plus some simple CSS to enable their styling.

article, aside, dialog, 
figure, footer, header, hgroup, 
nav, section {
display : block; }

Advanced CSS Styling

Before you read on, open the latest iteration of the CannyBill home page in either Safari 4 or Firefox 3.6 Alpha. Sorry Internet Explorer, Opera or Firefox 3.5 users, look at the screenshot on Flickr instead.

I'm making heavy use of Modernizr's ability to establish whether or not an HTML5 or CSS feature is implemented in a browser and its adding an appropriate class attribute to the HTML element. For example, if a browser has implemented border-radius Modernizr will add borderradius. If not, it will add no-borderradius. This simple technique makes designing alternatives depending on a browser's capabilities easier by using descendent CSS selectors.

.borderradius a.action {
border-radius : 10px;
-moz-border-radius : 10px; 
-webkit-border-radius : 10px; }

.no-borderradius a.action {
/* Alternative styles */ }

After-all, it's important to remember that websites don't need to be experienced exactly the same in every browser.

For CannyBill I am using Modernizr to check for border-radius, CSS transforms, CSS transitions, multiple background images, RGBA and opacity (and I dare say a few more by the time I'm finished.)

If you've already looked at the latest home page iteration, you might have spotted my using RGBA on both the top (language) bar and the main navigation list.

.rgba .tools {
background-color : rgba(0,0,0,.3); 
color : rgba(255,255,255,.9); 
text-shadow : rgba(0,0,0,.8) 0 1px 1px; }

.no-rgba .tools {
background-color : rgb(0,0,0); 
color : rgb(255,255,255); 
text-shadow : rgb(0,0,0) 0 1px 1px; }

A little more subtle is the effect that it creates for text and box shadows. You'll also probably have spotted border-radius on the main navigation and the orange call-to-action buttons. But I am using three more advanced CSS techniques on this page: CSS gradient backgrounds, CSS transforms and transitions. First let's take a look at CSS gradient backgrounds on the call-to-action buttons. Here is the HTML5 markup.

<a href="#" class="action secure">
<h4>See plans and prices</h4>
<p>Manage five active clients free</p>
</a>

And now the CSS, first for Webkit-based browsers and then for Mozilla. The gradient colours are added to the CSS background-image property.

.action { 
background-color : rgb(218,109,14);
background-repeat :  no-repeat;

background-image : -webkit-gradient(linear, /* Gradient type */
left top, left bottom, /* Gradient direction */
from(rgb(255,153,0)), /* Starting colour */
to(rgb(190,75,26))); /* End colour */

background-image : -moz-linear-gradient /* Gradient type */
(left top, left bottom, /* Gradient direction */
from(rgb(255,153,0)), /* Starting colour */
to(rgb(190,75,26))); /* End colour */ }

Although the syntax is, at first glance, a little complicated, you should soon get used to it. A great place to start experimenting is Westciv's linear gradient demonstration, but be sure to adjust the syntax for Mozilla as it differs a little from Webkit's implementation as the syntax has not yet been agreed between them.

CSS transforms

To add emphasis to the video screen-captures, I've used CSS transforms and transitions (plus a little generated content). Here is the HTML5.

<figure class="video-tour">
<a href="#">
<dd><img src="video-small-1.png" alt="" /></dd>
<dt>Create, send and manage invoices</dt>
</a>
</figure>

The CSS, first for Webkit-based browsers and then for Mozilla is simple with the scale property, followed by a scaling factor in parenthesis.

.csstransforms figure.video-tour:hover img {
-webkit-transform : scale(1.15);
-moz-transform : scale(1.15); }

To smooth the transition to the scaled images, I used CSS transitions.

.csstransforms figure.video-tour:hover img {
-webkit-transition : all .2s linear;
-moz-transition : all .2s linear; }

Then a little CSS generated content to add a play icon over the scaled images which is positioned absolutely.

figure.video-tour:hover dt:after {
content : url(figure-open.png); 
position : absolute; 
top : 35%; 
right : 40%; }

Here are the results in the finished home page. (You will need to look at the page in the browsers I mentioned to see the effect of transforms, transitions and generated content.


CannyBill home page in Safari 4
(with full support)

And here in Firefox 3.6a.


CannyBill home page in Firefox 3.6a

And finally the latest iteration of the CannyBill home page in HTML5 and CSS.

If you'd like, look at how the page renders in an older version of Firefox or Opera 10, the latest and greatest from that browser. As I've written about before, I can easily live with the natural differences between browsers as I've accepted that there will probably never be a time when all browsers implement the same CSS at the same time.

To expect this is a utopian fantasy as CSS3 was designed so that browser makers can choose which CSS modules to implement and when.

If right now you're asking yourself what your clients might think of this approach, remind yourself (and them) that only web geeks use more than one browser and will never see the differences between even these modern browsers.

Designing for Mobile with CSS3 with Dan Rubin

Join world-renowned mobile designer and author Dan Rubin for a full day learning the key steps to transform your site for mobile users, from content strategy to CSS3 to device detection and optimisation.

Book your place only £325.00

Excludes VAT.

Photo credit: © John Morrison / Subism Studios

There have been 26 replies

  1. 1

    Dave McNally

    Very nice job on the design!

    This is just the push I needed to get started on HTML5 too and leave behind the XHTML. Some nice tips in there too I didn’t know about.

    21st Oct 2009
  2. 2

    Philip Renich

    I’m curious, in your .rgba and .no-rgba, did you do a third fall back for opacity and IE opacity? I know we needn’t make it the same in all browsers, but using the standard opacity seems fair.

    I haven’t studied the differences between using something like background-color with opacity and just rgba()

    Thanks for being so open with your process and sharing your code!

    21st Oct 2009
  3. 3

    Philip Renich

    (Stupid, I didn’t realize my URL that I inserted was to a specific status. My bad)

    21st Oct 2009
  4. 4

    Ryan Brunsvold

    Really clean and clever, Andy. In running this page through the usual browser gauntlet, I did not notice any glaring differences. Sure… a few missing/altered borders here and there and poor opacity support (from Internet Exploder) but nothing that impedes on the integrity of the design, layout, or behaviour.

    And here I thought the main derivative of following this design project was to learn about your design methodology. Consider me properly HTML5’d and CSS3’d.

    21st Oct 2009
  5. 5

    mau

    Only web geeks use more than one browser.

    So. darn. true.

    (This comment was left on For A Beautiful Web)

    21st Oct 2009
  6. 6

    John Holdun

    Why percentages for the position of the play icons? Or rather, why percentages from top left, instead of using negative margins from 50% to center them? As it is they are ever so slightly askew and while I’d probably never have noticed otherwise…I now cannot see anything else.

    21st Oct 2009
  7. 7

    Alberto Calvo

    Hey, Andy.
    Good article here. I’ve one question, though. What’s the point of using one JavaScript plus presentational class names when you can achieve the same chaining, in example, the rgb property first and the rgba later? I mean, the browser that doesn’t support rgba simply ignore that rule and uses the first one instead. I’m currently developing my website with a very similar approach and this is working pretty fine on every browser.

    Well, in fact I’m using hexadecimal for creating a lo-fi version of the site and hsla (as I prefer this to rgba for obvious reasons)  for advanced browsers:

    .something {
    background-color: #xxx; /*for ancient browsers*/
    background-color: hsla(0, 0%, 0%, .9); /*for real ones*/
    }

    Isn’t it far simpler?

    21st Oct 2009
  8. 8

    Brajeshwar

    May be I’ve not got my head clear on the “figure” but are ‘dd’ and ‘dt’ allowed without a ‘dl’ inside of a “figure”? Also, is it normal for the ‘term’ (dt) to come after the ‘definition’ (dd)?

    (This comment was left on For A Beautiful Web)

    21st Oct 2009
  9. 9

    Oli

    Sweet looking site, and I completely agree with HTML5—why not indeed?

    <dialog> has been dropped; here’s the current spec recommendations.

    I echo @Alberto Calvo—why not use the CSS cascade for rgba etc?

    @Brajeshwar actually <figure> does currently use <dt> and <dd>, although there are some browser issues with it so this might change.

    I’ve been using block-level links a lot recently, but seem to be getting bitten by the Firefox vomit bug. It only occurs occasionally, but enough to be frustrating.

    Finally, you might want to move your charset declaration above your maker’s mark comment—it has to be in the first 512 bytes (np at the moment, but could be at the rate you are accumulating URLs ;-)

    21st Oct 2009
  10. 10

    Jan Sládek

    Great article, thanks!

    But why do you use Cufón when there’s @font-face or at least typeface.js with which you can select the text in (as I believe) every browser and it works pretty much the same as Cufón? With Cufón I can’t select the text in my Firefox 3.5.4. :(

    (This comment was left on For A Beautiful Web)

    21st Oct 2009
  11. 11

    John Faulds

    only web geeks use more than one browser and will never see the differences between even these modern browsers

    I’ve been working on a site lately where the site owner just doesn’t want to accept this to be a statement of fact.

    21st Oct 2009
  12. 12

    Régis Kuckaertz

    w00t! Now dancing, the way you choose :-) These HTML snippets are to writing semantic markup what programming pearls was to design beautiful programs, thank you very much!

    Modernizr seems to be nifty little script, would you recommend using it over the native error handling of CSS rules? i.e.

    .rgba elem { }
    .no-rgba elem { }

    over

    elem { background:rgb(0,0,0); background:rgba(0,0,0,.33); }
    
    And in which situation would you not recommend using it?

    (This comment was left on For A Beautiful Web)

    21st Oct 2009
  13. 13

    Tom

    Some lovely use of transitions and transforms in there.

    21st Oct 2009
  14. 14

    Andy Clarke

    @Jan Sládek: Why do you use Cufón when there’s @font-face or at least typeface.js?

    — These days I always use Cufon while I’m designing in a browser. I do expect that if we (me and the CannyBill team) will move to @font-face at some point before the site goes live. We will likely use either Typekit or Typoteque depending on the typeface we choose.

    @Oli: Finally, you might want to move your charset declaration above your maker’s mark comment—it has to be in the first 512 bytes.

    — Damn. I never realised that, what a great tip. Though when you mentioned Makers Mark, I thought you were referring to my favourite whisky!

    @Brajeshwar: May be I’ve not got my head clear on the figure but are dd and dt allowed without a dl inside of a figure? Also, is it normal for the term (dt) to come after the definition (dd)?

    — dt and dd are currently part of the figure semantics, although that might change. I have read anything that says that dt must come before dd.

    @Alberto Calvo: What’s the point of using one JavaScript plus presentational class names when you can achieve the same chaining, in example, the rgb property first and the rgba later? I mean, the browser that doesn’t support rgba simply ignore that rule and uses the first one instead.

    — Modernizr and the way that it uses class names for descendent selectors is more than just about replacing a modern (rgba/hsl) value with a different one (hex), it’s about allowing you to use descendent selectors to design full alternatives for different browser capabilities. For example, no-rgba? Use Modernizr to apply a different background image. Or no CSS columns? Use Modernizr to switch the layout to fixed instead of liquid. It’s an amazingly powerful tool.

    @John Holdun: Why percentages for the position of the play icons? Or rather, why percentages from top left, instead of using negative margins from 50% to center them?

    — Ah, good catch. That’s a hang over from before, when I hadn’t decided how large the images would be. Now I know, I can switch to pixels.

    @Philip Renich: I’m curious, in your .rgba and .no-rgba, did you do a third fall back for opacity and IE opacity?

    — I could easily add a -ms- filter into an IE8 only style sheet, but I won’t. The longer we encourage browser makers to sit on the laurels while we hack around their software’s problems (or lack of CSS spec support), the longer it will take for them to improve. Web designers should not hack around software issues, it’s not our job.

    21st Oct 2009
  15. 15

    Tobias

    Everytime I read these it makes me want to quit trying to be a good web designer, your work is *so* out of my league it isn’t even funny.

    21st Oct 2009
  16. 16

    Richard

    Not really a design issue but in my opinion the branding tagline would sound and look better like this:

    Every day, more than 200,000 businesses like yours use CannyBill to increase their revenues.

    Or

    More than 200,000 businesses like yours use CannyBill to increase their revenues….every day.

    The use of commas and that many different numbers within the three first elements of the sentence makes it more difficult to read.

    21st Oct 2009
  17. 17

    RellyAB

    Richard - that tagline is just placeholder, although what you say is very true.

    21st Oct 2009
  18. 18

    Richard Clark

    Hey Andy,

    So you’ve got HTML5, CSS3 and microformats. Any plans for any WAI-ARIA to be added?

    Rich

    21st Oct 2009
  19. 19

    Elliott

    ok, this is all really cool.  But I have to voice a criticism.  And let me preface this by saying I work on a site where near 75% of our audience is IE 6-8 (aren’t you all SOOOO jealous)....

    First, let me say that I get it.  HTML5, CSS3, progressive enhancements/enrichments are valid, and were it not for people like you championing such issues, we’d all still be building tabled websites.  That being said, I think there are some dangers to implement bleeding-edge solutions in production environments.

    I agree that websites-dont-need-to-look-or-behave-exactly-the-same-in-every-environment.  But in certain scenarios, it kinda should.

    Case-in-point: The ‘See plans and prices’ call to action on this CannyBill mockup.  In Safari, I see a well-designed button. In Firefox, I lose the gradient, but I still have rounded corners and text-shadows (still looks like a button).  In IE, rounded corners and text-shadows are gone - and here’s my point - it’s starting to NOT look like something I should click on.

    Believe me, I’m sick of all things IE, but I imagine that audience is important to CannyBill, and they probably want to convert them as best they can.  It would have been not-much-more time consuming to implement a sliding-doors solution — or a graphic (gasp!) — to ensure the button looks consistent across browsers.

    I just don’t see the point — at least, not yet — in spending extra time developing for the user experience of the vast minority of a site’s audience, when that time could be spent developing a better lowest-common-denominator solution.  Most of this stuff just isn’t ready for prime-time yet.

    21st Oct 2009
  20. 20

    Andy Clarke

    @Richard Clark: So you’ve got HTML5, CSS3 and microformats. Any plans for any WAI-ARIA to be added?

    — Psst. Rich, can you keep a secret? I know nothing about ARIA, nothing. I couldn’t even tell you what the acronym means. That makes me a bad person. Right? (Seriously I need to do more reading).

    @Elliott: I just don’t see the point — at least, not yet — in spending extra time developing for the user experience of the vast minority of a site’s audience, when that time could be spent developing a better lowest-common-denominator solution.  Most of this stuff just isn’t ready for prime-time yet.

    — I could write a book answering that question. No wait, I did. And I’m about to write another one. Hot damn. Anyway, look out for a proper answer in an article for 24ways in December. Enough to say that I disagree with you completely, but then that’s OK too.

    21st Oct 2009
  21. 21

    DavidCOG

    Off-topic: For A Beautiful Web is a very nice design, but it’s horrible to read any more than a couple of sentences. An alternative CSS would be a great thing - black on white, nice and clear.

    — Ed says: Thanks David. Look out for a new version of For A Beautiful Web in the next few weeks (to celebrate the release of our new DVDs. In the meantime, you can read these articles over on our other site, Stuff and Nonsense, in sharp black and white.

    (This comment was left on For A Beautiful Web)

    21st Oct 2009
  22. 22

    Rich Clark

    Sure can Andy, but in the meantime, check out these links re ARIA.

    Using ARIA Landmark roles

    HTML5 Spec that shows which elements map to ARIA roles.

    Hope it helps.

    22nd Oct 2009
  23. 23

    DavidCOG

    Thanks, Ed (or is that ‘Editor’?! - and you’re Andy?! :)). Look forward to seeing the new design.

    22nd Oct 2009
  24. 24

    Peter

    I don’t understand one part. Why are you relying on Modernizr for visuals? I mean, why not write:

    a.action { /* default styles */ }
    . borderradius a.action { /* overwriting default styles */ }

    This way users without JavaScript will get at least some CSS, basic CSS.

    If that’s the case (and I’m not reading it the wrong way), this is awful way to treat users. I don’t really have to explain why JS is opt-in for modern websites. :P

    (This comment was left on For A Beautiful Web)

    24th Oct 2009
  25. 25

    DAZ

    Andy, this looks amazing. Good on you for deciding to use CSS3 and HTML5 out there in the wild. I definitely think this should start happening more and more, and agree that users don’t need the same browsing experience. This stuff is ready to use now, like you said, but I also think that you should try and please as many users as possible.

    By using Modernizr, aren’t you also relying on the browser having JavaScript enabled, adding an extra layer of requirements for users?

    I like a lot of things about HTML5. The easy doctype and the new tags that provides a richer browsing experience such as video, audio and drag and drop, but header,section and footer are just playing with semantics - really, what is the difference between a section and a division? I would prefer to use div class=“header” and allow IE without JavaScript to have the styles. I just don’t see what you gain by using the header and section tags.

    Its also great to use some of the nice CSS3 features, but it seems a little bit too much at the expense of a large number of users in some places. The point Elliot made about the button is a good one - all it would need would be an image or two to make it look the same, hardly loads of work.

    And what’s with the fixed width? I don’t get everything in my browser window at its default setting!

    Looking forward to your next book and your 24-Ways article.

    DAZ
    ps - on this site the captcha doesn’t appear on the right of the instructions, it obscures the instructions!

    (This comment was left on For A Beautiful Web)

    26th Oct 2009
  26. 26

    DAZ

    Sorry to post again, but I’m just not getting Modernizr. Why not use default styles, followed by styles for modern browsers (that older browsers will just ignore). Then add any styles for older browsers that have JavaScript installed. For example, for a transparent background:

    .header{
    background:#cc0000; /* old browser styles */
    bacground:rgba(256,0,0,0.8); /* modern broswer styles */
    }
    .no-rgba .header{
    background:#fff url(transparent-red-bg.png) 0 0 repeat;
    }/* fix for old browser styles that have JS */

    What I’m saying is, why do you ever need to use the .rgba class?

    And since most of the time the browser that doesn’t support the CSS3 property is one that begins with I and finishes with E, you could probably get away with using conditional comments rather than JavaScript to target it.

    Another nice bonus is that support normally goes hand in hand, so you could declare text-shadow with an rgba colour, knowing that usually most browsers will support both of these properties or none at all, so need to test for support with Modernizr.

    (This comment was left on For A Beautiful Web)

    26th Oct 2009
Commenting is not available in this weblog entry.

Tweet a reply using the hash tag #sn_1206

There are currently no tweet replies. Add one?

From the archives

An archive of blog entries since 2004 on subjects including CSS, web standards, accessibility, website design and development.