<?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>Kashit &#187; IE Conditional</title>
	<atom:link href="http://www.kashit.org/words/ie-conditional/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kashit.org</link>
	<description>home to Ehsan Quddusi</description>
	<lastBuildDate>Sun, 28 Feb 2010 18:43:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS Best Practices</title>
		<link>http://www.kashit.org/design/css-best-practices/</link>
		<comments>http://www.kashit.org/design/css-best-practices/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 09:40:18 +0000</pubDate>
		<dc:creator>Ehsan Quddusi</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[browser reset]]></category>
		<category><![CDATA[CSS Best Practices]]></category>
		<category><![CDATA[css hacks]]></category>
		<category><![CDATA[IE Conditional]]></category>
		<category><![CDATA[shorthand css]]></category>

		<guid isPermaLink="false">http://new.kashit.org/?p=48</guid>
		<description><![CDATA[<span class="dropcap">C</span>SS Best Practices is the topic that I had been planning to write on for months. As CSS is the order of the day as far as web related UI is concerned, more people are moving to it. CSS isn't always easy to deal with. CSS coding can sometimes become a nightmare, particularly if you're not sure which selectors are applied to document elements. CSS Best Practices covers some important and easy to remember tricks and tips to better manage, organise and develop your CSS Snippets.]]></description>
			<content:encoded><![CDATA[<p><span class="dropcap">C</span>SS Best Practices is the topic that I had been planning to write on for months. As CSS is the order of the day as far as web related UI is concerned, more people are moving to it. CSS isn&#8217;t always easy to deal with. CSS coding can sometimes become a nightmare, particularly if you&#8217;re not sure which selectors are applied to document elements. CSS Best Practices covers some important and easy to remember tricks and tips to better manage, organise and develop your CSS Snippets.</p>
<h4>Use a browser reset</h4>
<p>One of the most common mistakes that designers fall victim to when it comes to CSS is not resetting their browser defaults. This leads to inconsistencies in the appearance of your desing across different browsers. So before doing anything else, when coding a website, you should reset the styling. You can use a simple reset with the universal selector like this<br />
<code><br />
* { margin:0;padding:0;}<br />
</code><br />
But using the universal selector is sometimes a bad idea as it is very heavy on the rendering agent to apply rules to every single element in the document.</p>
<p>One of the most popular browser resets is of <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/" target="_blank">CSS Reset</a> by Eric Meyer. As Meyer says, “the styles should list all the actual elements to be reset and exactly how they should be reset.”</p>
<p>Another Browser Reset Library is Yahoo! UI Library: <a href="http://developer.yahoo.com/yui/reset/" target="_blank">Reset CSS</a>. It removes and neutralizes the default styling of html elements providing a foundation upon which you can explicity declare your extentions.</p>
<p>Another very useful CSS reset is <a href="http://warpspire.com/features/css-frameworks/">CSS Global Styles Reset</a> by Kyle Neath. A simple CSS Reset with some additional classes for better debugging.</p>
<h4>Size text without using pixels</h4>
<p>Web Designing best principles is to enable a site to withstand a user enlarging text and setting absolute text sizes is not a good practice. Instead we can size our text relative to the browser. Standard browser font size is 1em which is equal to 16px. A little web designer trick works around the issue and resets the font sizes for the entire site so that 1em is equal to 10 px.<br />
<code><br />
body { font-size:62.5%; }<br />
</code><br />
Simply throwing the font-size to 62.5% for the entire site does the trick. Now you can use em instead of pixels.</p>
<h4>Organise your CSS Code</h4>
<p>Organising your CSS code helps you with future maintainability of your site. You should make independent style sheets for different purposes and then linke them in your master stylesheet. Like you should maintain your typographic styles and structure selectors independently in different stylesheets and then link them together in your master stylesheet.<br />
<code><br />
@import url("reset.css")<br />
@import url("structure.css")<br />
@import url("typography.css")<br />
</code></p>
<h4>Make your code easy to read</h4>
<p>While scanning through CSS, I came across a very nicely separated CSS coded probably by Rundle. It looked something like this:<br />
<code><br />
h1 {}<br />
h1#title { font-size:2em; }</code></p>
<p>div {}<br />
div#error { color:#eee; }</p>
<p>This technique is very useful if you&#8217;re sharing code or working on a large site where you are using the same div tag in multiple places.</p>
<h4>Document your code</h4>
<p>This might be common sense to some of you but sometimes I look at CSS and it&#8217;s not documented at all. It is always a good practice to document your code or atleast provide a separate heading for a part of code as it makes working with code months or years later easier.<br />
<code><br />
/**********************************/<br />
/* Primary Navigation - Top Links */<br />
/*********************************/<br />
#nav {<br />
border:1px solid #eee;<br />
margin:10px auto;<br />
padding:5px;<br />
}</code></p>
<p>/***************/<br />
/* Search Box */<br />
/**************/<br />
#search-box {<br />
position:absolute;<br />
top:30px;<br />
left:30px;<br />
}</p>
<h4>Keep containers to minimum</h4>
<p>Avoid using too many Divs as it makes your document too much complex and tougher to handle. Avoid block level tags as much as possible and consider all options before using DIVs. New Developers to CSS often mistake DIVs for table cells and maximise their use to achieve the layout. Some people even style their headings with DIVs. Try using small tags or inline tags for goodness sake.</p>
<h4>Use Shorthand CSS</h4>
<p>Work smarter, not harder with CSS. You can wrap multiple properties within a single declaration by using special syntax. Avoid unnecessary properties as it directly effects your troubleshooting efforts.</p>
<h5>Like instead of writing</h5>
<p><code>margin-left:2px;<br />
margin-top:3px;<br />
margin-right:4px;<br />
margin-bottom:5px;<br />
</code></p>
<h5>You can write</h5>
<p><code>margin:3px 4px 5px 2px;<br />
</code><br />
Similarly we can use shorthand for border, background, padding, font and other properties.</p>
<h4>Specify Units</h4>
<p>Always specify units for the Property values unless it is 0. This a very common mistake among CSS beginners. In HTML you can get away with this but in CSS all length values should have a unit. While there&#8217;s no wrong in specifying a unit for 0 value, but for me it&#8217;s only a wastage of space.</p>
<pre class="css">padding:2px 3px 0 10px;</pre>
<h4>Working with Colors</h4>
<p>In hexadecimal notation, a color is represented by three pairs of hexadecimal digits. You can write a color more efficiently by omitting every second digit like this.</p>
<p><code>#ffffff</code> can be written as <code>#fff</code></p>
<p>Similarly <code>#ff3366</code> can be written as <code>#f36</code></p>
<p>Another color related tip is that you can specify web safe colors by using only digits that are multiples of 3 for the red, green and blue.</p>
<h4>Don&#8217;t redeclare inherited values</h4>
<p>The values of many properties are inherited by any descendants of the element that you specify the property for. So there is no fun of redeclaring those properties again and again. Some of the commonly inherited properties are of font and color.<br />
<code><br />
div { font-size:2em;color:#ef321d; }<br />
div.hello { font-size:2em;color:#ef23ef; }<br />
</code></p>
<h5>can be written as</h5>
<p><code>div { font-size:2em;color:#ef321d; }<br />
div.hello { color:#ef23ef; }<br />
</code></p>
<h4>Multiple Classes</h4>
<p>You can assign multiple classes to a single HTML element. This allows you to write several rules that define different properties and only apply them as needed. The multiple classes (assuming .head &amp; .head-about) can be applied to a single element like this.<br />
<code><br />
&lt;div class="head head-about"&gt;This is test for multiple classes&lt;/div&gt;<br />
</code></p>
<h4>Minimise CSS Hacks</h4>
<p>Hacks are the tricks, usually non-standard, to overcome some browser limitations. Don&#8217;t use hacks unless it is a known and documented bug as it makes the future maintenance of the code very difficult in absence of proper documentation and standard coding design.</p>
<h4>Define pseudo classes for links in the LoVe/HAte order</h4>
<p>Link, Visited, Hover &amp; Active, as the above represents. You should define your pseudo classes in this order<br />
<code><br />
a:link { color: blue; }<br />
a:visited { color: purple; }<br />
a:hover { color: purple; }<br />
a:active { color: red; }<br />
</code></p>
<h4>Define generic font families</h4>
<p>“When we declare a specific font to be used within our design, we are doing so in the hope that the user will have that font installed on their system. If they don’t have the font on their system, then they won’t see it, simple as that. What we need to do is reference fonts that the user will likely have on their machine, such as the ones in the font-family property below. It is important that we finish the list with a generic font type. [<a href="http://www.communitymx.com/content/article.cfm?cid=FAF76&amp;print=true">Getting into good coding habits</a>]<br />
<code><br />
p { font-family: Arial, Verdana, Helvetica, sans-serif; }<br />
</code></p>
<h4>1 ID per page, many classes per page</h4>
<p>“Check your IDs: Only one element in a document can have a certain value for the id attribute, while any number of elements can share the same class name. [..] Class and id names can only consist of the characters [A-Za-z0-9] and hyphen (-), and they cannot start with a hyphen or a digit (see CSS2 syntax and basic data types).” [<a href="http://www.456bereastreet.com/lab/developing_with_web_standards/css/" target="_blank">Roger Johansson</a>]</p>
<h4>Horizontally Centering an element</h4>
<p>It is very easy to center an element horizontally using HTML with the align attribute, but there is no such property in the CSS. Instead we use margin to center the element like this</p>
<pre class="css">margin:0 auto;</pre>
<p>Here &#8216;auto&#8217; automatically divides the space left on the sides of element into half and assigns each half on each side of the element</p>
<h4>Conditional Comments of IE</h4>
<p>IE versions less than 7 adhere to CSS standards very less and often create a nasty CSS bug or issue to deal with. You can come around the issue by creating a different style to address the issue and then include the style for only IE using IE conditional comments like this.<br />
<code><br />
&lt;!--[if IE]&gt;<br />
&lt;link rel="stylesheet" type="text/css" href="ie.css" /&gt;<br />
&lt;![endif]--&gt;</code></p>
<p><em>Next Article in Series <a href="http://www.kashit.org/design/css-best-practices-ii/" title="">CSS Best Practices &#8211; II</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kashit.org/design/css-best-practices/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
