Tuesday, August 11FreeJQuery

Microsite Concept with Rotating Background

Microsite Rotating Background

An animated microsite concept with rotating background made with CSS3, jQuery and GSAP’s TweenMax. A microsite is an individual web page or small cluster of web pages that act as a separate entity for a brand. A microsite typically lives on its own domain, but some exist as a subdomain. Companies have different reasons for investing in microsites. For example, some companies have used them to highlight a specific campaign or target specific buyer personas. Others have used them to tell a short story or to inspire a specific call-to-action.

Interested in mastering CSS3 like a pro? CSS Master, by Tiffany Brown, is available for download to all SitePoint Premium members. Alternatively, you can grab your copy of the book for just $19.

Scaling, skewing and rotating any element is possible with the CSS3 transformproperty. It’s supported in all modern browsers without vendor prefixes. (I’ve added in the -webkit- just in case you want to support some older browsers.)

#myelement {
-webkit-transform: rotate(30deg);
transform: rotate(30deg);

Great stuff. However, this rotates the whole element — its content, border and background image. What if you only want to rotate the background image? Or what if you want the background to remain fixed while the element is rotated?

Currently, there’s no W3C proposal for background-image transformations. It would be incredibly useful, so I suspect one will appear eventually, but that doesn’t help developers who want to use similar effects today.

Fortunately, there is a solution. In essence, it’s a hack which applies the background image to a before or after pseudo element rather than the parent container. The pseudo element can then be transformed independently.

Transforming Microsite Rotating Background

The container element can have any styles applied, but it must be set to position: relative, since our pseudo element will be positioned within it. You should also set overflow: hidden unless you’re happy for the background to spill out beyond the container.

#myelement {
position: relative;
overflow: hidden;

We can now create an absolutely-positioned pseudo element with a transformed background.

Leave a Reply

Your email address will not be published. Required fields are marked *