Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Friday, December 20, 2013

How do I make my div 100% height?

You need to know what the 100% is of, so the parent div must have a height set. One problem that people often come up against is making the main page fill the screen if there's little content. You can do that like this :
CSS
body, html {
height:100%;
}
body {
margin:0;
padding:0;
}
#wrap {
position:relative;
min-height:100%;
}
* html #wrap {
height:100%;
}

Here, the #wrap div goes around your whole page - it's like a sub-body.

You need to use 'min-height' rather than 'height' for Firefox because otherwise it will set it to 100% of the viewport and no more. Internet Explorer, being well... crap, treats 'height' as it should be treating 'min-height' which it doesn't recognise. (You can target IE by preceding your code with ' * html ').

To make floated divs within this #wrap div 100% of the #wrap div... well that's more difficult. I think the best way is to use the 'faux columns' technique which basically means that you put the background in your body rather than your columns. If the body has columns and your floats don't then it looks like your floated content is in a column that stretches to the bottom of the page. I've used this technique in my layout demos.

The problem is often not that the columns aren't 100% height, but that they're not equal lengths. Columns usually don't start from the top of the page and end at the bottom - there's often a header and a footer or sometimes, more interesting designs don't have a recognisable columnar layout, but do require div boxes to be equal heights. This can be done with the aid of a couple of images and some css or with some javascript.
Source: http://goo.gl/8QTHTj

Friday, January 27, 2012

Font Size Conversion Chart


Font Size Conversion Chart
Points Pixels Ems Percent Keyword Default sans-serif
6pt 8px 0.5em 50% CSS Tricks
7pt 9px 0.55em 55% CSS Tricks
7.5pt 10px 0.625em 62.5% x-small CSS Tricks
8pt 11px 0.7em 70% CSS Tricks
9pt 12px 0.75em 75% CSS Tricks
10pt 13px 0.8em 80% small CSS Tricks
10.5pt 14px 0.875em 87.5% CSS Tricks
11pt 15px 0.95em 95% CSS Tricks
12pt 16px 1em 100% medium CSS Tricks
13pt 17px 1.05em 105% CSS Tricks
13.5pt 18px 1.125em 112.5% large CSS Tricks
14pt 19px 1.2em 120% CSS Tricks
14.5pt 20px 1.25em 125% CSS Tricks
15pt 21px 1.3em 130% CSS Tricks
16pt 22px 1.4em 140% CSS Tricks
17pt 23px 1.45em 145% CSS Tricks
18pt 24px 1.5em 150% x-large CSS Tricks
20pt 26px 1.6em 160% CSS Tricks
22pt 29px 1.8em 180% CSS Tricks
24pt 32px 2em 200% xx-large CSS Tricks
26pt 35px 2.2em 220% CSS Tricks
27pt 36px 2.25em 225% CSS Tricks
28pt 37px 2.3em 230% CSS Tricks
29pt 38px 2.35em 235% CSS Tricks
30pt 40px 2.45em 245% CSS Tricks
32pt 42px 2.55em 255% CSS Tricks
34pt 45px 2.75em 275% CSS Tricks
36pt 48px 3em 300% CSS Tricks
There is a good online PX to EM conversion calculator available. You can also use this calculator.

Friday, July 9, 2010

HTML Hexadecimal Color Codes

Color Color Code Color Color Code
Red #FF0000 White #FFFFFF
Turquoise #00FFFF Light Grey #C0C0C0
Light Blue #0000FF Dark Grey #808080
Dark Blue #0000A0 Black #000000
Light Purple #FF0080 Orange #FF8040
Dark Purple #800080 Brown #804000
Yellow #FFFF00 Burgundy #800000
Pastel Green #00FF00 Forest Green #808000
Pink #FF00FF Grass Green #408080




Color Code Chart

COLOR NAME CODE COLOR
Black #000000 Black
Gray0 #150517 Gray0
Gray18 #250517 Gray18
Gray21 #2B1B17 Gray21
Gray23 #302217 Gray23
Gray24 #302226 Gray24
Gray25 #342826 Gray25
Gray26 #34282C Gray26
Gray27 #382D2C Gray27
Gray28 #3b3131 Gray28
Gray29 #3E3535 Gray29
Gray30 #413839 Gray30
Gray31 #41383C Gray31
Gray32 #463E3F Gray32
Gray34 #4A4344 Gray34
Gray35 #4C4646 Gray35
Gray36 #4E4848 Gray36
Gray37 #504A4B Gray37
Gray38 #544E4F Gray38
Gray39 #565051 Gray39
Gray40 #595454 Gray40
Gray41 #5C5858 Gray41
Gray42 #5F5A59 Gray42
Gray43 #625D5D Gray43
Gray44 #646060 Gray44
Gray45 #666362 Gray45
Gray46 #696565 Gray46
Gray47 #6D6968 Gray47
Gray48 #6E6A6B Gray48
Gray49 #726E6D Gray49
Gray50 #747170 Gray50
Gray #736F6E Gray
Slate Gray4 #616D7E Slate Gray4
Slate Gray #657383 Slate Gray
Light Steel Blue4 #646D7E Light Steel Blue4
Light Slate Gray #6D7B8D Light Slate Gray
Cadet Blue4 #4C787E Cadet Blue4
Dark Slate Gray4 #4C7D7E Dark Slate Gray4
Thistle4 #806D7E Thistle4
Medium Slate Blue #5E5A80 Medium Slate Blue
Medium Purple4 #4E387E Medium Purple4
Midnight Blue #151B54 Midnight Blue
Dark Slate Blue #2B3856 Dark Slate Blue
Dark Slate Gray #25383C Dark Slate Gray
Dim Gray #463E41 Dim Gray
Cornflower Blue #151B8D Cornflower Blue
Royal Blue4 #15317E Royal Blue4
Slate Blue4 #342D7E Slate Blue4
Royal Blue #2B60DE Royal Blue
Royal Blue1 #306EFF Royal Blue1
Royal Blue2 #2B65EC Royal Blue2
Royal Blue3 #2554C7 Royal Blue3
Deep Sky Blue #3BB9FF Deep Sky Blue
Deep Sky Blue2 #38ACEC Deep Sky Blue2
Slate Blue #357EC7 Slate Blue
Deep Sky Blue3 #3090C7 Deep Sky Blue3
Deep Sky Blue4 #25587E Deep Sky Blue4
Dodger Blue #1589FF Dodger Blue
Dodger Blue2 #157DEC Dodger Blue2
Dodger Blue3 #1569C7 Dodger Blue3
Dodger Blue4 #153E7E Dodger Blue4
Steel Blue4 #2B547E Steel Blue4
Steel Blue #4863A0 Steel Blue
Slate Blue2 #6960EC Slate Blue2
Violet #8D38C9 Violet
Medium Purple3 #7A5DC7 Medium Purple3
Medium Purple #8467D7 Medium Purple
Medium Purple2 #9172EC Medium Purple2
Medium Purple1 #9E7BFF Medium Purple1
Light Steel Blue #728FCE Light Steel Blue
Steel Blue3 #488AC7 Steel Blue3
Steel Blue2 #56A5EC Steel Blue2
Steel Blue1 #5CB3FF Steel Blue1
Sky Blue3 #659EC7 Sky Blue3
Sky Blue4 #41627E Sky Blue4
Slate Blue #737CA1 Slate Blue
Slate Blue #737CA1 Slate Blue
Slate Gray3 #98AFC7 Slate Gray3
Violet Red #F6358A Violet Red
Violet Red1 #F6358A Violet Red1
Violet Red2 #E4317F Violet Red2
Deep Pink #F52887 Deep Pink
Deep Pink2 #E4287C Deep Pink2
Deep Pink3 #C12267 Deep Pink3
Deep Pink4 #7D053F Deep Pink4
Medium Violet Red #CA226B Medium Violet Red
Violet Red3 #C12869 Violet Red3
Firebrick #800517 Firebrick
Violet Red4 #7D0541 Violet Red4
Maroon4 #7D0552 Maroon4
Maroon #810541 Maroon
Maroon3 #C12283 Maroon3
Maroon2 #E3319D Maroon2
Maroon1 #F535AA Maroon1
Magenta #FF00FF Magenta
Magenta1 #F433FF Magenta1
Magenta2 #E238EC Magenta2
Magenta3 #C031C7 Magenta3
Medium Orchid #B048B5 Medium Orchid
Medium Orchid1 #D462FF Medium Orchid1
Medium Orchid2 #C45AEC Medium Orchid2
Medium Orchid3 #A74AC7 Medium Orchid3
Medium Orchid4 #6A287E Medium Orchid4
Purple #8E35EF Purple
Purple1 #893BFF Purple1
Purple2 #7F38EC Purple2
Purple3 #6C2DC7 Purple3
Purple4 #461B7E Purple4
Dark Orchid4 #571B7e Dark Orchid4
Dark Orchid #7D1B7E Dark Orchid
Dark Violet #842DCE Dark Violet
Dark Orchid3 #8B31C7 Dark Orchid3
Dark Orchid2 #A23BEC Dark Orchid2
Dark Orchid1 #B041FF Dark Orchid1
Plum4 #7E587E Plum4
Pale Violet Red #D16587 Pale Violet Red
Pale Violet Red1 #F778A1 Pale Violet Red1
Pale Violet Red2 #E56E94 Pale Violet Red2
Pale Violet Red3 #C25A7C Pale Violet Red3
Pale Violet Red4 #7E354D Pale Violet Red4
Plum #B93B8F Plum
Plum1 #F9B7FF Plum1
Plum2 #E6A9EC Plum2
Plum3 #C38EC7 Plum3
Thistle #D2B9D3 Thistle
Thistle3 #C6AEC7 Thistle3
Lavender Blush2 #EBDDE2 Lavender Blush2
Lavender Blush3 #C8BBBE Lavender Blush3
Thistle2 #E9CFEC Thistle2
Thistle1 #FCDFFF Thistle1
Lavender #E3E4FA Lavender
Lavender Blush #FDEEF4 Lavender Blush
Light Steel Blue1 #C6DEFF Light Steel Blue1
Light Blue #ADDFFF Light Blue
Light Blue1 #BDEDFF Light Blue1
Light Cyan #E0FFFF Light Cyan
Slate Gray1 #C2DFFF Slate Gray1
Slate Gray2 #B4CFEC Slate Gray2
Light Steel Blue2 #B7CEEC Light Steel Blue2
Turquoise1 #52F3FF Turquoise1
Cyan #00FFFF Cyan
Cyan1 #57FEFF Cyan1
Cyan2 #50EBEC Cyan2
Turquoise2 #4EE2EC Turquoise2
Medium Turquoise #48CCCD Medium Turquoise
Turquoise #43C6DB Turquoise
Dark Slate Gray1 #9AFEFF Dark Slate Gray1
Dark Slate Gray2 #8EEBEC Dark slate Gray2
Dark Slate Gray3 #78c7c7 Dark Slate Gray3
Cyan3 #46C7C7 Cyan3
Turquoise3 #43BFC7 Turquoise3
Cadet Blue3 #77BFC7 Cadet Blue3
Pale Turquoise3 #92C7C7 Pale Turquoise3
Light Blue2 #AFDCEC Light Blue2
Dark Turquoise #3B9C9C Dark Turquoise
Cyan4 #307D7E Cyan4
Light Sea Green #3EA99F Light Sea Green
Light Sky Blue #82CAFA Light Sky Blue
Light Sky Blue2 #A0CFEC Light Sky Blue2
Light Sky Blue3 #87AFC7 Light Sky Blue3
Sky Blue #82CAFF Sky Blue
Sky Blue2 #79BAEC Sky Blue2
Light Sky Blue4 #566D7E Light Sky Blue4
Sky Blue #6698FF Sky Blue
Light Slate Blue #736AFF Light Slate Blue
Light Cyan2 #CFECEC Light Cyan2
Light Cyan3 #AFC7C7 Light Cyan3
Light Cyan4 #717D7D Light Cyan4
Light Blue3 #95B9C7 Light Blue3
Light Blue4 #5E767E Light Blue4
Pale Turquoise4 #5E7D7E Pale Turquoise4
Dark Sea Green4 #617C58 Dark Sea Green4
Medium Aquamarine #348781 Medium Aquamarine
Medium Sea Green #306754 Medium Sea Green
Sea Green #4E8975 Sea Green
Dark Green #254117 Dark Green
Sea Green4 #387C44 Sea Green4
Forest Green #4E9258 Forest Green
Medium Forest Green #347235 Medium Forest Green
Spring Green4 #347C2C Spring Green4
Dark Olive Green4 #667C26 Dark Olive Green4
Chartreuse4 #437C17 Chartreuse4
Green4 #347C17 Green4
Medium Spring Green #348017 Medium Spring Green
Spring Green #4AA02C Spring Green
Lime Green #41A317 Lime Green
Spring Green #4AA02C Spring Green
Dark Sea Green #8BB381 Dark Sea Green
Dark Sea Green3 #99C68E Dark Sea Green3
Green3 #4CC417 Green3
Chartreuse3 #6CC417 Chartreuse3
Yellow Green #52D017 Yellow Green
Spring Green3 #4CC552 Spring Green3
Sea Green3 #54C571 Sea Green3
Spring Green2 #57E964 Spring Green2
Spring Green1 #5EFB6E Spring Green1
Sea Green2 #64E986 Sea Green2
Sea Green1 #6AFB92 Sea Green1
Dark Sea Green2 #B5EAAA Dark Sea Green2
Dark Sea Green1 #C3FDB8 Dark Sea Green1
Green #00FF00 Green
Lawn Green #87F717 Lawn Green
Green1 #5FFB17 Green1
Green2 #59E817 Green2
Chartreuse2 #7FE817 Chartreuse2
Chartreuse #8AFB17 Chartreuse
Green Yellow #B1FB17 Green Yellow
Dark Olive Green1 #CCFB5D Dark Olive Green1
Dark Olive Green2 #BCE954 Dark Olive Green2
Dark Olive Green3 #A0C544 Dark Olive Green3
Yellow #FFFF00 Yellow
Yellow1 #FFFC17 Yellow1
Khaki1 #FFF380 Khaki1
Khaki2 #EDE275 Khaki2
Goldenrod #EDDA74 Goldenrod
Gold2 #EAC117 Gold2
Gold1 #FDD017 Gold1
Goldenrod1 #FBB917 Goldenrod1
Goldenrod2 #E9AB17 Goldenrod2
Gold #D4A017 Gold
Gold3 #C7A317 Gold3
Goldenrod3 #C68E17 Goldenrod3
Dark Goldenrod #AF7817 Dark Goldenrod
Khaki #ADA96E Khaki
Khaki3 #C9BE62 Khaki3
Khaki4 #827839 Khaki4
Dark Goldenrod1 #FBB117 Dark Goldenrod1
Dark Goldenrod2 #E8A317 Dark Goldenrod2
Dark Goldenrod3 #C58917 Dark Goldenrod3
Sienna1 #F87431 Sienna1
Sienna2 #E66C2C Sienna2
Dark Orange #F88017 Dark Orange
Dark Orange1 #F87217 Dark Orange1
Dark Orange2 #E56717 Dark Orange2
Dark Orange3 #C35617 Dark Orange3
Sienna3 #C35817 Sienna3
Sienna #8A4117 Sienna
Sienna4 #7E3517 Sienna4
Indian Red4 #7E2217 Indian Red4
Dark Orange3 #7E3117 Dark Orange3
Salmon4 #7E3817 Salmon4
Dark Goldenrod4 #7F5217 Dark Goldenrod4
Gold4 #806517 Gold4
Goldenrod4 #805817 Goldenrod4
Light Salmon4 #7F462C Light Salmon4
Chocolate #C85A17 Chocolate
Coral3 #C34A2C Coral3
Coral2 #E55B3C Coral2
Coral #F76541 Coral
Dark Salmon #E18B6B Dark Salmon
Salmon1 #F88158 Pale Turquoise4
Salmon2 #E67451 Salmon2
Salmon3 #C36241 Salmon3
Light Salmon3 #C47451 Light Salmon3
Light Salmon2 #E78A61 Light Salmon2
Light Salmon #F9966B Light Salmon
Sandy Brown #EE9A4D Sandy Brown
Hot Pink #F660AB Hot Pink
Hot Pink1 #F665AB Hot Pink1
Hot Pink2 #E45E9D Hot Pink2
Hot Pink3 #C25283 Hot Pink3
Hot Pink4 #7D2252 Hot Pink4
Light Coral #E77471 Light Coral
Indian Red1 #F75D59 Indian Red1
Indian Red2 #E55451 Indian Red2
Indian Red3 #C24641 Indian Red3
Red #FF0000 Red
Red1 #F62217 Red1
Red2 #E41B17 Red2
Firebrick1 #F62817 Firebrick1
Firebrick2 #E42217 Firebrick2
Firebrick3 #C11B17 Firebrick3
Pink #FAAFBE Pink
Rosy Brown1 #FBBBB9 Rosy Brown1
Rosy Brown2 #E8ADAA Rosy Brown2
Pink2 #E7A1B0 Pink2
Light Pink #FAAFBA Light Pink
Light Pink1 #F9A7B0 Light Pink1
Light Pink2 #E799A3 Light Pink2
Pink3 #C48793 Pink3
Rosy Brown3 #C5908E Rosy Brown3
Rosy Brown #B38481 Rosy Brown
Light Pink3 #C48189 Light Pink3
Rosy Brown4 #7F5A58 Rosy Brown4
Light Pink4 #7F4E52 Light Pink4
Pink4 #7F525D Pink4
Lavender Blush4 #817679 Lavendar Blush4
Light Goldenrod4 #817339 Light Goldenrod4
Lemon Chiffon4 #827B60 Lemon Chiffon4
Lemon Chiffon3 #C9C299 Lemon Chiffon3
Light Goldenrod3 #C8B560 Light Goldenrod3
Light Golden2 #ECD672 Light Golden2
Light Goldenrod #ECD872 Light Goldenrod
Light Goldenrod1 #FFE87C Light Goldenrod1
Lemon Chiffon2 #ECE5B6 Lemon Chiffon2
Lemon Chiffon #FFF8C6 Lemon Chiffon
Light Goldenrod Yellow #FAF8CC Light Goldenrod Yellow

Thursday, September 10, 2009

CSS Tricks

CSS3? What's that?!

I'm sure you've heard of CSS in general. CSS3 isn't that much different, in terms of syntax; however, the power of CSS3 is much greater. As you'll see in these eleven techniques, you can have multiple backgrounds, dynamically resize those backgrounds, border radiuses, text shadows, and more!

Here's what the official (or at least, what I consider official) website of CSS3, css3.info, has to say about CSS3:

CSS3 is the new kid in the stylesheet family. It offers exciting new possibilities to create an impact with your designs, allows you to use more diverse style sheets for a variety of occasions and lots more.

What We'll Be Covering

Here are the 11 techniques that I'll be showing you how to recreate with CSS3. I'll show you how to create them using CSS2 (or JavaScript), and then with CSS3 properties. Remember - these effects will only work in modern browsers that implement these CSS3 features. Your best option is to view these with Safari 4.

  1. Rounded Corners
  2. Box Shadow
  3. Text Shadow
  4. Fancy Font
  5. Opacity
  6. RGBA
  7. Background Size
  8. Multiple Backgrounds
  9. Columns
  10. Border Image
  11. Animations

1. Rounded Corners

Rounded Corners

Probably my favorite on of this list, rounded corners provide a developer with so many options. You can create a rounded corner button in seconds. My favorite thing to do is set a gradient background to repeat along the x-axis and then apply rounded corners to make a very nice looking Web 2.0 button.

You can simulate rounded corners by using four extra divs or by using JavaScript. Though, a user doesn't see these smooth corners if they have JavaScript disabled, I think that's fine as long as the website still functions as it should. You can read up on this method if you would prefer to use pure CSS in making rounded corners.

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript" src="js/jquery.corners.js"></script>  
  3. <script type="text/javascript">  
  4. $(function(){  
  5.     $('.box').corners('10px');  
  6. });  
  7. </script>  
  8. <div class="box">  
  9.     <!--CONTENT-->  
  10. </div>  

The classical method uses jQuery along with a JavaScript plugin called Corners.

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. border-radius: 10px;  
  4. -moz-border-radius: 10px;  
  5. -webkit-border-radius: 10px;  
  6. }  
  7. </style>  
  8. <div class="box">  
  9.     <!--CONTENT-->  
  10. </div>  

As you can see, all that you need to do is specify three CSS3 properties. Eventually, it will only be one; you have to use three now because different browsers use different property names.

View the demo.

2. Box Shadow

Box Shadow

Box shadows provide you with a very powerful tool. 99% of the time when I'm desigining, I find myself using drop shadows for something. Once again, I'll be using a jQuery plugin to take care of the classic way because honestly, trying to figure it out with just CSS is confusing. Why should I waste my time fiddling with negative margins when there's already something written that does the job for me? As long as my design looks fine when people have JavaScript disabled, I'm perfectly content using a jQuery plugin.

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript" src="js/jquery.dropShadow.js"></script>  
  3. <script type="text/javascript">  
  4. $(function(){  
  5.     $('.box').dropShadow({  
  6.         left: 5,  
  7.         top: 5,  
  8.         opacity: 1.0,  
  9.         color: 'black'  
  10.     });  
  11. });  
  12. </script>  
  13. <div class="box">  
  14.     <!--CONTENT-->  
  15. </div>  

I'm using the dropShadow plugin. Simple and what I wanted; though I would prefer to use just CSS ;).

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. box-shadow: 5px 5px 2px black;  
  4. -moz-box-shadow: 5px 5px 2px black;  
  5. -webkit-box-shadow: 5px 5px 2px black;  
  6. }  
  7. </style>  
  8. <div class="box">  
  9.     <!--CONTENT-->  
  10. </div>  

The values for the box shadow properties are: x-offset y-offset blur color. Much easier than importing two JavaScript files, and A LOT easier than messing around with background images and negative margins.

View the demo.

3. Text Shadow

Text Shadow

If you've ever read a tutorial about how to make the letterpress effect in Photoshop, you'll know that the drop shadow effect is used. It's really simple to create letterpressed text, just follow this tutorial at Line25 by Chris Spooner.

Classic Way

  1. <style type="text/css">  
  2. .font {  
  3. font-size: 20px;  
  4. color: #2178d9;  
  5. }  
  6. .fonts {  
  7. position: relative;  
  8. }  
  9. .fonts .font {  
  10. position: absolute;  
  11. z-index: 200;  
  12. }  
  13. .fonts .second {  
  14. top: 1px;  
  15. color: #000;  
  16. z-index: 100;  
  17. }  
  18. </style>  
  19. <div class="fonts">  
  20.     <span class="font">The quick brown fox jumps over the lazy dog.</span>  
  21.     <span class="font second">The quick brown fox jumps over the lazy dog.</span>  
  22. </div>  

Instead of using a jQuery plugin this time, I just used some simple CSS tricks to absolutely position the text behind the other copy of text. The only bad thing about not using CSS3 for this situation is that you will get two copies of the text if CSS is disabled.

CSS3 Way

  1. <style type="text/css">  
  2. .font {  
  3. font-size: 20px;  
  4. color: #2178d9;  
  5. }  
  6. .font {  
  7. text-shadow: 0 1px 0 #000;  
  8. }  
  9. </style>  
  10. <span class="font">The quick brown fox jumps over the lazy dog.</span>  

If you're planning on using text shadows that are blurred (the third "option" in the text-shadow property), I don't know how you would accomplish that with pure CSS, and no images.

View the demo.

4. Fancy Font

Fancy Font

We've dreamed about it for a long time now, but you can finally display "fancy fonts" on the web without relying on JavaScript. Of course this causes some issues with allowing paid fonts to be distributed over the internet. Anyhow, I present you with @font-face.

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript" src="js/cufon.js"></script>  
  3. <script type="text/javascript" src="js/loyal.js"></script>  
  4. <script type="text/javascript">  
  5. $(function(){  
  6.     Cufon.replace('.classic .font');  
  7. });  
  8. </script>  
  9. <style type="text/css">  
  10. .font {  
  11. font-size: 20px;  
  12. }  
  13. </style>  
  14. <span class="font">The quick brown fox jumps over the lazy dog.</span>  

I decided to use Cufón to replace the text. I'm not going to explain how to use it because Jeffrey has an awesome screencast already.

CSS3 Way

  1. <style type="text/css">  
  2. @font-face {  
  3. font-family: 'Loyal';  
  4. src: url('loyal.ttf');  
  5. }  
  6. .font {  
  7. font-family: Loyal;  
  8. font-size: 20px;  
  9. }  
  10. </style>  
  11. <span class="font">The quick brown fox jumps over the lazy dog.</span>  

We create a font family with @font-face and then use it as a value for font-family. Michael Owens wrote an article here about a month ago which explains @font-face quite well.

View the demo.

5. Opacity

Opacity

If you've visited the Envato website redesign lately, you might have noticed that there are a lot of transparent elements. Though this is achieved with transparent PNGs, you can achieve a similar effect by using the opacity property. Now, the opacity property has been around for a while, but our beloved IE has its own properties.

Classic Way

  1. <style type="text/css">  
  2. .box {  
  3. opacity: .6; // all modern browsers (this is CSS3)  
  4. -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; // IE 8  
  5. filter: alpha(opacity=60); // IE 5-7  
  6. }  
  7. </style>  
  8. <div class="box">  
  9.     <!--CONTENT-->  
  10. </div>  

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. opacity: .6;  
  4. }  
  5. </style>  
  6. <div class="box">  
  7.     <!--CONTENT-->  
  8. </div>  

With CSS3, we just eliminated two properties that were specific to IE, isn't that great?!

View the demo.

6. RGBA

RGBA

Everyone knows what RGB stands for (red, green, blue), but what does the A stand for? It stands for alpha, which refers to the transparency.

Other than rounded corners, RGBA is my next most used CSS3 property. Sometimes I just want to add a few light white/black background to navigation links when a user hover overs them. It's much easier than creating a new image for each color; however, with a little PHP it makes things a lot easier.

Classic Way

Seeing as how this isn't a PHP article, I won't be going over the PHP. Just save this file as rgba.php and when you need a certain RGBA color, make the background "color" as url(rgba.php?r=R&g=G&b=B&a=A).

  1. <?php  
  2. $image = imagecreatetruecolor(1, 1);  
  3. $r = (int)$_GET['r'];  
  4. $g = (int)$_GET['g'];  
  5. $b = (int)$_GET['b'];  
  6. $a = (float)$_GET['a'];  
  7. $white = imagecolorallocate($image, 255, 255, 255);  
  8. $color = imagecolorallocatealpha($image, $r, $g, $b, 127*(1-$a));  
  9. imagefill($image, 0, 0, $white);  
  10. imagefilledrectangle($image, 0, 0, 1, 1, $color);  
  11. header('Content-type: image/png');  
  12. imagepng($image);  
  13. ?>  

Now just apply that to a div...

  1. <style type="text/css">  
  2. .box {  
  3. background: url(rgba.php?r=239&g=182&b=29&a=.25);  
  4. }  
  5. </style>  
  6. <div class="box">  
  7.     <!--CONTENT-->  
  8. </div>  

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. background: rgba(239, 182, 29, .25);  
  4. }  
  5. </style>  
  6. <div class="box">  
  7.     <!--CONTENT-->  
  8. </div>  

View the demo.

7. Background Size

Background Size

The background size property is an amazing thing to have on your tool belt when you're creating a liquid layout. An example of this could be when you have a background image for a container that is for the sidebar. The classic way of doing this would require tweaking to have the image repeat along the y-axis, but with CSS3 it's like adding another background property.

Classic Way

  1. <style type="text/css">  
  2. .box {  
  3. position: relative;  
  4. overflow: hidden;  
  5. }  
  6.     .box img {  
  7.     position: absolute;  
  8.     top: 0;  
  9.     left: 0;  
  10.     width: 50%;  
  11.     height: 50%;  
  12.     z-index: 100;  
  13.     }  
  14.     .box .content {  
  15.     position: absolute;  
  16.     z-index: 200;  
  17.     }  
  18. </style>  
  19. <div class="box">  
  20.     <div class="content">  
  21.         <!--CONTENT-->  
  22.     </div>  
  23.     <img src="http://nettuts.s3.amazonaws.com/423_screenr/200x200.jpg" alt="" />  
  24. </div>  

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. background: #ccc url(http://nettuts.s3.amazonaws.com/423_screenr/200x200.jpg) no-repeat;  
  4. -webkit-background-size: 50%; /* Safari */  
  5. -o-background-size: 50%; /* Opera */  
  6. -khtml-background-size: 50%; /* Konqueror */  
  7. }  
  8. </style>  
  9. <div class="box">  
  10.     <!--CONTENT-->  
  11. </div>  

Unfortunately, this property isn't implemented into Firefox (V3.5.2) at the time of this writing.

View the demo.

8. Multiple Backgrounds

Multiple Backgrounds

Ah, multiple backgrounds. Now this give developers a very powerful tool. I can think of so many things that require multiple divs just to have more than one background. The most common place I can see this being helpful is in a header section of the website, but that's just the first thing I thought of.

Classic Way

  1. <style type="text/css">  
  2. .box {  
  3. width: 200px;  
  4. height: 150px;  
  5. background: url(images/bg.png) repeat-x;  
  6. }  
  7.     .box2 {  
  8.     width: 100%;  
  9.     height: 100%;  
  10.     background: url(images/text.png) center center no-repeat;  
  11.     }  
  12. </style>  
  13. <div class="box">  
  14.     <div class="box2">  
  15.         <!--CONTENT-->  
  16.     </div>  
  17. </div>  

The classic method is pretty obvious, just wrap the div with another div and so on for each background you need. Produces lovely looking code, doesn't it?

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. width: 200px;  
  4. height: 150px;  
  5. background: url(images/text.png) center center no-repeat, url(images/bg.png) repeat-x;  
  6. }  
  7. </style>  
  8. <div class="box">  
  9.     <!--CONTENT-->  
  10. </div>  

The syntax is really easy to pick up on this one. All you do for the multiple backgrounds is add a comma in between each one! However, once again, this is a limited property and is only in Safari.

View the demo.

9. Columns

Columns

This is the most interesting CSS3 property I've come by. It's not something you see a lot in web design. Myself, I've only seen newspaper-like columns once or twice; however, I love how the effect looks when done correctly. Normally you would separate the content into divs and float those divs, but I found a jQuery plugin which dynamically renders the columns.

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript" src="js/jquery.columnize.js"></script>  
  3. <script type="text/javascript">  
  4. $(function(){  
  5.     $('.columns').columnize({  
  6.         columns: 2  
  7.     });  
  8. });  
  9. </script>  
  10. <style type="text/css">  
  11. .column {  
  12. padding-right: 10px;  
  13. }  
  14. .column.last {  
  15. padding: 0;  
  16. }  
  17. </style>  
  18. <div class="columns">  
  19.     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.</p>  
  20.     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.</p>  
  21. </div>  

I've added a little padding to the columns just so the text isn't smashed up against each other.

CSS3 Way

  1. <style type="text/css">  
  2. .columns {  
  3. -moz-column-count: 2;  
  4. -webkit-column-count: 2;  
  5. }  
  6. </style>  
  7. <div class="columns">  
  8.     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.</p>  
  9.     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elementum accumsan mi. Maecenas id dui a magna tempor pretium. Quisque id enim. Proin id tortor. Curabitur sit amet enim vitae quam pharetra imperdiet. Nulla diam ante, pellentesque eu, vestibulum non, adipiscing nec, eros. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis a nunc. Donec non dui a velit pulvinar gravida. Nunc rutrum libero vel tortor. Duis sed mi eu metus tincidunt ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In purus lorem, aliquam ac, congue ac, vestibulum quis, felis. Aliquam non sapien.</p>  
  10. </div>  

There are a handful of other CSS3 column properties that you can apply, but for demonstrative purposes, I only specified the number of columns. If you'd like to learn more about these other properties, check out the multi-column page at CSS3.info.

View the demo.

10. Border Image

Border Image

I had no clue about the border image property until I upgraded to Firefox 3.5 and went to Chris Spooner's website and saw that his post images had image borders. I personally don't have any interest in this property, but that's not going to stop me from explaining how to achieve it.

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript" src="js/jquery.borderImage.js"></script>  
  3. <script type="text/javascript">  
  4. $(function(){  
  5.     $('.classic .box').borderImage('url(images/border.png) 27 27 27 27 round round');  
  6. });  
  7. </script>  
  8. <style type="text/css">  
  9. .box {  
  10. border-width: 20px;  
  11. }  
  12. </style>  
  13. <div class="box">  
  14.     <!--CONTENT-->  
  15. </div>  

Instead of spending the time creating multiple divs and repeating the background image around the div, I found a jQuery plugin that does the work for me. It's called borderImage and works just like it should.

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. border-width: 20px;  
  4. -webkit-border-image: url(images/border.png) 27 round;  
  5. -moz-border-image: url(images/border.png) 27 round;  
  6. border-image: url(images/border.png) 27 round;  
  7. }  
  8. </style>  
  9. <div class="box">  
  10.     <!--CONTENT-->  
  11. </div>  

As you can see, the border image property is a bit odd. W3 explains how it gets calculated MUCH better.

View the demo.

11. Animations

Animations

Alright, who doesn't love to see some element gently slide to the left or fade in when you hover over something? Animations are great to increase user interface, but make sure that you don't go over board! The only browsers that support CSS3 animations are Webkit based browsers. The only other way to display animations is to use JavaScript. I'll be using jQuery because it's my favorite JavaScript library (if you haven't guessed by now).

Classic Way

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  
  2. <script type="text/javascript">  
  3. $(function(){  
  4.     $('.box').hover(function(){  
  5.         $(this).stop().animate({  
  6.             top: '20px'  
  7.         }, 300);  
  8.     }, function(){  
  9.         $(this).stop().animate({  
  10.             top: '0'  
  11.         }, 300);  
  12.     });  
  13. });  
  14. </script>  
  15. <style type="text/css">  
  16. .box {  
  17. position: relative;  
  18. }  
  19. </style>  
  20. <div class="box">  
  21.     <!--CONTENT-->  
  22. </div>  

CSS3 Way

  1. <style type="text/css">  
  2. .box {  
  3. position: relative;  
  4. -webkit-transition: top 300ms linear;  
  5. }  
  6. .box:hover {  
  7. top: 20px;  
  8. }  
  9. </style>  
  10. <div class="box">  
  11.     <!--CONTENT-->  
  12. </div>  

Both of these code snippets do the same thing: slide the div 20 pixels down over the course of 300 ms. Remember, the CSS3 code only works in Webkit browsers!

View the demo.

Article from http://net.tutsplus.com/