Home > Resources > Web Development > Web Tips > CSS 3


Tutorials and examples

http://w3schools.com/css3/ - interactive examples

New features

Colors (hex, rgb, hsl, rgba, hsla - rgb values are 0-255; a is alpha for opacity/transparency)
Opacity (0.0 is transparent, 1.0 is opaque, 0.5 is semi-transparent)
Backgrounds (size, origin, clip)
Gradients (horizontal, vertical, diagonal, or gradient; multiple stops)
http://css-tricks.com/css3-gradients/ - technical overview; gradient images no longer needed
http://gradients.glrzad.com/ - simple gradient generator
http://www.colorzilla.com/gradient-editor/ - another gradient generator
Borders (border-radius gives round corners; borders can use images)
Box (box-sizing: border-box; puts padding and border inside the box - good for liquid layouts)
Shadows (text, box)
Text (overflow, word-wrap)
Transforms (translate, rotate, scale, skew, matrix)
Transitions (property, duration, timing function, delay)
Animations (keyframes, properties) - instead of animated images, Flash or JavaScript

Vendor-specific prefixes

Different browsers use vendor-specific prefixes to extend CSS with their own properties.
-webkit- is used by Apple Safari, Google Chrome, and Dreamweaver CS 5.5.
-moz- is used by Mozilla Firefox.
-o- is used by Opera.
-ms- and filter are used by Microsoft Internet Explorer.
Newer browsers use the standard properties, so put them last, after vendor-specific properties.

Microsoft visual filters

http://rainbow.arch.scriptmania.com/css/ie_filters_generator.html - demo (limited options)
http://msdn.microsoft.com/en-us/library/ms532853(v=vs.85).aspx - full documentation


Easily generate cross-platform CSS3 code from a GUI and copy into your stylesheet


Different browsers use different defaults for font size, padding, margins, borders, line height, etc.
Use CSS resets to override browser defaults and render a page consistently in all browsers.
Use reset files for XHTML and HTML 5 that others have developed and tested.
Dreamweaver CS5.5 HTML 5 templates seem to do much of this work.

Conditional stylesheets for Internet Explorer

To handle Internet Explorer versions, you can create one or more separate stylesheets.
This separates IE-only CSS from other browsers and makes validation easier.
Avoid using CSS filters that use hacks to detect browsers, but know it is a last-resort option.

New selectors

A CSS selector determines which elements should have style rules applied to them.
CSS3 selectors add to the already powerful selectors in CSS2. Just a few examples:
Attribute selectors are especially useful to select and format links based on their href.
[attribute^=value] - begins with, [attribute$=value] - ends with, [attribute*=value] - contains
a[href$=".pdf"] { padding-right: 20px; background: url(pdf.png) center right no-repeat; }
:nth-of-type(n) and :nth-child(n) - select the nth, first, last or only element; useful for coloring alternate rows differently, creating rows and columns, and creating borders on navigation
tr:nth-child(even) { background-color: #eee; }
:enabled, :disabled, :checked - select form input elements based on their state

@font-face Web fonts

http://www.slideshare.net/RZasadzinski/web-font-services-march-2011 - overview presentation
For cross-browser compatibility, developers used to be limited to a small number of fonts.
Internet Explorer has long supported web fonts, but now other browsers can also display them.
You can either download fonts, or link directly to online font services, free or commercial.
http://www.google.com/webfonts - easiest to use but limited font selection
http://www.fontsquirrel.com/fontface - download many free OTF or TTF fonts
http://www.webfonts.info/ - free and commercial web fonts
http://www.typekit.com/ - commercial web fonts

CSS frameworks, preprocessors and generators

CSS frameworks can automatically generate vendor prefixes.
They have other features that programmers like, such as variables, mixins (classes for classes), nested rules, math operations within CSS, color functions, and JavaScript evaluation.
The JavaScript can decrease performance, so it is also possible to generate CSS code, but this must be regenerated every time the source file is changed.
This can be automated, depending on the server and development platform used.
http://lesscss.org/ - easy to start using; just download a JavaScript file and add a script tag for it
http://sass-lang.com/ - requires the Ruby programming language which is available on all Macs
http://compass-style.org/ - uses Sass for CSS3, typography, styling tools, page layout and resets

JavaScript libraries for improved HTML5 and CSS3 compatibility

http://modernizr.com/ - supports HTML5 and CSS3; generate code for only needed features
http://selectivizr.com/ and http://css3pie.com/ - CSS3 support for Internet Explorer 6-9
http://headjs.com/ - improve browser support and performance of HTML5, CSS3 and JavaScript

CSS template systems

Develop complex CSS grid layouts and templates more quickly with one of these frameworks.
http://960.gs/ - popular and easy to use CSS grid layout, used by ACNS and RamCT Help sites
http://blueprintcss.org/ - CSS framework that includes grid, typography and print
http://yuilibrary.com/yui/docs/cssgrids/ - layout used by the CSU Libraries Discovery tool
http://jqueryui.com/ - includes a CSS framework to build custom jQuery widgets
http://html5reset.org/ - a set of starting tools (CSS resets, jQuery, Analytics, modernizer, etc.)