Tikier Hosting Offshore, Adult, Warez Linking Hosting Allowed

18May/100

Better Page Corner Ads with CSS3 Transforms

The other day I came across a useful site called ScriptSrc.net that allows you to get up-to-date script tag links that point to your favourite JavaScript libraries.

The site has a clickable corner ad promo to get people to “spread the word”. I thought using CSS3 there would be a better way to position such a corner advertisement (or promo, or whatever), because the clickable area for the ad on ScriptSrc.net is actually too big. In some cases, you might prefer the clickable area to be bigger, but I think it’s always best to keep the clickable area limited to the actual ad.

The Clickable Area is too Big

On the ScriptSrc.net website, the clickable area on the corner promo is naturally a square, because all page elements in HTML are square or rectangular. This is indicated in the image below:

The  clickable area of the corner ad is square

Maybe they don’t care that this is the case, or maybe they prefer it that way, so it gets more clicks. I personaly feel it’s more usable if the actual corner section is the only clickable area.

CSS3 Transforms to the Rescue

If you’ve become familiar with some new CSS3 enhancements, you probably know that elements can be rotated. We can use this to make the corner promo more usable. Here is the CSS:

#corner-ad {
display: block;
width: 200px;
height: 200px;
position: absolute;
top: -100px;
rightright: -100px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
}

(NOTE: The syntax highlighter I’m using displays the CSS property “right” as “rightright”, so just ignore that in the code above and below).

Now the only clickable area is the actual corner, so there is no risk that a stray click near the corner triggers the corner promo.

Works in All Browsers (with Hacks for IE)

The great thing about this is that, although the method uses a CSS3 enhancement, Internet Explorer offers rotation capabilities by means of proprietary filters. In the case of my own demo page, I also had to add some IE-version-specific hacks to get the positioning of the ad correct, so there is some extra unwanted code that’s needed to get this to work properly. The following code placed below the original CSS gets it to work in all versions of IE:

#corner-ad {
top: -142px9;
right: -60px9;
*right: -140px;
filter:  progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476);
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";
zoom: 1;
}

The “transform” code is from Paul Irish’s CSS3, please CSS3 generator, which has recently added support for IE’s matrix rotation filter. The “zoom” property isn’t needed in my example, but it is needed in cases where the element doesn’t have layout.

Check out the demo using the button below.

DEMO

Related posts:

  1. CSS Tutorial – Generated Content
  2. 3 Key Off-Page Search Engine Optimization Methods
Print This Post Print This Post
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.