April 27th, 3:29am 0 comments

Create Date Badge with Wordpress and CSS

This tutorial will walk you through creating date badges with Wordpress and CSS.

Media_httponcemadecom_xgoch

Let's start of by adding the necessary markup to render the appropriate date format. Create a DIV element with a class of "entryDate" and three children SPANs with respective classes "postMoth", "postDay", and "postYear".
Add the PHP code to get the post date from the database as shown bellow. For more PHP date format go to http://us.php.net/date

Markup

Now let's add styles to make it look pretty.

First of all, set the body font-size to 10px or 62.5%. Then go ahead and set the DIV that wraps the post entry to position: relative so the date badge can be positioned relatively to it. Set margin-left to the width of the date badge plus the gap between the post entry. In this sample the margin-left is set to 4.8em.

Absolute position the entryDate and set the left to the same size as the its parent margin-left. After that, set the width to 3.5em. Next, set all the SPANs inside entryDate as block element (The reason why SPANs are being used instead of DIVs is because if the stylesheet is disabled, the date renders nicely in one line). Don't forget to centered align the text.

Change the appearance as needed, I have changed the size of the text to look more like a calendar and I've set its color to blue and white.

CSS

Browser Support

  • Firefox
  • Safari
  • Chrome
  • Opera
  • Internet Explore 7 & 8
  • Internet Explore 6
Posted