SHARE
Facebook X Pinterest WhatsApp

Web Developer Class: How to Use CSS3 Transforms with vCards

Written By
thumbnail
Michael Rohde
Michael Rohde
Feb 3, 2011

Using CSS3 transforms to style the hCard microformat provides a powerful means to design your web pages while at the same time providing contact information that, according to Microformats Wiki, “enables applications to retrieve information directly from web pages without having to reference a separate file.”


Transforms are made up of four different properties:


  • translate
  • skew
  • rotate
  • scale

The majority of modern browsers all currently support transforms, including Firefox, Google Chrome, Opera, and Safari. Each browser has their own specific prefix. For example:


.vcard {
  -webkit-transform:;
  -moz-transform:;
  -ms-transform:;
  -o-transform:;
}

For the following examples, I

ll use the -moz- prefix for the sake of keeping the examples short and uncluttered.



The images will all come from your CSS, not from the HTML. This is done without the use of id attributes and instead relies on :nth-of-type.

.vcard:nth-of-type(1) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
}
.vcard:nth-of-type(2) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
 }
.vcard:nth-of-type(3) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
}
.vcard:nth-of-type(4) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
}

For the sake of learning, I used the same image for each type. That way, when I start to transform the images, I can see the differences that I

m creating. In an actual web page, you

ll most likely use different images.



Now we’ll use transform so you can adjust the size of each of the images. Simply add -moz-transform: scale(1.25); to the block of code.

.vcard:nth-of-type(1) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
 -moz-transform: scale(1.25);
}

Adjust the scale to suit your needs. To increase the image size, use any number over 1.0. To decrease the size, use any number below 1.0. For example, 0.90 scales the image down to 90% of it

s original size.



You can use rotate to, you guessed it, rotate the image. You can combine this with transform:

.vcard:nth-of-type(1) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
 -moz-transform: scale(1.25) rotate(90deg);
}

Last, you can use translate to move the image on the vertical and horizontal axis. You could go so far as piling the images on top of each other:


.vcard:nth-of-type(1) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
 -moz-transform: scale(1.25) rotate(45deg) translate(90px, 10px);
 }
.vcard:nth-of-type(2) {
  background-image: url(a.jpg);
  background-repeat: no-repeat;
 -moz-transform: scale(.75) rotate(90deg) translate(90px, 300px);
}

For the HTML side of the equation, you can go to

hCard creator

to help generate the hCard code. You can simply copy and paste the generated code into your HTML and tweak it as needed.



You’ll notice that the hCard text is appearing on your web page alongside your text. You may or may not want that to happen. If you want the text off the page, but still accessible to search engines and applications, you’ll need to add this to your CSS:

 .vcard * {
 text-indent: -9999px;
}

Recommended for you...

Importing Custom Less Styles at Run-time in Angular
Rob Gravelle
Jun 14, 2022
Setting CSS Values from Less Variables in Angular
Rob Gravelle
Jun 4, 2022
Color Manipulation with JavaScript
Rob Gravelle
May 21, 2022
An Introduction to CSS-in-JS
Rob Gravelle
May 14, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.