
It is almost impossible to gather in an article all the CSS tricks that could help you in the future but here are some of the ones that you would need more often than others.

Don’t get scared by the length of some of these CSS hacks’s code cause they’re all easy to implement and where is the case, they’re well documented.

Besides the ones that solve common and annoying problems there are also some that solve new issues brought by the new technologies.

By the way, if you like this article, you should know that I have another one about CSS text effects and one with HTML & CSS headers that you might like.

Vertical Align Anything

If you stumbled upon this issue before, you know how annoying it is. Luckily, you can now use CSS3 Transform to solve the problem.

.vc{ position: relative; top: 50%; -webkit-transform: translateY(-50%); -o-transform: translateY(-50%); transform: translateY(-50%); }

Box Shadow Only on One or Two Sides

.box-shadow { background-color: #AC92EC; width: 160px; height: 90px; margin-top: -45px; margin-left: -80px; position: absolute; top: 50%; left: 50%; } .box-shadow:after { content: &amp;amp;quot;&amp;amp;quot;; width: 150px; height: 1px; margin-top: 88px; margin-left: -75px; display: block; position: absolute; left: 50%; z-index: -1; -webkit-box-shadow: 0px 0px 8px 2px #000000; -moz-box-shadow: 0px 0px 8px 2px #000000; box-shadow: 0px 0px 8px 2px #000000; }

Animating A Gradient Background

CSS Animations have started to become a cool thing since CSS3, but they only look good if they aren’t overdone. This neat trick moves the background position to look like it is animating.

button { background-image: linear-gradient(#FC6E51, #E9573F); background-size: auto 200%; background-position: 0 100%; transition: background-position 0.5s; } button:hover { background-position: 0 0; }

Split the text into columns

-webkit-column-count: 2; -moz-column-count: 2; column-count: 2;

Table auto-width

I got annoyed by this more than I should have been when I worked on a project.

td { white-space: nowrap; }

First article larger, like in print publications

p:first-child::first-letter{ font-family: &amp;amp;quot;papyrus&amp;amp;quot;; font-size: 28px; font-weight: bold; }

Demo:

See the Pen bdGPWd by Preethi (@rpsthecoder) on CodePen.

Comprehensive List of Browser-Specific CSS Hacks

Cross browser coding can be sometimes tricky but these browser specific css hacks can help you with your problems. With them cross browser compatibility comes to you served on a plate.

/***** Selector Hacks ******/ /* IE6 and below */ * html #uno { color: red } /* IE7 */ *:first-child+html #dos { color: red } /* IE7, FF, Saf, Opera */ html&amp;amp;gt;body #tres { color: red } /* IE8, FF, Saf, Opera (Everything but IE 6,7) */ html&amp;amp;gt;/**/body #cuatro { color: red } /* Opera 9.27 and below, safari 2 */ html:first-child #cinco { color: red } /* Safari 2-3 */ html[xmlns*=&amp;amp;quot;&amp;amp;quot;] body:last-child #seis { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:nth-of-type(1) #siete { color: red } /* safari 3+, chrome 1+, opera9+, ff 3.5+ */ body:first-of-type #ocho { color: red } /* saf3+, chrome1+ */ @media screen and (-webkit-min-device-pixel-ratio:0) { #diez { color: red } } /* iPhone / mobile webkit */ @media screen and (max-device-width: 480px) { #veintiseis { color: red } } /* Safari 2 - 3.1 */ html[xmlns*=&amp;amp;quot;&amp;amp;quot;]:root #trece { color: red } /* Safari 2 - 3.1, Opera 9.25 */ *|html[xmlns*=&amp;amp;quot;&amp;amp;quot;] #catorce { color: red } /* Everything but IE6-8 */ :root *&amp;amp;gt; #quince { color: red } /* IE7 */ *+html #dieciocho { color: red } /* Firefox only. 1+ */ #veinticuatro, x:-moz-any-link { color: red } /* Firefox 3.0+ */ #veinticinco, x:-moz-any-link, x:default { color: red } /***** Attribute Hacks ******/ /* IE6 */ #once { _color: blue } /* IE6, IE7 */ #doce { *color: blue; /* or #color: blue */ } /* Everything but IE6 */ #diecisiete { color/**/: blue } /* IE6, IE7, IE8 */ #diecinueve { color: blue\9; } /* IE7, IE8 */ #veinte { color/*\**/: blue\9; } /* IE6, IE7 -- acts as an !important */ #veintesiete { color: blue !ie; } /* string after ! can be anything */

(source)

Create a blurry text

.blurry-text { color: transparent; text-shadow: 0 0 5px rgba(0,0,0,0.5); }

Cross Browser Vertically and Horizontally Centered Images in CSS without Tables

This centers an image of unknown size vertically and horizontally within a box. The wrapper box has an explicit width and height. The is a hack for internet explorer

&amp;amp;lt;figure class='logo'&amp;amp;gt; &amp;amp;lt;span&amp;amp;gt;&amp;amp;lt;/span&amp;amp;gt; &amp;amp;lt;img class='photo'/&amp;amp;gt; &amp;amp;lt;/figure&amp;amp;gt;

.logo { display: block; text-align: center; display: block; text-align: center; vertical-align: middle; border: 4px solid #dddddd; padding: 4px; height: 74px; width: 74px; } .logo * { display: inline-block; height: 100%; vertical-align: middle; } .logo .photo { height: auto; width: auto; max-width: 100%; max-height: 100%; }

Highlight checked input

input:checked + label{ background: yellow; }

Demo:

See the Pen BNaEOm by Preethi (@rpsthecoder) on CodePen.

Cross-Browser Transparency via CSS

You can quickly and easily apply transparency to any supportive element by adding the following CSS code your stylesheet:

selector { filter: alpha(opacity=50); /* internet explorer */ -khtml-opacity: 0.5; /* khtml, old safari */ -moz-opacity: 0.5; /* mozilla, netscape */ opacity: 0.5; /* fx, safari, opera */ }

(source)

CSS Box Shadow

Overdoing it may result in looking weird but using it with style can add a certain classy look to your divs without using any images to do so. The box shadow property is one of the new things that CSS 3 brings us and one of the most wanted.

Outer shadow

.shadow { -moz-box-shadow: 5px 5px 5px #ccc; -webkit-box-shadow: 5px 5px 5px #ccc; box-shadow: 5px 5px 5px #ccc; }

Inner shadow


.shadow { -moz-box-shadow:inset 0 0 10px #000000; -webkit-box-shadow:inset 0 0 10px #000000; box-shadow:inset 0 0 10px #000000; }

You can see a demo at Design Resource Box

Cross-Browser Min Height

The CSS min-height is one of the most requested css snippets to solve the annoying min-height problems in IE.

#div { min-height: 500px; height:auto !important; height: 500px; }

3 Ways to Preload Images with CSS, JavaScript, or Ajax

Reloading images is a great way to improve the user experience. When images are preloaded in the browser, the visitor can surf around your site and enjoy extremely faster loading times. This is especially beneficial for photo galleries and other image-heavy sites where you want to deliver the goods as quickly and seamlessly as possible. Preloading images definitely helps users without broadband enjoy a better experience when viewing your content. In this article, we’ll explore three different preloading techniques to enhance the performance and usability of your site.

CSS Fixed Footer

Making your footer sticky with CSS is a must do. You don’t want it to come after the header on small content pages like a kid comes after candy. It is simply wrong.

#footer { position:fixed; left:0px; bottom:0px; height:30px; width:100%; background:#999; } /* IE 6 */ * html #footer { position:absolute; top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px'); }

(source)

Clearfix CSS Hack

Putting everything together and combining these lessons learned with the original (correct) version of the Easy Clear Method, we fashion the following, fully functional, flaw-fixing CSS clearfix formula:

/* slightly enhanced, universal clearfix hack */ .clearfix:after { visibility: hidden; display: block; font-size: 0; content: &amp;amp;quot; &amp;amp;quot;; clear: both; height: 0; } .clearfix { display: inline-block; } /* start commented backslash hack \*/ * html .clearfix { height: 1%; } .clearfix { display: block; } /* close commented backslash hack */

(source)

8 Definitive Web Font Stacks

The idea behind creating recommended font stacks is simple: since most web designers don’t know a great deal about font selection and typography for the Web, and have far too much on their plates to spend the time needed to learn, they need a one-stop shop of font stacks that provides a wide variety for all platforms—Windows, Mac and Linux.

Additionally, those designers who do understand enough about typography may feel like their creativity is limited by the restrictions of the standard “web safe” set of fonts. Using font stacks is one possible way of increasing a designer’s options.

The font stacks listed here are grouped together by the universal font that forms the base of that stack. A designer can therefore decide on a typographical look for their site, grab the appropriate font stack, and tweak it to suit their needs.

/* The Times New Roman-based serif stack: */ font-family: Cambria, &amp;amp;quot;Hoefler Text&amp;amp;quot;, Utopia, &amp;amp;quot;Liberation Serif&amp;amp;quot;, &amp;amp;quot;Nimbus Roman No9 L Regular&amp;amp;quot;, Times, &amp;amp;quot;Times New Roman&amp;amp;quot;, serif; /* A modern Georgia-based serif stack:*/ font-family: Constantia, &amp;amp;quot;Lucida Bright&amp;amp;quot;, Lucidabright, &amp;amp;quot;Lucida Serif&amp;amp;quot;, Lucida, &amp;amp;quot;DejaVu Serif,&amp;amp;quot; &amp;amp;quot;Bitstream Vera Serif&amp;amp;quot;, &amp;amp;quot;Liberation Serif&amp;amp;quot;, Georgia, serif; /*A more traditional Garamond-based serif stack:*/ font-family: &amp;amp;quot;Palatino Linotype&amp;amp;quot;, Palatino, Palladio, &amp;amp;quot;URW Palladio L&amp;amp;quot;, &amp;amp;quot;Book Antiqua&amp;amp;quot;, Baskerville, &amp;amp;quot;Bookman Old Style&amp;amp;quot;, &amp;amp;quot;Bitstream Charter&amp;amp;quot;, &amp;amp;quot;Nimbus Roman No9 L&amp;amp;quot;, Garamond, &amp;amp;quot;Apple Garamond&amp;amp;quot;, &amp;amp;quot;ITC Garamond Narrow&amp;amp;quot;, &amp;amp;quot;New Century Schoolbook&amp;amp;quot;, &amp;amp;quot;Century Schoolbook&amp;amp;quot;, &amp;amp;quot;Century Schoolbook L&amp;amp;quot;, Georgia, serif; /*The Helvetica/Arial-based sans serif stack:*/ font-family: Frutiger, &amp;amp;quot;Frutiger Linotype&amp;amp;quot;, Univers, Calibri, &amp;amp;quot;Gill Sans&amp;amp;quot;, &amp;amp;quot;Gill Sans MT&amp;amp;quot;, &amp;amp;quot;Myriad Pro&amp;amp;quot;, Myriad, &amp;amp;quot;DejaVu Sans Condensed&amp;amp;quot;, &amp;amp;quot;Liberation Sans&amp;amp;quot;, &amp;amp;quot;Nimbus Sans L&amp;amp;quot;, Tahoma, Geneva, &amp;amp;quot;Helvetica Neue&amp;amp;quot;, Helvetica, Arial, sans-serif; /*The Verdana-based sans serif stack:*/ font-family: Corbel, &amp;amp;quot;Lucida Grande&amp;amp;quot;, &amp;amp;quot;Lucida Sans Unicode&amp;amp;quot;, &amp;amp;quot;Lucida Sans&amp;amp;quot;, &amp;amp;quot;DejaVu Sans&amp;amp;quot;, &amp;amp;quot;Bitstream Vera Sans&amp;amp;quot;, &amp;amp;quot;Liberation Sans&amp;amp;quot;, Verdana, &amp;amp;quot;Verdana Ref&amp;amp;quot;, sans-serif; /*The Trebuchet-based sans serif stack:*/ font-family: &amp;amp;quot;Segoe UI&amp;amp;quot;, Candara, &amp;amp;quot;Bitstream Vera Sans&amp;amp;quot;, &amp;amp;quot;DejaVu Sans&amp;amp;quot;, &amp;amp;quot;Bitstream Vera Sans&amp;amp;quot;, &amp;amp;quot;Trebuchet MS&amp;amp;quot;, Verdana, &amp;amp;quot;Verdana Ref&amp;amp;quot;, sans-serif; /*The heavier “Impact” sans serif stack:*/ font-family: Impact, Haettenschweiler, &amp;amp;quot;Franklin Gothic Bold&amp;amp;quot;, Charcoal, &amp;amp;quot;Helvetica Inserat&amp;amp;quot;, &amp;amp;quot;Bitstream Vera Sans Bold&amp;amp;quot;, &amp;amp;quot;Arial Black&amp;amp;quot;, sans-serif; /*The monospace stack:*/ font-family: Consolas, &amp;amp;quot;Andale Mono WT&amp;amp;quot;, &amp;amp;quot;Andale Mono&amp;amp;quot;, &amp;amp;quot;Lucida Console&amp;amp;quot;, &amp;amp;quot;Lucida Sans Typewriter&amp;amp;quot;, &amp;amp;quot;DejaVu Sans Mono&amp;amp;quot;, &amp;amp;quot;Bitstream Vera Sans Mono&amp;amp;quot;, &amp;amp;quot;Liberation Mono&amp;amp;quot;, &amp;amp;quot;Nimbus Mono L&amp;amp;quot;, Monaco, &amp;amp;quot;Courier New&amp;amp;quot;, Courier, monospace;

(source)

Give Clickable Elements a Pointer Cursor

Some elements that are clickable mysteriously don’t trigger a pointer cursor in browsers. This fixes that, and provides a default class “pointer” for applying it to other clickable things as needed.

a[href], input[type='submit'], input[type='image'], label[for], select, button, .pointer { cursor: pointer; }

(source)

iPad Orientation CSS (Revised)

It doesn’t take much foresight to anticipate that with the rise of Natural User Interfaces (NUIs) like the iPhone and iPad, UI designers will have a greater responsibility to optimize for orientation-based contexts. As such, it’s quite prescient that today, the folks at Cloud Four demonstrated how to serve up stylesheets based on device orientation.

&amp;amp;lt;!-- css --&amp;amp;gt; @media only screen and (max-device-width: 1024px) and (orientation:portrait) { .landscape { display: none; } } @media only screen and (max-device-width: 1024px) and (orientation:landscape) { .portrait { display: none; } } &amp;amp;lt;!-- example markup --&amp;amp;gt; &amp;amp;lt;h1 class=&amp;amp;quot;portrait&amp;amp;quot;&amp;amp;gt;Your device orientation is &amp;amp;quot;portrait&amp;amp;quot;&amp;amp;lt;h1&amp;amp;gt; &amp;amp;lt;h1 class=&amp;amp;quot;landscape&amp;amp;quot;&amp;amp;gt;Your device orientation is &amp;amp;quot;landscape&amp;amp;quot;&amp;amp;lt;h1&amp;amp;gt;

(source and more info)

Wrapping Text Inside Pre Tags

height: 120px; overflow: auto; font-family: “Consolas”,monospace; font-size: 9pt; text-align:left; background-color: #FCF7EC; overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ margin: 0px 0px 0px 0px; padding:5px 5px 3px 5px; white-space : normal; /* crucial for IE 6, maybe 7? */

(source)

Hardboiled CSS3 Media Queries

/* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 320px) and (max-device-width : 480px) { /* Styles */ } /* Smartphones (landscape) ----------- */ @media only screen and (min-width : 321px) { /* Styles */ } /* Smartphones (portrait) ----------- */ @media only screen and (max-width : 320px) { /* Styles */ } /* iPads (portrait and landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { /* Styles */ } /* iPads (landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { /* Styles */ } /* iPads (portrait) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { /* Styles */ } /* Desktops and laptops ----------- */ @media only screen and (min-width : 1224px) { /* Styles */ } /* Large screens ----------- */ @media only screen and (min-width : 1824px) { /* Styles */ } /* iPhone 4 ----------- */ @media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) { /* Styles */ }

(source and more info) – Download the CSS file

Eric Meyer’s Reset Reloaded

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline; } /* remember to define focus styles! */ :focus { outline: 0; } body { line-height: 1; color: black; background: white; } ol, ul { list-style: none; } /* tables still need 'cellspacing=&amp;amp;quot;0&amp;amp;quot;' in the markup */ table { border-collapse: separate; border-spacing: 0; } caption, th, td { text-align: left; font-weight: normal; } blockquote:before, blockquote:after, q:before, q:after { content: &amp;amp;quot;&amp;amp;quot;; } blockquote, q { quotes: &amp;amp;quot;&amp;amp;quot; &amp;amp;quot;&amp;amp;quot;; }

(source)

Multiple borders

An element must be relatively positioned and have sufficient padding to contain the width of the extra border you will be creating with pseudo-elements.

#borders { position:relative; z-index:1; padding:30px; border:5px solid #f00; background:#ff9600; }

The pseudo-elements are positioned at specific distances away from the edge of the element’s box, moved behind the content layer with the negative z-index, and given the border and background values you want.

#borders:before { content:&amp;amp;quot;&amp;amp;quot;; position:absolute; z-index:-1; top:5px; left:5px; right:5px; bottom:5px; border:5px solid #ffea00; background:#4aa929; } #borders:after { content:&amp;amp;quot;&amp;amp;quot;; position:absolute; z-index:-1; top:15px; left:15px; right:15px; bottom:15px; border:5px solid #00b4ff; background:#fff; }

(source) – Demo

Remove Scrollbar from Textarea in IE

It makes you wonder why do textareas have in IE a scrollbar even when they’re empty. Nobody knows for sure but here’s the solution.

textarea { overflow: auto; }

CSS: border-radius and -moz-border-radius

One of the most keenly-anticipated CSS3 properties is border-radius. Web designers will no longer have to resort to complex table structures using custom-made corner graphics or including arcane JavaScript files in order to produce designs with rounded corners.

While Internet Explorer doesn’t support many (or any) advanced CSS properties, you can get started using Firefox and any of the ‘Mozilla’ family of browsers. Apple’s WebKit web browser engine also supports rounded corners making them available in the Safari and Chrome web browsers, the iPhone and other devices running WebKit.

Simple and Nice Blockquote Styling

blockquote { background:#f9f9f9; border-left:10px solid #ccc; margin:1.5em 10px; padding:.5em 10px; quotes:&amp;amp;quot;\201C&amp;amp;quot;&amp;amp;quot;\201D&amp;amp;quot;&amp;amp;quot;\2018&amp;amp;quot;&amp;amp;quot;\2019&amp;amp;quot;; } blockquote:before { color:#ccc; content:open-quote; font-size:4em; line-height:.1em; margin-right:.25em; vertical-align:-.4em; } blockquote p { display:inline; }

(source)

:-moz-placeholder

:-moz-placeholder matches form elements displaying placeholder text. This allows web developers and theme designers to customize the appearance of placeholder text, which is a light grey color by default. This may not work well if you’ve changed the background color of your form fields to be a similar color, for example, so you can use this pseudo-class to change the placeholder text color.

&amp;amp;lt;!doctype html&amp;amp;gt; &amp;amp;lt;html&amp;amp;gt; &amp;amp;lt;head&amp;amp;gt; &amp;amp;lt;title&amp;amp;gt;Placeholder demo&amp;amp;lt;/title&amp;amp;gt; &amp;amp;lt;style type=&amp;amp;quot;text/css&amp;amp;quot;&amp;amp;gt; input:-moz-placeholder { color: green; } &amp;amp;lt;/style&amp;amp;gt; &amp;amp;lt;/head&amp;amp;gt; &amp;amp;lt;body&amp;amp;gt; &amp;amp;lt;input id=&amp;amp;quot;test&amp;amp;quot; placeholder=&amp;amp;quot;Placeholder text!&amp;amp;quot;&amp;amp;gt; &amp;amp;lt;/body&amp;amp;gt; &amp;amp;lt;/html&amp;amp;gt;

(source)

Sticky Footer

I’ve shown you one way of making the footer stay sticky, now here’s another one:

* { margin:0; padding:0; } html, body, #wrap { height: 100%; } body &amp;amp;gt; #wrap {height: auto; min-height: 100%;} #main { padding-bottom: 150px; } /* must be same height as the footer */ #footer { position: relative; margin-top: -150px; /* negative value of footer height */ height: 150px; clear:both;} /* CLEAR FIX*/ .clearfix:after {content: &amp;amp;quot;.&amp;amp;quot;; display: block; height: 0; clear: both; visibility: hidden;} .clearfix {display: inline-block;} /* Hides from IE-mac \*/ * html .clearfix { height: 1%;} .clearfix {display: block;} /* End hide from IE-mac */

&amp;amp;lt;div id=&amp;amp;quot;wrap&amp;amp;quot;&amp;amp;gt; &amp;amp;lt;div id=&amp;amp;quot;main&amp;amp;quot; class=&amp;amp;quot;clearfix&amp;amp;quot;&amp;amp;gt; &amp;amp;lt;/div&amp;amp;gt; &amp;amp;lt;/div&amp;amp;gt; &amp;amp;lt;div id=&amp;amp;quot;footer&amp;amp;quot;&amp;amp;gt; &amp;amp;lt;/div&amp;amp;gt;

(source)

21 Awesome @font-face Embeddable Typefaces

While @font-face may not work in all browsers, I think it’s still one of the best solution available today. Of course not all type foundries will let us embed their fonts on our webpages. There are solutions like Typekit which look very promising but today we’ll simply go over the @font-face CSS property and check out some typefaces you can use with @font-face

Before you can start using those typefaces on your site you need to declare the font file(s) in your CSS file along with the font-weight and font-style if available. Like this:

@font-face { font-family: GraublauWeb; src: url(&amp;amp;quot;path-to-the-font-file/GraublauWeb.otf&amp;amp;quot;) format(&amp;amp;quot;opentype&amp;amp;quot;); } @font-face { font-family: GraublauWeb; font-weight: bold; src: url(&amp;amp;quot;path-to-the-font-file/GraublauWebBold.otf&amp;amp;quot;) format(&amp;amp;quot;opentype&amp;amp;quot;); }

Then you can call the font via the font-familly property. Don’t forget to put some other (web-safe) fonts there as a fallback option. Like this:

h1 { font-family: GraublauWeb, Helvetica, Verdana, Sans-Serif; }

(source and more info)

Text Rotation with CSS

Thankfully, many of the popular browsers of today support the ability to rotate HTML elements. Even better? We can make it work in Internet Explorer (back to version 5.5 even). How you might ask? Okay, let’s look at the HTML.

&amp;amp;lt;div class=&amp;amp;quot;example-date&amp;amp;quot;&amp;amp;gt; &amp;amp;lt;span class=&amp;amp;quot;day&amp;amp;quot;&amp;amp;gt;31&amp;amp;lt;/span&amp;amp;gt; &amp;amp;lt;span class=&amp;amp;quot;month&amp;amp;quot;&amp;amp;gt;July&amp;amp;lt;/span&amp;amp;gt; &amp;amp;lt;span class=&amp;amp;quot;year&amp;amp;quot;&amp;amp;gt;2009&amp;amp;lt;/span&amp;amp;gt; &amp;amp;lt;/div&amp;amp;gt;

For Webkit and Firefox (as of 3.5), you can take advantage of the proposed transform property to handle the rotation. Each browser requires its property prefix for now.

-webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg);

In order to perform a transformation, the element has to be set to display:block. In this case, just add the declaration to the span that you want to rotate.

When it comes to effects in Internet Explorer, there is a surprising amount of power (and untapped at that, I’d say) in using filters. Although misleading, there is a filter called BasicImage that offers up the ability to rotate any element that has layout.

filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

(source and demo)

Background transparency

Being able to set the transparency of the background without affecting the transparency of the foreground (the text) is quite handy. That’s why there’s rgba() in CSS (red, green, blue, alpha). IE is not yet supporting it, but we can use the gradient filter which does support transparency. In this case we don’t need the actual gradient so we set start and end color to the same thing. Also the background: transparent is needed for the whole thing to work in IE:

.rgba { background-color: transparent; background-color: rgba(200,200,200,0.8); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99dddddd,endColorstr=#99dddddd); -ms-filter: &amp;amp;quot;progid:DXImageTransform.Microsoft.gradient(startColorstr=#99dddddd,endColorstr=#99dddddd)&amp;amp;quot;; }

(source)

Centering a DIV of Unknown Width

You can easily center a DIV by using margin:auto; property when you have mentioned its width in your CSS. But in case you wanted to center a DIV with unknown width, here is the code to do so :

.content { margin: 0 auto 8px; display: table; } .content div { display: table-cell; } &amp;amp;lt;!--[if IE]&amp;amp;gt; .content { display: block; text-align: center; } .content div { display: inline; zoom: 1; } &amp;amp;lt;![endif]--&amp;amp;gt;

Styling Links by File Type

You can easily style specific URLs by using icons. This works only with CSS3 compatible browsers and degrades nicely with non-compatible browsers. Make sure to change the icon image paths.

/* external links */ a[href^=&amp;amp;quot;http://&amp;amp;quot;] { padding-right: 13px; background: url(external.gif) no-repeat center right; } /* emails */ a[href^=&amp;amp;quot;mailto:&amp;amp;quot;] { padding-right: 20px; background: url(email.png) no-repeat center right; } /* pdfs */ a[href$=&amp;amp;quot;.pdf&amp;amp;quot;] { padding-right: 18px; background: url(acrobat.png) no-repeat center right; }

Fix IE6/7 double margin/padding bug

This problem appears when a left/right floated elements has a margin/padding value defined. To fix that just target these browsers as you earlier learned in this article and add “display: inline” declaration.

ul li { float: right; margin-right: 10px; *display: inline; /*Target IE7 and bellow*/ _display: inline; /*Target IE6 and bellow*/ } /* This example fixes the double right margin bug */

Change text selection style

::selection { color: white; background-color: red; } ::-moz-selection /* Firefox needs an extra attention for this */ { color: white; background-color: red; }

Drop cap

Drop cap is not an option only for books and newspapers, you can now use it in web designs also and it’s pretty easy to implement.

p:first-letter{ display:block; margin:5px 0 0 5px; float:left; color:#FF3366; font-size:60px; font-family:Georgia; }

Style links depending on file format

Wanna learn UX. Start with this one. This css code snippet adds icons next to specific links so that the user knows where the link will take him to.

/* external links */ a[href^=&amp;amp;quot;http://&amp;amp;quot;]{ padding-right: 20px; background: url(external.gif) no-repeat center right; } /* emails */ a[href^=&amp;amp;quot;mailto:&amp;amp;quot;]{ padding-right: 20px; background: url(email.png) no-repeat center right; } /* pdfs */ a[href$=&amp;amp;quot;.pdf&amp;amp;quot;]{ padding-right: 20px; background: url(pdf.png) no-repeat center right; }

If you liked this article, you should also check out these as well: