As linked in Smashing Magazine’s article “70 Expert Ideas for Better CSS Coding“, various developers have posted source code for their baseline stylesheet at one point or the other: Christian Montoya, Eric Meyer, Ping, Mike Rundle…any others come to mind?
For posterity I’ll go ahead and post mine here as it will no doubt evolve into a different animal a year from now. In fact I’ll try to post it again in May 2008 to see what’s changed in the approach:
/*
TABLE OF CONTENTS
HTML Elements
Page Structure
Navigation
Headings
Content Area
Forms
Clear
Footer
/* ---------- @ HTML Elements -----------*/
* {
margin: 0;
padding: 0;
}
body, html {
color:#666;
background: #FFF url(/images/bg.jpg);
min-height:101%;
font-size: 100%;
}
body, form {
font-family: Arial,Verdana
}
p {
margin: 15px 0;
}
a:link, a:visited {
text-decoration:none;
color: #369;
}
a:hover, a:active {
color:#2e81d4;
text-decoration:overline
}
*:focus {
outline: none
}
/* ---------- @ Page Structure -----------*/
#wrapper {
background: url(/images/bg_wrapper.png);
margin: 0 auto;
font-size: 0.8em;
width: 860px;
}
#masthead {
background: url(/images/bg_masthead.png);
height: 146px;
}
.left {
float:left;
}
.right {
float:right
}
/* ---------- @ Navigation -----------*/
#nav li {
list-style:none;
}
#nav a {
display:block;
width: 122px;
height: 16px;
text-indent: -9000px;
}
a#foo {
background:url(/images/nav_foo.gif);
}
a#foo:hover {
background:url(/images/nav_foo_on.gif);
}
/* ---------- @ Headings -----------*/
h1, #logo {
width: 150px;
background: url(/images/logo.png);
height: 146px;
text-indent:-9000px;
font-size: 1.8em
}
h2 {
font-size: 1.6em
}
h3 {
font-size: 1.4em
}
h4 {
font-size: 1.2em
}
/* ---------- @ Content Area -----------*/
/*Home*/
#content {
}
#sidebar {
}
/*Interior Pages*/
.bullets {
padding:15px 15px 15px 30px;
}
.bullets li {
background:url(/images/bullet.gif) no-repeat;
list-style:none;
padding-left: 11px;
margin-bottom: 5px;
}
/* ---------- @ Forms -----------*/
.button {
background: #000 ! important;
border:#F7ECD4 1px solid;
padding: 2px;
margin: 0 2px 0 0;
color:#FFF;
}
.button:focus {
padding:2px;
background: #000 ! important;
}
.button:hover {
background: #CCC ! important;
color: #000;
}
/*Clear*/
.clearfloat:after {
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfloat {
display: inline-block;
}
/* Hides from IE-mac \*/
* html .clearfloat {
height:1%;
}
*+html .clearfloat {
height:1%;
}
.clearfloat {
display:block;
}
/* End hide from IE-mac */
/* ---------- @ Footer -----------*/
#footer {
padding: 20px;
color:#7f99b3;
}
Download the whole thing here.
Notes:
- A Table of Contents always becomes more useful as the stylesheet grows.
- “Hooks” are added to each section in the form of an @ symbol. This is so code editors can CTRL+F (Search) for the @ symbol in order to more easily skip through sections of the stylesheet.
- Global styles are reset with an asterisk (*) to adjust for padding and margin properties which some browsers do not agree on.
- Font-size in the <body> is initially set to 100% for the same reason.
- A min-height property is added to the <body> to adjust for Firefox’s jarring habit of adding/removing a scrollbar depending a page’s height.
- Font styles are specified in both <body> and <form> tags since text fields in some browsers ignore font styles.
- Margins are specified for the <p> tag to adjust for browser inconsistency.
- The global psuedo-class :focus is set to “outline:none” because the dots it creates are obtrusive in some browsers.
- Relative to the initial 100% size, font-size is re-established for the entire wrapper in <em>s to allow users to scale text up and down.
- Classes .left and .right are created to enable basic floats, and are meant to be combined with other classes (ex: “<div class=”left sidebar”>foo</div><div class=”right content”>foo</div>
- Generic navigation elements are created within an unordered list called #nav with the assumption that list items will use image-backgrounds. The text-indent property is “-9000px” so text does not float over the images.
- The h1 tag shares the same properties as the #logo ID because the logo on the interior pages will also serve as a link back to Home.
- A class of .bullets is created for traditional bulleted lists. Padding and margins are set to display universally among browsers.
- A class of .button is created for use in forms. The use of “!important” is to maintain browser consistency when the button is pressed.
- Float clearing specs are courtesy of PiE.
Pingback: Presseschau für Webentwickler - Ausgabe Juli 2007 | Dr. Web Weblog
Pingback: Best of May/June 2007
Pingback: Best of May/June 2007 | Webdesign (css, grafica e altro)
Pingback: lost node » Blog Archive » Best of May/June 2007
Pingback: Cyber Space in One Hand » Blog Archive » Useful references, tutorials, services, tools, techniques and articles by smashingmagazine
Pingback: Mark Kirby - Brighton » Blog Archive » links for 2007-07-10
Pingback: Best of May/June 2007 · Style Grind
Pingback: Best of May/June 2007 at Design Resources
Pingback: CSS Frameworks + CSS Reset: Design From Scratch | CSS
Pingback: CSS Frameworks + CSS Reset: Design From Scratch .
Pingback: Obez Blog » CSS Frameworks + CSS Reset: Design From Scratch
Pingback: » CSS Frameworks + CSS Reset: Design From Scratch
Pingback: Darren Hoyt Dot Com » The Fuss Over Grids and CSS Frameworks
Pingback: CSS Frameworks + CSS Reset: Design From Scratch » » Google Adsense News
Pingback: CSS Concept » Frameworks & CSS Reset
Pingback: » Frameworks CSS + Reset CSS : design from scratch « css4design : des css pour votre design html
Pingback: provoke.pl » Blog Archive » CSS Frameworks + CSS Reset: Design From Scratch
Pingback: CSS Frameworks? - HackSystems