You are on page 1of 11

Hide text with text indent This is extremely useful for use for things such as your company

logo. More ofte n than not, its an image, but youll want to display it in h1 tags for SEO as well. Heres the best way to do so. What we basically do is hide the text far away off the screen, and apply a background image instead. 1 h1 { 2 text-indent:-9999px; 3 margin:0 auto; 4 width:400px; 5 height:100px; 6 background:transparent url("images/logo.jpg") no-repeat scroll; 7 } Style links depending on file format This snippet is aimed at user experience. Often on the internet we find ourself clicking on links knowing nothing about where we are heading. This snippet can b e used and expanded to show small icons next to your links telling the user if i t is an external link, an email, a pdf, an image, and so much more. 1 /* external links */ 2 a[href^="http://"]{ 3 padding-right: 20px; 4 background: url(external.gif) no-repeat center right; 5 } 6 7 /* emails */ 8 a[href^="mailto:"]{ 9 padding-right: 20px; 10 background: url(email.png) no-repeat center right; 11 } 12 13 /* pdfs */ 14 a[href$=".pdf"]{ 15 padding-right: 20px; 16 background: url(pdf.png) no-repeat center right;

17 } Remove textarea scrollbar in IE Internet Explorer has an annoying habit of adding scrollbars to textareas even wh en the textareas content is not overflowing. You can rectify this flaw with this easy to use snippet. 1 textarea{ 2 overflow:auto; 3 } Drop cap Commonplace these days in blogs and news sites is the dropcap. Youd be surprised at how easy it is to implement, and how well it degrades for older browsers. 1 p:first-letter{ 2 display:block; 3 margin:5px 0 0 5px; 4 float:left; 5 color:#FF3366; 6 font-size:60px; 7 font-family:Georgia; 8 } Css Transparency Transparency is something that isnt done the same way across browsers which can b e annoying. Heres how you can target transparency in multiple browsers. 1 .transparent { 2 filter:alpha(opacity=50); 3 -moz-opacity:0.5; 4 -khtml-opacity: 0.5; 5 opacity: 0.5; 6 } Css Reset by Eric Meyer Eric Meyers css reset has become almost standard now days for use at the start of your stylesheet. Having been adopted by some of the most influential designers, you can be sure of its quality. 1 html, body, div, span, applet, object, iframe,

2 h1, h2, h3, h4, h5, h6, p, blockquote, pre, 3 a, abbr, acronym, address, big, cite, code, 4 del, dfn, em, font, img, ins, kbd, q, s, samp, 5 small, strike, strong, sub, sup, tt, var, 6 b, u, i, center, 7 dl, dt, dd, ol, ul, li, 8 fieldset, form, label, legend, 9 table, caption, tbody, tfoot, thead, tr, th, td { 10 margin: 0; 11 padding: 0; 12 border: 0; 13 outline: 0; 14 font-size: 100%; 15 vertical-align: baseline; 16 background: transparent; 17 } 18 19 body { 20 line-height: 1; 21 } 22 23 ol, ul { 24 list-style: none; 25 } 26 27 blockquote, q { 28 quotes: none; 29 } 30 31 blockquote:before, blockquote:after,

32 q:before, q:after { 33 content: ; 34 content: none; 35 } 36 37 /* remember to define focus styles! */ 38 :focus { 39 outline: 0; 40 } 41 42 /* remember to highlight inserts somehow! */ 43 ins { 44 text-decoration: none; 45 } 46 47 del { 48 text-decoration: line-through; 49 } 50 51 /* tables still need cellspacing="0" in the markup */ 52 table { 53 border-collapse: collapse; 54 border-spacing: 0; 55 } Image preloader Sometimes it is useful to pre-load your images so that when a certain element is needed, theyll already be loaded for you and there wont be any delay or flickeri ng. 1 div.loader{ 2 background:url(images/hover.gif) no-repeat; 3 background:url(images/hover2.gif) no-repeat;

4 background:url(images/hover3.gif) no-repeat; 5 margin-left:-10000px; 6 } Basic css sprite button Having a button or link with a background image is fairly normal, and nowadays, we require further effects to enhance the user experience. Once of this is an in dicator to the user that they are hovering over a button. Using a sprite, we can create this effect by changing the position of the background image down a cert ain height to show the background to the button on hover. A simple yet effective technique. 1 a { 2 display: block; 3 background: url(sprite.png) no-repeat; 4 height: 30px; 5 width: 250px; 6 } 7 8 a:hover { 9 background-position: 0 -30px; 10 } Google Font API Google recently released a fantastic resource for web designers allowing them to load new fonts from google for use in our web pages. We can even load different variants of fonts such as bold, italic and so on. While the library of fonts av ailable from google is limited, there is still plenty to use. First include the dynamically written stylesheet by naming the fonts and variants you want, and th en use the font names in your css as you normally would! For further info on Goo gle Font API, read here. 1 <head> 2 Inconsolata:italic|Droid+Sans"> 3 </head> 1 body { 2 font-family: Tangerine , Inconsolata , Droid Sans , serif; font-size: 48p x; 3 } Browser specific hacks

Sometimes its useful to target specific browsers to fix their inconsistencies and conditional comments arent always the best way to do so. This list of css browse r hacks by Chris Coyier is a top-notch list of ways to target browsers with simp le css. 1 /* IE 6 */ 2 * html .yourclass { } 3 4 /* IE 7 */ 5 *+html .yourclass{ } 6 7 /* IE 7 and modern browsers */ 8 html>body .yourclass { } 9 10 /* Modern browsers (not IE 7) */ 11 html>/**/body .yourclass { } 12 13 /* Opera 9.27 and below */ 14 html:first-child .yourclass { } 15 16 /* Safari */ 17 html[xmlns*=""] body:last-child .yourclass { } 18 19 /* Safari 3+, Chrome 1+, Opera 9+, Fx 3.5+ */ 20 body:nth-of-type(1) .yourclass { } 21 22 /* Safari 3+, Chrome 1+, Opera 9+, Fx 3.5+ */ 23 body:first-of-type .yourclass { } 24 25 /* Safari 3+, Chrome 1+ */ 26 @media screen and (-webkit-min-device-pixel-ratio:0) { 27 .yourclass { } 28

} Fixed Footer You would think creating a footer that sticks to the bottom of the screen would be rather hard, but surprisingly it isnt if you want to start with a basic footer . There is an IE6 hack we have to use, but apart from that, its easy! 1 #footer { 2 position:fixed; 3 left:0px; 4 bottom:0px; 5 height:30px; 6 width:100%; 7 background:#999; 8 } 9 10 /* IE 6 */ 11 * html #footer { 12 position:absolute; 13 top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeig ht ? document.documentElement.clientHeight : document.body.clientHeight)+(ignore Me = document.documentElement.scrollTop ? document.documentElement.scrollTop : d ocument.body.scrollTop))+ px ); 14 } Flip an image Flipping an image rather than just loading a new image that is already reversed can be rather useful. Say you want to use only one image for an arrow, but have several on the page going in different directions. Heres your problem solved. 1 img.flip { 2 -moz-transform: scaleX(-1); 3 -o-transform: scaleX(-1); 4 -webkit-transform: scaleX(-1); 5 transform: scaleX(-1); 6 filter: FlipH; 7 -ms-filter: "FlipH"; 8 }

Clearfix A while back, someone decided it was time to clear floated elements without addi ng any extra markup to the document. They did this by creating a class that can be applied to the container of floated children to clear it. A fantastic way to do so, and something that is nowadays, widely used. 1 .clearfix:after { 2 visibility: hidden; 3 display: block; 4 font-size: 0; 5 content: " "; 6 clear: both; 7 height: 0; 8 } 9 10 .clearfix { display: inline-block; } 11 12 /* start commented backslash hack \*/ 13 * html .clearfix { height: 1%; } 14 .clearfix { display: block; } 15 /* close commented backslash hack */ Rounded Corners With the slow introduction of css3, rounded corners have been made easily possib ly in modern browsers. Sadly we still dont have css3 support for IE, but it will be available in IE9 whenever that is released. 1 .round{ 2 -moz-border-radius: 10px; 3 -webkit-border-radius: 10px; 4 border-radius: 10px; /* future proofing */ 5 -khtml-border-radius: 10px; /* for old Konqueror browsers */ 6 } Style Overriding It still surprises me that some people dont know about !important in css, because it is such a powerful and useful tool to have. Basically, any rule with !import ant at the end, will override any of the same rule that is applied to that eleme

nt wherever it appears in the css file, or in-line html. 1 p{ 2 font-size:20px !important; 3 } Font face Font-face didnt really break through until late last year, but has been around si nce the days of IE6 being a modern browser! Its picked up in support a lot now th ough, and offers a great way to use non web safe fonts in your web projects. Whi le this snippet works, you might as well save your time by using the Font Squirr el Font Face Generator. 1 @font-face { 2 font-family: Graublau Web ; 3 src: url( GraublauWeb.eot ); 4 src: local( ), 5 url( GraublauWeb.woff ) format( woff ), url( GraublauWeb.ttf ) format( t ruetype ); 6 } Center a website A common design trend these days is for your website to center itself in the mid dle of browsers viewport horizontally. This is an easily achievable thing to do. 1 .wrapper { 2 width:960px; 3 margin:0 auto; 4 } Min-height in IE This comes down to fixing a simple, yet annoying bug in IEs capability of handlin g min-height. In essence, IE interprets height as min-height, so since IE wont i mplement the auto height, this snippet will fix all this for us. 1 .box { 2 min-height:500px; 3 height:auto !important; 4 height:500px; 5 } Image loading

This image loading effects mimics that of an ajax loader, where a loading circle is displayed while content loads. This works especially well for larger, slower loading images, and is css only! 1 img { 2 background: url(loader.gif) norepeat 50% 50%; 3 } Vertical Center This short snippet allows you to vertically center the contents of a container w ithout any extra markup by simply displaying it as a table cell which then allow s you to use the vertical-align attribute. 1 .container { 2 min-height: 10em; 3 display: table-cell; 4 vertical-align: middle; 5 } Create pullquotes Firstly, what is a pullquote? Well in news and magazine style websites, youll oft en notice small quotes added within the article, not as full blockquotes, but as small quotes that sit within the article but to the side, sometimes adding thin gs such as peoples opinions or quotes. They are extremely easy to create youll be glad to know, and when used properly, can add greatly to the user experience whe n reading an article. 1 .pullquote { 2 width: 300px; 3 float: right; 4 margin: 5px; 5 font-family: Georgia, "Times New Roman", Times, serif; 6 font: italic bold #ff0000 ; 7 } Text Selection Some people are unaware that it is possible to change the color when you highlig ht text in your browser. It is so easy to with two selectors; just be careful yo u dont ruin your site with it. 1 ::selection { 2 color: #000000; 3

background-color: #FF0000; 4 } 5 ::-moz-selection { 6 color: #000000; 7 background: #FF0000; 8 } Print page breaks This adds again to the user experience when printing. For example, when printing an article, it may be useful for a user to have the comments on a new page from the article itself. by adding this class to the comments area, a page break will appear when printing. It can be used anywhere else on your site as well! 1 .page-break{ 2 page-break-before:always; 3 }

You might also like