<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MacTheWeb &#187; CSS</title>
	<atom:link href="http://mactheweb.com/archives/catagories/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://mactheweb.com</link>
	<description>Mac and the Web - Perfect</description>
	<lastBuildDate>Mon, 15 Dec 2008 22:45:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting page type styles</title>
		<link>http://mactheweb.com/tips/setting-page-type-styles/</link>
		<comments>http://mactheweb.com/tips/setting-page-type-styles/#comments</comments>
		<pubDate>Thu, 08 Feb 2007 07:21:27 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://mactheweb.com/tips/setting-page-type-styles/</guid>
		<description><![CDATA[*/ * { margin: 0; padding: 0; } /* This sets the default margin and padding of all page elements to 0 giving nice control over every page element.

....1em 0 .7em 0; /* top margin very small , left and right margins 0, bottom margin a little less than browser default */ } li, li li, li li li, { font-size: 1.2em; line-height: 1em; margin-bottom: .5em } /* All the li selectors are included to keep list elements from becoming progressively smaller as they are nested.

...} /*Ordered lists need just a bit more margin */ blockquote { margin-left: 2.2em; padding: .2em; background: #efefef; border-left: 1px dotted #ccc; } /* First, the left margin.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>It took me years to realize how much time I would save by setting up a default 	type styles sheet for my web design work. It wasn&#8217;t until I read an introduction 	to Ruby on Rails in 2005 that I got the whack on the side of my head that 	woke me up. The concept that broke through my time wasting behavior was DRY. 	Yes, technical writing is usually dry, but in this case it is an acronym for <strong>d</strong>on&#8217;t <strong>r</strong>epeat 	<strong>y</strong>ourself.</p>
<p>Obvious, you say; and you&#8217;re absolutely right. Perhaps it was simple laziness 	that stopped me from seeing the light. It doesn&#8217;t matter. I finally realized 	that it was time to write out some the common CSS selectors and some standard 	values. Now at least I am being smart lazy buy using a standard type styles 	sheet instead of stupid lazy by needing to recreate the same content over 	and over.</p>
<p>What follows is my default CSS style for HTML with many and probably excessive 	comments. Most of the less than obvious additions are intended to handle Internet 	Explorer&#8217;s (IE) less that stellar handling of CSS. I won&#8217;t include any outright 	hacks but you will definately see some kludges, starting with html.</p>
<p><!-- technorati tags start --></p>
<p style="text-align: right; font-size: 10px">Technorati Tags: <a rel="tag" href="http://www.technorati.com/tag/puppy">puppy</a></p>
<p><!-- technorati tags end --><br />
<span id="more-223"></span></p>
<p><strong>html {<br />
font-size: 100%<br />
}</strong> /* this may not be necessary anymore but it handles an old IE problem 	with displaying combinations of percent and em sized fonts correctly. */</p>
<p><strong>* {<br />
margin: 0; padding: 0;<br />
}</strong> /* This sets the default margin and padding of all page elements to 0 giving nice control over every page element. I can eliminate a lot of head scratching when trying to figure out why things don&#8217;t line up. Zero it all and start from scratch. */</p>
<p><strong>body {<br />
color: #333;<br />
</strong>/* Dark gray text against a white background. It&#8217;s readable without 	the starkness of pure black on white. Chances are this will be different on 	every site but this starts us out. These are the shorthand color notations. 	*/<br />
<strong> 	background: #fff;<br />
font-size: 62.5%;<br />
}</strong> /*<a href="http://www.clagnut.com/blog/348/">This is a clever idea 	that sets the basic font size in modern browsers</a>	to something approximating 10 pixels. From now on all font measurements will 	be specified in em&#8217;s, a relative measurement that equals the size of a capital 	M. All page elements (almost) should now be 1em and will need to be individually 	specified. This allows us to over-ride the default browser style sheet and 	replace it with our own. */</p>
<p><strong>th, td {<br />
font-size: 1.2em;<br />
}</strong> /* Another IE kludge. It doesn&#8217;t inheret font sizes from the body 	as it should. Ideally you would include all text within table cells in a p 	tag. Practically, I forget sometimes, especially when I&#8217;m populating a table 	dynamically. */</p>
<p><strong>th {<br />
font-weight: bold;<br />
text-align: center;<br />
}</strong> /* This is probably redundant but explicitly setting all values is what 	this style sheet is about */</p>
<p><strong>h1, h2, h3, h4, h5 {<br />
font-weight: bold;<br />
font-family: Georgia, Times, serif;<br />
</strong>	/* Obviously this is arbitrary but if I put it in to start with I won&#8217;t forget to set the font family. Change to 	suit. A shorthand version would be font : bold georgia, times, serif;*/<br />
<strong>margin: .1em 0 .5em 0;</strong><br />
/* a tiny top margin and a smaller bottom margin than default. 0 margins for left and right *<strong>}</strong></p>
<p><strong>h1 { font-size: 2.4 em; }</strong> /* Twice the size we&#8217;ll use for paragraphs. Remember 	that all font sizes have been reset to about 10 px. This makes the h1 element 	about 24 pixels large. */</p>
<p><strong>h2 { font-size: 2em; }</strong></p>
<p><strong>h3 { font-size: 1.7em; }</strong></p>
<p><strong>h4 { font-size: 1.4em; }</strong></p>
<p><strong>h5 {font-size: 1.2em; }  </strong></p>
<p><strong>p {<br />
font-size:1.2em</strong><br />
/* This makes the default font 	size about 12 pixels, which is a good compromise between compactness and readability<br />
<strong>font-family: verdana, helvetica, sans-serif;</strong><br />
/* Again, this is arbitrary, but sans-serif fonts tend to be easier to read on screen than serif ones. It also stands out nicely against the serif Georgia */<br />
<strong>line-height: 1.5em;</strong><br />
/ * to create some breathing space between lines in print design this is called leading. 1.4em is also nice. */<br />
<strong>margin:	.1em 0 .7em 0;</strong><br />
/* top margin very small , left and right margins 0, bottom margin a little less than browser default */<br />
}</p>
<p><strong>li, li li, li li li, {<br />
font-size: 1.2em;<br />
line-height: 1em;<br />
margin-bottom: .5em }</strong> /* All the li selectors are included to keep list elements from becoming progressively smaller as they are nested. That&#8217;s a gotcha when using relative sizes for font display. Three levels are all that you would practically encounter and I didn&#8217;t use the li * selector because I sometimes include other HTML inside of lists */</p>
<p><strong>ul {<br />
margin-left: 1.8em;<br />
}</strong> /* Remember that we zeroed out all margins and have to specify them for each element. This is a good average value */</p>
<p><strong>ol {<br />
margin-left: 2.1em;<br />
}</strong> /*Ordered lists need just a bit more margin */</p>
<p><strong>blockquote {<br />
margin-left: 2.2em;<br />
padding: .2em;<br />
background: #efefef;<br />
border-left: 1px dotted #ccc;<br />
}</strong> /* First, the left margin. That&#8217;s all that&#8217;s really needed here. The other selectors are one common way to set blockquotes off from the rest of the text. This gives them a very slight background color and left dotted border. Obviously this is a great place to set your own styles. Again, I include a default to so I don&#8217;t forget. */</p>
<p><strong>dl {<br />
font-size: 1.2em;<br />
}</strong> /* New element. Need to set font size */</p>
<p><strong>dt {<br />
font-weight: bold;<br />
margin-bottom: .4em;<br />
}</strong> /* I like definition terms to stand out, hence the bold font-weight. The bottom margin is to separate the term from its definition.(The dt margin is not additive with the top dd margin. It will be .4em not .6em) */</p>
<p><strong>dd {<br />
margin: .2em .5em .4em 2em;<br />
line-height: 1.3em;<br />
}</strong> /* just setting the breathing space around the definitions */</p>
<p><strong>input, select {<br />
font-size: 1em;<br />
}</strong> /* This is my personal preference. Your milage may vary */</p>
<p><strong>label {<br />
font-size: 1.2em;<br />
}<br />
</strong>/* You are using labels for your form elements, aren&#8217;t you? */</p>
<p><strong>hr {<br />
margin: .2em .1em .6em;<br />
}</strong><br />
/* Just a little breathing room for the horizontal rule */</p>
<p><strong>cite {<br />
font-style: italic;<br />
}</strong><br />
/* Probably redundant. Here for completeness */</p>
<p><strong><abbr title="abbreviation">abbr</abbr>, acronym, <span title="mommas little helper" class="help">.help</span> {<br />
border-bottom: 1px dotted #333; cursor: help;<br />
}<br />
</strong>/* A little touch that sets acronyms and abbreviations a little dotted underline and possibly a tool tip. I&#8217;ve added the class help for times when I want to define something. is used in conjunction with the TITLE attribute on an ABBR or ACRONYM tag, or a SPAN with class=&#8221;help&#8221;, to create an underline effect that is different from the hyperlink underline. Changing the cursor to &#8220;help&#8221; implies that the word is not clickable, and the TITLE attribute expands the abbreviation or acronym.*/</p>
<p><strong>img {<br />
border: 0;<br />
}</strong><br />
/* Older browsers will place a border, in your link color, around a linked image. Just say no. */</p>
<p><strong>a:link {<br />
color: #036;<br />
text-decoration: underline;<br />
}</strong></p>
<p><strong>a:visited {<br />
color: #603;<br />
text-decoration: underline;<br />
}</strong></p>
<p><strong>a:hover {<br />
color: #900;<br />
text-decoration: underline;<br />
}</strong></p>
<p><strong>a:active {<br />
color: #c66;<br />
text-decoration: underline;<br />
}</strong><br />
/* These link attributes will almost always end up being changed. If they are here I&#8217;ll always know where to find them. BTW use them in this order. Having everything in the same place every time makes things simple. I guess the complete instruction would be KISS; DRY. (keep things simple stupid; don&#8217;t repeat yourself) */</p>
<p>/* This concludes the default HTML section. Not that many elements, are there? 	Below are selectors and classes that I usually throw in for completeness. 	*/</p>
<p><strong>.imageleft {<br />
float: left;<br />
margin: 2px 4px;<br />
} </strong></p>
<p><strong>.imageright {<br />
float: right;<br />
margin: 2px 4px;<br />
}<br />
</strong>/* With strict XHTML we aren&#8217;t supposed to use the 	img align attribute. Creating a couple if classes that float the images left or right lets us achieve the same effect and validate. The margin setting replaces v-space and h-space. These classes are only used for image placed in the document flow, not design elements, so I will assume they need the space. */</p>
<p><strong>.floatleft {<br />
float: left;<br />
width: 200px;<br />
padding: 5px;<br />
border: 1px solid #ccc;<br />
text-align:	center;<br />
} </strong></p>
<p><strong>.floatright {<br />
float: rigcht;<br />
width: 200px;<br />
padding: 5px;<br />
text-align: center;<br />
}</strong><br />
/* What&#8217;s the difference between these and the .imageleft/right classes? These floats are intended for callouts or images with captions. Notice the explicit width, border, text centering and padding. The widths and borders are arbitrary and will be adjusted for each layout, or not. They are there. */</p>
<p><strong>.clearing {<br />
clear: both;<br />
height: .1%<br />
}</strong><br />
/* Once we start using floats or even right and left aligned images it becomes useful to be able to clear text below the floats or images. Depending on your layout you may also or need to use clear-left or clear-right. */</p>
<p><strong>td { padding: 3px; }</strong><br />
/* Again, this is using CSS to replace a depreciated  attribute, in this case 		cellpadding. If you want cellspacing use margin instead of padding, or 		both if you want both. I&#8217;m assuming here that you are only using tables 		for data. If you&#8217;re still laying out your site with tables, obviously you 		would want to set margin: 0; padding 0; for table, th and td. This should 		inherit from the body * selector, but isn&#8217;t reliable in all versions of 		IE. It&#8217;s also usually best to give each table a unique id or at least a 		class for setting width in CSS instead of HTML. */</p>
<p><strong>.red {<br />
color: red;<br />
}</strong></p>
<p><strong>.green {<br />
color: green;<br />
}<br />
</strong></p>
<p><strong>.smaller {<br />
font-size: smaller;<br />
} </strong></p>
<p><strong>.larger {<br />
font-size: larger;<br />
}</strong><br />
/* It is often useful to have a couple, or more, font sizes and colors pre-defined. 	Some people use .warning or .caution for the .red class and .success 	for .green. It is supposed to be express the meaning in the code. Whatever. Colors for warnings should be supplemental information, not something you rely on.<br />
With a good friend who is an avid web user and who is quite 	color blind, I&#8217;ve learned to not rely on color for warnings. Color is good information for most of us but shouldn&#8217;t be the only indicator of problems. But still 	colors can be helpful supplements, or just fun. We all know that red shoes make us run faster, don&#8217;t we? My boss&#8217; 10 year old daughter told me that recently. It&#8217;s  helpful to define a couple of 	color classes that compliment your design and include them in the style sheet.</p>
<p>I have set up content management systems for a number of client, and have clients 	who use Adobe&#8217;s Contribute. With a little extra work I can disable all their 	font size and color changing ability and only leave them with <em>my choices</em> of 	color and size. Never trust a client&#8217;s good taste or sense. Give them a couple 	of customization choices and they will normally be happy and won&#8217;t cry for 	more control.</p>
<p>/* ************************* */</p>
<p>That&#8217;s pretty much it for text display. CSS layout is another subject, as 	is CSS for forms. Fortunately the parts are additive. Start with text display. 	Customize your own text stylesheet and save hours on upcoming projects. And 	having a pre-defined stylesheet will help insure that you don&#8217;t forget something 	that will need fixing later.</p>
<p>I&#8217;m using <a href="http://www.google.com/url?sa=t&#038;ct=res&#038;cd=1&#038;url=http%3A//developer.yahoo.com/yui/grids/&#038;ei=anjKRaKHBZf-gwOxjeSYDA&#038;usg=__PfTin3k6vrQbtcwcu6SzwL5fy7c=&#038;sig2=6wo5l4vPzkhfdr-gxUPakg">Yahoo&#8217;s 		Grids for my basic CSS layout</a>. Their system is a little verbose but seems 		pretty <a href="http://www.simplebits.com/publications/bulletproof/">bulletproof</a>. The Grid templates will give you a solid page layout 		but you will still need to style them. That could take some hours the first 		time out. Still, it seems the best generic CSS implementation around. You 		might want to check that out.</p>
]]></content:encoded>
			<wfw:commentRss>http://mactheweb.com/tips/setting-page-type-styles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
