<?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>Garrick Cheung &#187; best practice</title>
	<atom:link href="http://www.garrickcheung.com/tag/best-practice/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.garrickcheung.com</link>
	<description>Sharing what I know and learn about CSS, MooTools, Javascript, PHP and etc.</description>
	<lastBuildDate>Fri, 30 Sep 2011 05:16:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>CSS Best Practice #3: Clear Floated Containers (with Height&#124;&#124;Width and Overflow)</title>
		<link>http://www.garrickcheung.com/css/css-best-practice-3-clear-floated-containers-with-heightwidth-and-overflow/</link>
		<comments>http://www.garrickcheung.com/css/css-best-practice-3-clear-floated-containers-with-heightwidth-and-overflow/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 01:00:21 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML / XHTML]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[clear float]]></category>
		<category><![CDATA[hasLayout]]></category>
		<category><![CDATA[overflow]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=217</guid>
		<description><![CDATA[I know you&#8217;ve done it before. I think we&#8217;ve all done it. You have a container with a floated element inside. The container doesn&#8217;t wrap around everything, thus causing the element to break outside of the container. To fix this, we&#8217;d usually add a clear element at the bottom of the container so it would [...]]]></description>
			<content:encoded><![CDATA[<p>I know you&#8217;ve done it before. I think we&#8217;ve all done it. You have a container with a floated element inside. The container doesn&#8217;t wrap around everything, thus causing the element to break outside of the container. To fix this, we&#8217;d usually add a clear element at the bottom of the container so it would wrap everything within. But there is a better solution, which uses two CSS properties. For this example, I&#8217;ll place the styles inline.. please don&#8217;t hate me.<span id="more-217"></span></p>
<p><strong>If you want to just get to the <a href="#solution">better solution&#8230;</a></strong></p>
<h3>The Example</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;container&quot; style=&quot;border:1px solid #000;&quot;&gt;
    &lt;img src=&quot;something.gif&quot; height=&quot;50&quot; width=&quot;50&quot; alt=&quot;Alt img txt&quot; style=&quot;background:green; float:left;&quot; /&gt;
    &lt;p style=&quot;margin:0;&quot;&gt;Text inside the container div.&lt;/p&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>Proceeding with the example, div.clear is placed at the bottom of div.container, which solves the problem. Div.container&#8217;s border now wraps all the elements within.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;container&quot; style=&quot;border:1px solid #000;&quot;&gt;
    &lt;img src=&quot;something.gif&quot; height=&quot;50&quot; width=&quot;50&quot; alt=&quot;Alt img txt&quot; style=&quot;background:green; float:left;&quot; /&gt;
    &lt;p style=&quot;margin:0;&quot;&gt;Text inside the container div.&lt;/p&gt;
    &lt;div class=&quot;clear&quot; style=&quot;clear:both;&quot;&gt;&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3><a name="solution"></a>The Better Solution</h3>
<p>But why should we even bother placing an extra element? It&#8217;s not sexy. Here&#8217;s the solution: Use height:1% or width:100% and overflow:auto||hidden on div.container. Height and width on div.container would set the hasLayout property in IE, thus fixing a slew of float/box-model bugs (<a href="http://www.satzansatz.de/cssd/onhavinglayout.html" target="_blank">more on hasLayout</a>). Overflow auto or hidden tells div.container to wrap everything within it.</p>
<p><strong>Note:</strong> This won&#8217;t work if the element is floated, which would cause it to shrink to the percentage height or width.</p>
<p>The HTML</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;container&quot; style=&quot;border:1px solid #000;&quot;&gt;
    &lt;img src=&quot;something.gif&quot; height=&quot;50&quot; width=&quot;50&quot; alt=&quot;Alt img txt&quot; style=&quot;background:green; float:left;&quot; /&gt;
    &lt;p style=&quot;margin:0;&quot;&gt;Text inside the container div.&lt;/p&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>The CSS</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.container</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/css/css-best-practice-3-clear-floated-containers-with-heightwidth-and-overflow/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>CSS Best Practice #2: Shorthand Properties</title>
		<link>http://www.garrickcheung.com/css/css-best-practice-2-shorthand-properties/</link>
		<comments>http://www.garrickcheung.com/css/css-best-practice-2-shorthand-properties/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 19:00:30 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[short hand]]></category>
		<category><![CDATA[shorthand]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=210</guid>
		<description><![CDATA[Write your CSS rules with shorthand properties. It keeps things simple and clean. 1 2 3 4 5 6 7 8 9 10 .example &#123; /* long */ padding-top:1px; padding-right:2px; padding-bottom:3px; padding-left:4px; &#160; /* short */ padding:1px 2px 3px 4px; &#125; To help you with the shorthand, Dustin Diaz took the time to put together [...]]]></description>
			<content:encoded><![CDATA[<p>Write your CSS rules with shorthand properties. It keeps things simple and clean.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.example</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* long */</span>
    <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* short */</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">2px</span> <span style="color: #933;">3px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>To help you with the shorthand, Dustin Diaz took the time to put together a <a href="http://www.dustindiaz.com/css-shorthand/" target="_blank">CSS shorthand guide</a>. Way to go Dustin! Check the guide for in-depth descriptions, examples, and Dustins &#8220;quirky facts&#8221; (such as shorthand defaults).</p>
<p><a href="http://reference.sitepoint.com/css" target="_blank">SitePoint CSS Reference</a> is another source for shorthand properties, or any property in general, you should/could/would use.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/css/css-best-practice-2-shorthand-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Best Practice #1: Reset CSS</title>
		<link>http://www.garrickcheung.com/css/css-best-practice-1-reset-css/</link>
		<comments>http://www.garrickcheung.com/css/css-best-practice-1-reset-css/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 13:01:25 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[reset css]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=193</guid>
		<description><![CDATA[I think resetting browser styles is important. You&#8217;ll never know what you&#8217;re dealing with. If all the browsers start on the same page it will make your life easier because you&#8217;ll know what to expect. I personally use Eric Meyer&#8217;s Reset CSS as a base and modify it as needed. 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>I think resetting browser styles is important. You&#8217;ll never know what you&#8217;re dealing with. If all the browsers start on the same page it will make your life easier because you&#8217;ll know what to expect. I personally use <a href="http://meyerweb.com/eric/tools/css/reset/" target="_blank">Eric Meyer&#8217;s Reset CSS</a> as a base and modify it as needed.<span id="more-193"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* v1.0 | 20080212 */</span>
&nbsp;
html<span style="color: #00AA00;">,</span> body<span style="color: #00AA00;">,</span> div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> applet<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> iframe<span style="color: #00AA00;">,</span>
h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> pre<span style="color: #00AA00;">,</span>
a<span style="color: #00AA00;">,</span> abbr<span style="color: #00AA00;">,</span> acronym<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> big<span style="color: #00AA00;">,</span> cite<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span>
del<span style="color: #00AA00;">,</span> dfn<span style="color: #00AA00;">,</span> em<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span> ins<span style="color: #00AA00;">,</span> kbd<span style="color: #00AA00;">,</span> q<span style="color: #00AA00;">,</span> s<span style="color: #00AA00;">,</span> samp<span style="color: #00AA00;">,</span>
small<span style="color: #00AA00;">,</span> strike<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> sub<span style="color: #00AA00;">,</span> sup<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> var<span style="color: #00AA00;">,</span>
b<span style="color: #00AA00;">,</span> u<span style="color: #00AA00;">,</span> i<span style="color: #00AA00;">,</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span>
dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span>
fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> legend<span style="color: #00AA00;">,</span>
table<span style="color: #00AA00;">,</span> caption<span style="color: #00AA00;">,</span> tbody<span style="color: #00AA00;">,</span> tfoot<span style="color: #00AA00;">,</span> thead<span style="color: #00AA00;">,</span> tr<span style="color: #00AA00;">,</span> th<span style="color: #00AA00;">,</span> td <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">baseline</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ol<span style="color: #00AA00;">,</span> ul <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
blockquote<span style="color: #00AA00;">,</span> q <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">quotes</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
blockquote<span style="color: #3333ff;">:before</span><span style="color: #00AA00;">,</span> blockquote<span style="color: #3333ff;">:after</span><span style="color: #00AA00;">,</span>
q<span style="color: #3333ff;">:before</span><span style="color: #00AA00;">,</span> q<span style="color: #3333ff;">:after </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">''</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* remember to define focus styles! */</span>
<span style="color: #3333ff;">:focus </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* remember to highlight inserts somehow! */</span>
ins <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
del <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">line-through</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* tables still need 'cellspacing=&quot;0&quot;' in the markup */</span>
table <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Other Resets</h3>
<p>There are actually a lot more choices besides Eric Meyers. I found several more at a <a href="http://www.pinceladasdaweb.com.br/blog/2008/11/10/10-tecnicas-para-reset-css/" target="_blank">post on Pinceladas da Web</a>. It is in Portuguese so you may need to translate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/css/css-best-practice-1-reset-css/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS Best Practices: Index</title>
		<link>http://www.garrickcheung.com/css/css-best-practices-index/</link>
		<comments>http://www.garrickcheung.com/css/css-best-practices-index/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 13:00:52 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[best practice]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=160</guid>
		<description><![CDATA[I&#8217;ve decided to create an index of all the CSS best practices in this post that will be updated when I add a new best practice. It should be easier for you to keep track of everything. Please bear with me while I get things together. CSS Best Practices Posts: Reset CSS CSS Best Practice [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to create an index of all the CSS best practices in this post that will be updated when I add a new best practice. It should be easier for you to keep track of everything. Please bear with me while I get things together.<span id="more-160"></span></p>
<h3>CSS Best Practices Posts:</h3>
<ol>
<li><a href="http://www.garrickcheung.com/css/css-best-practice-1-reset-css/">Reset CSS</a></li>
<li><a href="http://www.garrickcheung.com/css/css-best-practice-2-shorthand-properties/">CSS Best Practice #2: Shorthand Properties</a></li>
<li><a href="http://www.garrickcheung.com/css/css-best-practice-3-clear-floated-containers-with-heightwidth-and-overflow/"><br />
CSS Best Practice #3: Clear Floated Containers (with Height||Width and Overflow)</a></li>
<li><a href="http://www.garrickcheung.com/css/css-best-practice-4-understand-selector-specificity-for-better-speed-and-easier-override/">CSS Best Practice #4: Understand Selector Specificity for Better Speed and Easier Override</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/css/css-best-practices-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

