Easier Date Display Technique with CSS 3

This small tutorial will try to replicate the famous and recently popular Date Display Technique with Sprites, but opting to do it with CSS 3 instead. The advantage of the CSS 3 method is that:

  • You don’t have to create CSS image sprites.
  • No more sprites limitation. With image sprites the year is limited, the font selection is fixed, the month name is limited to English words only, and so on. With this technique everything can be shown.
  • The CSS is much shorter and understandable.

This only works with modern browsers that support CSS3, of course.

Look Ma, No Images!

The HTML structure for the date:

<div class="date">
  <span class="day">30</span>
  <span class="month">Jun</span>
  <span class="year">2009</span>
</div>

Next, the CSS for it can be like this.

.date {
  position: relative;
  width: 70px;
  font-family: Georgia, serif;
  color: #999;
  margin: 0 auto;
 }
 
.day, .month, .year {
  position: absolute;
  }
 
.day { 
  font-size: 30px;
  top: 15px;
  }
 
.month { 
  top: 0;
  left: 0;  
  font-size: 18px;
  }
 
.year { 
  top: 19px;
  right: 0;
  font-size: 20px;
  rotation: -90deg !important;
  /* ** Hacks ** */
  -webkit-transform: rotate(-90deg);
  -moz-transform: rotate(-90deg);  
  }

And after that (here’s the hardest part so I hope you pay more attention now)…

…nah, just kidding. We’re done. Here’s an actual result:

30
Jun
2009

Advanced Tweakeries

Depending on your own design, you might want to:

  • tweak the width of the .date div (more width, more distance between the year and the day/month pair)
  • change the font-sizes (in which case you will likely need to tweak the .date’s width and the other span’s top property).
  • Use your own font either with sIFR, Cufon, or the more modern @font-face method. Custom font is probably the sprites technique’s only advantage over this CSS 3 method, but no more with this last tweak.

2 Responses to “Easier Date Display Technique with CSS 3”

  1. Ludwig Bernstein

    I like how simple it is compared to the original one. Here’s hoping for more widespread support for CSS3 soon.

  2. Ricardo

    so basically we only need to use rotate, right? handy

Leave a Reply

Latest Links More →

Custom Shortlinks for WordPress

Have your own short domain name for the purpose of shortlinking? Here’s an easy way to combine that with your WordPress install.

The Quick Start Guide to Using Google Webmaster Tools With WordPress

GWT is a great, frequently updated features like showing you search queries volume, malware and crawl error diagnostics and links to your site. If you don’t use it yet, you probably need to. This will help you get started.

WordPress & jQuery Contact Form without a Plugin

I would recommend this either if you want more flexibility or to learn how to code a contact form.

Understanding and cleaning the pharma (spam) hack on WordPress

How to fix that hack:

This attack is very interesting because it is not visible to the normal user and the spam (generally about Viagra, Nexium, Cialis, etc) only shows up if the user agent is from Google’s crawler (googlebot). Also, the infection is a bit tricky to remove and if not done properly will keep reappearing.

Web Safe Fonts Cheat Sheet

An updated (written in April 2010), well researched, CC-licensed Web safe fonts cheat sheet, available both in low-res PNG and high-rest PDF. Even the article is useful as well.

The Nicest 2010 Child Theme You’ll See Today

The Timaru Mental Health Support Trust website, made for charity by Team USA (comprised by web superstars like Jason Santa Maria, Dan Mall, Liz Danzico and Automattic’s John Ford) during the FullCodePress competition, is actually a clever child theme of 2010.

More recap by JSM, Daniel Mall, and Liz Danzico.

WordPress 3.0 Theme Tip: The Comment Form

The simpler way to code comment form (once you understand how hooks and filters work).

Showing and hiding content with pure CSS3

I like it, I think it’s short and easy to understand.