Cross-Browser CSS Gradient

Very handy CSS for creating cross-browser gradient effects. Really useful in reducing number of images calls / sprite size.

background: #dde9f5; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=’#ffffff’, endColorstr=’#dae6f4′); /* for IE */

background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#dae6f4)); /* for webkit browsers */
background: -moz-linear-gradient(top, #ffffff, #dae6f4); /* for firefox 3.6+ */


CSS Rendering Priority and Inheritance

Styles are read in three ways: browser default (blue links etc), style sheets (internal in the <head> or external via @import or <link>) and inline styles. Here is the simulated default priority order, where no.4 as most important:

  1. Browser default
  2. External style sheet
  3. Internal style sheet
  4. Inline style

Let me try to explain how this works. If two rules have the same weight, the latter wins.

Now, let’s make a general list of the internal priorities for CSS (3 has the highest priority):

  1. element
  2. .class
  3. #id

This is the default priority order. In addition to this, specificity will also count, f.ex ul li will override li. W3C has made a decent table over how you should calculate internal weight:

LI            {...}  /* a=0 b=0 c=1 -> specificity =   1 */
UL LI         {...}  /* a=0 b=0 c=2 -> specificity =   2 */
UL OL LI      {...}  /* a=0 b=0 c=3 -> specificity =   3 */        {...}  /* a=0 b=1 c=1 -> specificity =  11 */
UL OL  {...}  /* a=0 b=1 c=3 -> specificity =  13 */
#list         {...}  /* a=1 b=0 c=0 -> specificity = 100 */
  • a represents the number of #id attributes in the selector
  • b represents the number of class attributes
  • c represents the number of tag names

more detailed information available here …

6 Keys to Understanding Modern CSS-based Layouts

Much of CSS is pretty straightforward and, I suspect, quite easy for most people to grasp. There’s font styles, margin, padding, color and what not. But there’s a wall that people will run into… that point where a number of key elements need to come together to create a solid CSS-based layout that is consistent cross-browser.

These are the six things that will help people get over the hump.

Box Model

Floated Columns

Sizing Using Ems

Image Replacement

Floated Navigation