<?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>Technikal.net blog &#187; CSS</title>
	<atom:link href="http://technikal.net/blog/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://technikal.net/blog</link>
	<description>A blog on Web design, development and freelancing</description>
	<lastBuildDate>Sun, 25 Jul 2010 23:23:05 +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>Introduction to CSS Shorthand</title>
		<link>http://technikal.net/blog/introduction-to-css-shorthand/</link>
		<comments>http://technikal.net/blog/introduction-to-css-shorthand/#comments</comments>
		<pubDate>Tue, 05 May 2009 16:45:33 +0000</pubDate>
		<dc:creator>Al</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[shorthand]]></category>

		<guid isPermaLink="false">http://technikal.net/blog/?p=29</guid>
		<description><![CDATA[fgdfg dfgdf gdfgdfg]]></description>
			<content:encoded><![CDATA[<p>CSS Shorthand refers to the ability to set several properties in one single declaration instead of a sequence of related declarations. As we&#8217;ll see this a) Reduces the size of your CSS file, and b) Makes it a lot more organised and easy to understand. In this post I&#8217;ll look at a few of the common places where shorthand gets used. There are other rarely used or obscure uses like &#8220;outline&#8221; which I won&#8217;t cover today.</p>
<p><span id="more-29"></span></p>
<h3>Borders</h3>
<p>Below is an example of CSS code we can use to control the appearance of a border.</p>
<p><code>border-width: 1px;<br />
border-style: solid;<br />
border-color: #CDCDCD;<br />
</code></p>
<p>A simpler way to deal with these settings is to use the &#8220;border&#8221; shorthand.</p>
<p><code>border:1px solid #CDCDCD;</code></p>
<p>The exact order of width, style, color isn&#8217;t strictly required and using the values in different orders should work fine but if you notice something funky going on then you might want to check your order as it might be something simple like that if the browser is particularly strict. It should be noted that the properties above are actually shorthand themselves but when was the last time you used border-left-width: 1px? I can&#8217;t say I have often but perhaps i&#8217;m not daring or cool enough to have ultra modified borders.</p>
<h3>Backgrounds</h3>
<p>Another common use of shorthand is dealing with background. Instead of &#8220;background-color&#8221;, &#8220;background-image&#8221;, background-repeat&#8221;, &#8220;background-attachment&#8221; and &#8220;background-position&#8221; we can just use the rather obvious &#8220;background&#8221;.<br />
<code><br />
background-color: #fff;<br />
background-image: url(images/bg.jpg);<br />
background-repeat: repeat;<br />
background-attachment: fixed;<br />
background-position: 0 0;<br />
</code></p>
<p>Can be more easily maintained as:</p>
<p><code><br />
background: #fff url(images/bg.jpg) repeat fixed 0 0;<br />
</code></p>
<p>If you don&#8217;t specify a value in each case then defaults will be assumed. In many instances these are fine. If you&#8217;re only interested in making a background into a certain colour then you aren&#8217;t particularly worried about &#8220;image: none&#8221; being assumed as it will have no effect on you. The defaults are:</p>
<li>color: transparent</li>
<li>image: none</li>
<li>repeat: repeat</li>
<li>attachment: scroll</li>
<li>position: 0% 0%</li>
<h3>Margin and Padding</h3>
<p>Margin and padding are used extensively within CSS and I can&#8217;t recall ever creating a stylesheet that didn&#8217;t contain margins and padding in many different places. Because of this I find using the shorthands makes life a lot easier and saves a lot of space in the file.</p>
<p>It is important to remember <strong>TR</strong>em<strong>BL</strong>e or <strong>TR</strong>ou<strong>BL</strong>e when dealing with margins and padding. The uppercase letters standing for Top, Right, Bottom, Left. This is the order in which the shorthand is written.</p>
<p>Instead of:</p>
<p><code>margin-top: 5px;<br />
margin-right: 20px;<br />
margin-bottom: 10px;<br />
margin-left: 20px;<br />
</code></p>
<p>We can instead type:</p>
<p><code>margin: 5px 20px 10px 20px;</code></p>
<p>The smarty pants amongst us may have noticed that in the above example right and left are both 20px. Is there a way to group them to make our declaration even shorter? Well yes there is. Top and bottom, and Right and Left can be grouped together if desired.<br />
<code>margin: 5px 20px 10px;</code></p>
<p>You can of course cut it down from 3 to 2 to 1 depending on what you want to do:</p>
<p>Top and bottom &#8211; 5px, Right and left &#8211; 20px</p>
<p><code>margin: 5px 20px</code></p>
<p>Everything 5px</p>
<p><code>margin: 5px</code></p>
<h3>Fonts</h3>
<p>Last but not least for this introduction to shorthand are Fonts.</p>
<p><code>font-style: normal;<br />
font-variant: small-caps;<br />
font-weight: bold;<br />
font-size: 2em;<br />
line-height: 2.4em;<br />
font-family: Arial,sans-serif;<br />
</code></p>
<p>Can just as easily be written as:</p>
<p><code>font: normal small-caps bold 1em/1.2em Arial,sans-serif;</code></p>
<p>As mentioned with background above, there are some default settings that will be assumed if you don&#8217;t specify them yourself. Again it depends on whether the default interferes with what you want to do. In some cases it will be what you want or won&#8217;t be of interest.</p>
<li>font-style: normal</li>
<li>font-variant: normal</li>
<li>font-weight: normal</li>
<li>font-size: medium</li>
<li>line-height: normal</li>
<li>font-family: depends on the user agent</li>
<h3>Summary</h3>
<p>When learning CSS it&#8217;s often a good idea to start out by writing in full instead of shorthand. Indeed I would say I have a fairly decent grasp of CSS but I do still often tend to write in some shorthand and in full in other places. This is for a combination of reasons. Often its just a by product of the design and trying things out at the time to see what happens. A good exercise is to go back to the CSS file after you&#8217;ve tested and a put a site live to see if it can be slimmed down and reorganised. I should probably follow my own advice when I get some time!</p>
]]></content:encoded>
			<wfw:commentRss>http://technikal.net/blog/introduction-to-css-shorthand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
