<?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>Lateral Code &#187; css</title>
	<atom:link href="http://www.lateralcode.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lateralcode.com</link>
	<description>A Web Development Blog Focused on Code and Technology</description>
	<lastBuildDate>Thu, 26 Aug 2010 22:29:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>CSS3 in IE using cssSandpaper</title>
		<link>http://www.lateralcode.com/css3-ie-sandpape/</link>
		<comments>http://www.lateralcode.com/css3-ie-sandpape/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 17:50:42 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1453</guid>
		<description><![CDATA[A few months back, I wrote an article about Giving Elements Cool Effects Using CSS3. One of the major disappointments at the time of the writing of that article was a lack of support. Back then, Firefox, Safari, Chrome, and variants supported all effects, with Opera 10.5 slated to support them. Now, Opera 10.5 has [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back, I wrote an article about <a href="http://www.lateralcode.com/cool-css3-effects/">Giving Elements Cool Effects Using CSS3</a>. One of the major disappointments at the time of the writing of that article was a lack of support. Back then, Firefox, Safari, Chrome, and variants supported all effects, with Opera 10.5 slated to support them.</p>
<p>Now, Opera 10.5 has been released, and a wide variety of browsers support these effects, with the exception of Internet Explorer, which we all know will not support things like that natively for a while.</p>
<p><span id="more-1453"></span></p>
<p>Well, actually, it does for some of them. For one thing, Internet Explorer actually supports transforms, and has for a while now. But the syntax for doing it is ridiculous and incredibly time-consuming. Remember that the CSS3 for transforming looks like this:</p>
<pre><code>
.element {
	transform: rotate(10deg);
}</code></pre>
<p>In Internet Explorer, it looks something like this:</p>
<pre><code>
.element {
	filter:progid:DXImageTransform.Microsoft.Matrix(M11='0.7071067811865476',
	M12='0.7071067811865475', M21='-0.7071067811865475'
	,M22='0.7071067811865476', sizingmethod='auto expand');
}</code></pre>
<p>I won&#8217;t even begin to pretend I understand what any of that is. As far as I could tell, it&#8217;s probably something to do with radians and matrices.</p>
<p>So imagine my excitement when I came across something called <a href="http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">cssSandpaper</a>, which takes care of all the conversion from easy-to-understand numbers to the complex Microsoft method for you.</p>
<p>You can read all about cssSandpaper and how to use it at the original site, <a href="http://www.useragentman.com/blog/2010/03/09/cross-browser-css-transforms-even-in-ie/">User Agent Man</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/css3-ie-sandpape/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intelligent Caching of the CSS Minifier</title>
		<link>http://www.lateralcode.com/caching-css-minifier/</link>
		<comments>http://www.lateralcode.com/caching-css-minifier/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 23:44:09 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1410</guid>
		<description><![CDATA[A few months back, I presented a stunningly simple CSS minifier that enables you to pack your CSS while still maintaining format and readability. Soon after that, I presented a system called Lateral Cache that you could use to store the minified CSS and deliver it quickly. Although the Lateral Cache system works well and [...]]]></description>
			<content:encoded><![CDATA[<p>A few months back, I presented a <a href="http://www.lateralcode.com/css-minifer/">stunningly simple CSS minifier</a> that enables you to pack your CSS while still maintaining format and readability. Soon after that, I presented a system called <a href="http://www.lateralcode.com/lateral-cache/">Lateral Cache</a> that you could use to store the minified CSS and deliver it quickly.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/caching-css-minifier/1.jpg" alt="CSS" class="list-post-img"/></p>
<p>Although the Lateral Cache system works well and is great for general purposes, the CSS minifier can be aided by a more <strong>intelligent caching system</strong>. Well, what do I mean by that? That&#8217;s what you are going to find out.</p>
<p><a href="http://www.lateralcode.com/wp-content/themes/SimplyWhite/lateral-cache/css-styles.php" class="view">View a Demo</a> <a href="http://www.lateralcode.com/wp-content/uploads2/caching-css-minifier/caching-css-minifier.zip" class="dl">Download the Files</a></p>
<p>Please note that the demo link above directs you to Lateral Code&#8217;s own CSS file, where intelligent caching is used.</p>
<p><span id="more-1410"></span></p>
<h2>Re-caching for no reason? Say whaaat&#8230;?</h2>
<p>Any general caching system normally allows you to provide a time interval to cache. This interval is used in a simple manner:</p>
<ol>
<li>Store an initial cache of the data in a file.</li>
<li>Check if the time of the last cache is greater than the specified time interval.</li>
<li>If so, re-cache a new set of updated data and deliver it.</li>
<li>Otherwise, deliver the data in the cache</li>
<li>Repeat steps 2 &#8211; 4 indefinitely.</li>
</ol>
<p>This system is a basic standard and has been used with much success. By re-caching at a specified interval, data will eventually be updated and the user won&#8217;t have to wait excessively after each request to the website. Essentially, if this system is used, a website will not have to check for new data at each user request; rather, it will check only after the specified time interval.</p>
<p>Note that the above works very well for data that is updated at a specific time interval. For example, if new data arrives every 30 minutes, a cache is ideal because it can be configured to update only when new information is available.</p>
<p>Returning back to the CSS minifier, it&#8217;s important to realize that the need for re-minifying only occurs when the original CSS file has been modified. Only under this circumstance will the cache have to be updated. In essence, keeping a cache with a specified interval such as one day will produce excessive re-caching that is not useful. On the flip side, if you were to use a very large cache interval, such as 30 days, updating the CSS file would be a pain, as you would have two main choices:</p>
<ul>
<li>Wait 30 days until the cache refreshes</li>
<li>Change the code to temporarily stop caching</li>
</ul>
<p>The first option is much worse than the second, but both are still a pain.</p>
<h2>How can you check if a file is modified?</h2>
<p>Now there&#8217;s the golden question you were all waiting for. If you know that the cache should only be updated when the original CSS file is modified, how would you adapt the code to meet this criterion? Luckily, the answer is simple due to magic <a href="http://php.net/manual/en/function.filemtime.php"><code>filemtime</code></a> PHP function, which can tell you the last time the file was modified.</p>
<p>The algorithm to accomplish the task now becomes quite trivial:</p>
<ol>
<li>When caching, store both the last modified time and the minified CSS. This can be done by using two files or just one.</li>
<li>When checking what to deliver to the user, compare the stored time to the last modified time. If they are the same, return what is in the cache. Otherwise, re-cache and re-minify the CSS. Consequently, deliver the new data to the user.</li>
</ol>
<h2>Writing code using the algorithm</h2>
<p>From the algorithm comes the following code:</p>
<pre><code>header( "Content-type: text/css" );

// config --->
$dataFile = 'cache/styles'; // Make sure a cache directory exists
$timeFile = 'cache/styles-time';
$origFile = '/path/to/css/file'; // Change this
// < --- end config

$lastTime = -1;
if( file_exists( $timeFile ) )
	$lastTime = (int) file_get_contents( $timeFile );

$cache = false;
if( file_exists( $dataFile ) &#038;&#038; file_exists( $origFile ) &#038;&#038; $lastTime == filemtime( $origFile ) ) {
	$css = file_get_contents( $dataFile );
	$cache = true;
}
else {
	$css = file_get_contents( $origFile );
	$css = minify( $css );

	file_put_contents( $dataFile, $css );
	file_put_contents( $timeFile, filemtime( $origFile ) );
}

echo $css;</code></code></pre>
<p>Remember to change <code>$origFile</code> to point to your CSS file and also ensure that a <code>cache/</code> directory exists (you may change the name/placement of this directory by editing the <code>$dataFile</code> and <code>$timeFile</code> variables).</p>
<p>Note that the minify function used in the above code is present in the <a href="http://www.lateralcode.com/css-minifer/">original article</a>.</p>
<p>As a quick overview:</p>
<ol>
<li>The configuration options set the location of the original CSS file. They also point to the data files for storing minified CSS and the last modified time.</li>
<li>The time file is loaded into a variable and compared with the <code>filemtime</code> of the original CSS file.</li>
<li>If the two differ, minification is applied and the data is re-cached. It is then delivered.</li>
<li>Otherwise, the cached file with minifed CSS is delivered.</li>
</ol>
<h2>Conclusion</h2>
<p>So, with some simple analysis and one useful PHP function, caching can become much more intelligent for the CSS minifier.</p>
<p>Do you have any thoughts about the minifier? Do you know some way to make it better? It&#8217;s now your time to talk, so feel free to do so in a comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/caching-css-minifier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving Elements Cool Effects Using CSS3</title>
		<link>http://www.lateralcode.com/cool-css3-effects/</link>
		<comments>http://www.lateralcode.com/cool-css3-effects/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 13:00:18 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1383</guid>
		<description><![CDATA[CSS3 is full of cool new features. For example, last week we talked about CSS3 colors. In this post, I&#8217;d like to talk about some other cool features that CSS3 has to offer, and how you can access some of them now. Border-Radius I&#8217;m going to start out with an oldie but goodie. Border-Radius has [...]]]></description>
			<content:encoded><![CDATA[<p>CSS3 is full of cool new features. For example, last week we talked about <a href="http://www.lateralcode.com/playing-with-css3-colors/">CSS3 colors</a>. In this post, I&#8217;d like to talk about some other cool features that CSS3 has to offer, and how you can access some of them now.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/almosteveryth.png" alt="CSS3 Effects" class="list-post-img"/></p>
<p><span id="more-1383"></span></p>
<h2>Border-Radius</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/border-radius.png" alt="Border Radius" class="list-post-img"/></p>
<p>I&#8217;m going to start out with an oldie but goodie. Border-Radius has been making the rounds for a while &#8211; it&#8217;s basically a way to get curved corners on a box. Recent versions of Mozilla Firefox, Chrome, and Safari all support Border-Radius, and, although Opera supposedly supported it at one point, current versions of Opera do not. It has been reported, though, that Opera 10.5 will support this again.</p>
<p>Here&#8217;s how to make it work:</p>
<pre><code>.element {
	border-radius:10px; /* Official statement */
	-moz-border-radius:10px; /* For Firefox */
	-webkit-border-radius:10px; /* For Safari and Chrome */
	-o-border-radius:10px; /* Reported statement for Opera 10.5 */
}
</code></pre>
<p>Border-radius takes up to four numerical arguments (meaning in <code>px</code>, <code>pt</code>, or <code>em</code>), separated by spaces. The arguments denote the radius for the corners starting from the top-left corner and circling clockwise. If less than four arguments are given, then the arguments are duplicated for the remaining corners, similar to what happens with padding and margin when less than four arguments are given.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/border-radius-2.png" alt="Border Radius - Multiple arguments" class="list-post-img"/></p>
<p>If you wanted to apply a rounded corner to only one corner, it is possible with individual statements. These statements differ between Firefox and Webkit-based browsers:</p>
<table>
<tr>
<th scope="column">Corner</th>
<th scope="column" style="font-weight:bold">Firefox</th>
<th scope="column" style="font-weight:bold">Webkit</th>
</tr>
<tr>
<td scope="row">Top-Left</td>
<td>-moz-border-radius-topleft</td>
<td>-webkit-border-top-left-radius</td>
</tr>
<tr>
<td scope="row">Top-Right</td>
<td>-moz-border-radius-topright</td>
<td>-webkit-border-top-right-radius</td>
</tr>
<tr>
<td scope="row">Bottom-Right</td>
<td>-moz-border-radius-bottomright</td>
<td>-webkit-border-bottom-right-radius</td>
</tr>
<tr>
<td scope="row">Bottom-Left</td>
<td>-moz-border-radius-bottomleft</td>
<td>-webkit-border-bottom-left-radius</td>
</tr>
</table>
<p>If you want rounded corners on a cross-browser basis, there have been numerous hacks to get it to work. I recommend using the <a href="http://plugins.jquery.com/project/corners">jQuery Rounded Corners Plugin</a>.</p>
<h2>Box-Shadow</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/box-shadow.png" alt="Box Shadow" class="list-post-img"/></p>
<p>Box-Shadow is a fun one. It adds a shadow to the element affected, but it is capable of a great deal of customization.</p>
<p>Box-Shadow takes up to five arguments:</p>
<ol>
<li>Horizontal offset</li>
<li>Vertical offset</li>
<li>Blur radius</li>
<li>Spread</li>
<li>Color</li>
</ol>
<p>The first two arguments are required, as is the last one. Blur radius and Spread are optional. The first four arguments take numerical value inputs, and the last one, obviously, takes a color input.</p>
<p>How the offsets work is fairly obvious. A positive horizontal offset means that the shadow is offset to the right of the element, and a negative horizontal offset means that the shadow is offset to the left. Similarly, a positive vertical offset means the shadow is offset toward the downward direction, and a negative vertical offset offsets the shadow upwards.</p>
<p>The color argument can be in hexadecimal format, RGB format, or, if the browser supports it, <a href="http://www.lateralcode.com/playing-with-css3-colors/">RGBA, HSL, or HSLA</a>.</p>
<p>Blur radius and spread are interesting concepts.</p>
<p>The Blur radius argument is how big the blur of the shadow is. An input of 0 for the Blur radius means that the shadow will have solid edges, much like the element it is shadowing. The higher the value of the input, the more blurred the edges are. However, because you can&#8217;t have a more solid edge than 0, you can&#8217;t pass a negative number for Blur radius.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/blur.png" alt="Blur" class="list-post-img"/></p>
<p>The Spread argument can expand or contract the shadow. A positive value means that the dimensions of the shadow are bigger than the dimensions of the element, while a negative value makes the dimensions smaller. An input of 0 gives the shadow the same dimensions as the element.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/spread.png" alt="Spread" class="list-post-img"/></p>
<p>The CSS statements for Box-Shadow are as follows:</p>
<pre><code>.element {
	box-shadow: 10px 10px 5px 0 #888888; /* Official statement */
	-moz-box-shadow: 10px 10px 5px 0 #888888; /* For Firefox */
	-webkit-box-shadow: 10px 10px 5px 0 #888888; /* For Safari and Chrome */
}
</code></pre>
<p>As you can see, Opera does not support Box-Shadow yet, but, like Border-Radius, it is reported that Box-Shadow will be supported in Opera 10.5.</p>
<h2>Transform</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/transform-rotate.png" alt="Transform: Rotate" class="list-post-img"/></p>
<p>I&#8217;m actually kind of scared of Transform and what it means for the future of web design. Traditionally, layouts have been done in rectangular, blocky grids, because that&#8217;s what CSS supported: rectangular, blocky grids. Transform kind of turns that idea on it&#8217;s head. Or side, or corner. And skews it.</p>
<p>Basically, transform can do a lot of stuff to an element. Here&#8217;s a basic list of what it can do:</p>
<dl>
<dt>rotate</dt>
<dd>Rotates the element clockwise by the specified angle.</dd>
<dt>scale</dt>
<dd>Scales the element by the specified decimal value: a value of &gt;1 will make the element bigger, while a value of &lt;1 will make the element smaller.</dd>
<dt>skew</dt>
<dd>Skews the element by the specified number of angle.</dd>
<dt>translate</dt>
<dd>Shifts the element by the specified numerical value.</dd>
</dl>
<p>All these are passed to transform in the following fashion:</p>
<pre><code>.element {
	transform: command(comma-separated-inputs);
}
</code></pre>
<p>For example, the command for translating an element 10px to the right and 20px down would look like this:</p>
<pre><code>.element {
	transform: translate(10px,20px);
}</code></pre>
<p>Rotate takes a single parameter: the angle that the element is rotated. The angle can be specified in either degrees or radians; the distinctions is made by appending <code>deg</code> or <code>rad</code> after the number. The appendix is required, or the transform will not occur.</p>
<p>Scale takes one or two input. If only one input is given, it is applied in the horizontal direction, while the second input would be applied in the vertical direction. The arguments are given in decimal format, meaning that an input of 1.2 means the element is scaled to 120% in the applicable direction, while an input of .75 means the element is scaled to 75% in the applicable direction.</p>
<p>Skew, like scale, takes one or two inputs. Similarly, the first input is applied horizontally, while the second input is applied vertically. Inputs are given as angles, meaning that the values must be appended with <code>deg</code> or <code>rad</code>, like rotate.</p>
<p>Translate, like the previous two, takes one or two inputs with the same directional applications. Inputs are given in <code>px</code>, <code>pt</code>, or <code>em</code>.</p>
<p>Scale, Skew, and Translate also come with X and Y only versions, that look like this:</p>
<ul>
<li>scale &#8211; scaleX, scaleY</li>
<li>skew &#8211; skewX, skewY</li>
<li>translate &#8211; translateX, translateY</li>
</ul>
<p>Applying multiple translations is done like this:</p>
<pre><code>.element {
	transform: skew(5deg,-15deg) scale(1.2, 1.5) rotate(10deg);
}</code></pre>
<p>You can see the effects of the multiple translations, along with Border-Radius, Box-Shadow, and the CSS2 feature Text-Shadow:</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/css3/everyth.png" alt="A slew of CSS3 Effects" class="list-post-img"/></p>
<p>Transform is supported by newer versions of Firefox, Chrome, Safari, and will be supported in Opera starting from Opera 10.5:</p>
<pre><code>.element {
	transform: [commands]; /* Official statement */
	-moz-transform: [commands]; /* For Firefox */
	-webkit-transform: [commands]; /* For Safari and Chrome */
	-o-transform: [commands]; /* For Opera 10.5 */
}</code></pre>
<p>I hope you&#8217;ve enjoyed reading this wall of text about the new CSS3 features. Feel free to subscribe to our RSS feed or follow us on Twitter for more goodies like this in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/cool-css3-effects/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Playing Around with CSS3 Colors</title>
		<link>http://www.lateralcode.com/playing-with-css3-colors/</link>
		<comments>http://www.lateralcode.com/playing-with-css3-colors/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 12:00:28 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1327</guid>
		<description><![CDATA[Traditionally, people using colors in CSS have dealt with either the hexadecimal format, which looks like this: #ABCDEF or the rgb format, which looks like this: rgb(171,205,239). CSS3 comes with a few new ways of manipulating colors, such as using HSL (Hue, Saturation, Light) and opacity/alpha-channels. Unfortunately, only Firefox 3+, Opera 10+, Chrome 1.0+ and [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally, people using colors in CSS have dealt with either the hexadecimal format, which looks like this: <code>#ABCDEF</code> or the rgb format, which looks like this: <code>rgb(171,205,239)</code>.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/1116539_41135139.jpg" alt="Color Pencils" class="list-post-img" /></p>
<p>CSS3 comes with a few new ways of manipulating colors, such as using HSL (Hue, Saturation, Light) and opacity/alpha-channels. Unfortunately, only Firefox 3+, Opera 10+, Chrome 1.0+ and Safari 3+ and a few derivatives fully support these at the moment, but we make do with what we can, seeing as Internet Explorer doesn&#8217;t even start supporting CSS3 elements until <a href="http://beta.blogs.msdn.com/ie/archive/2009/11/18/an-early-look-at-ie9-for-developers.aspx">Internet Explorer 9</a>.</p>
<p><span id="more-1327"></span></p>
<h2>Opacity</h2>
<p>This one is an old one that, surprisingly, is available in current versions of IE, albeit in a more complicated way.</p>
<p>Opacity turns the entire CSS object transparent, and the opacity of any child element is scaled appropriately. The official CSS3 statement is as follows:</p>
<pre><code>    opacity: [number between 0-1];
</code></pre>
<p>So a setting of <code>opacity: 0.5;</code> would make the object 50% transparent. Although newer browsers support this head-on, older browsers require some custom code, as well as Internet Explorer.</p>
<p>So for older Firefox versions, we use the <code>-moz-</code> prefix, and for older Safari/Chrome versions, we use the <code>-webkit-</code> prefix. For really oldschool versions of Safari that used KHTML instead of Webkit, we use <code>-khtml-</code>. So if we really wanted to support everyone, our code might look something like this:</p>
<pre><code>    opacity: 0.5;
    -moz-opacity: 0.5;
    -webkit-opacity: 0.5;
    -khtml-opacity: 0.5;
</code></pre>
<p>But wait! What about Internet Explorer? Well, Internet Explorer doesn&#8217;t actually support this outright, but rather through a proprietary Microsoft filter. The traditional way of doing it was short and sweet:</p>
<pre><code>    filter:alpha(opacity=50);
</code></pre>
<p>Note that we now use a scale of 0-100 for Internet Explorer, not 0-1 as we do for other browsers. Internet Explorer 8 provides a new beast to have to deal with. Don&#8217;t try to memorize this one like you would the other ones, this is a long one:</p>
<pre><code>    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
</code></pre>
<p>Of course, if you wanted to support older versions of Internet Explorer, you would have to use the shorter version as well, meaning you would need a total of <strong>six</strong> CSS statements if you wanted to support a large range of browsers.</p>
<h2>RGBa</h2>
<p>Let&#8217;s next talk about RGBa. RGBa is an extension of the original RGB, but it takes a fourth argument: the alpha channel. The alpha channel argument takes a number between 0 and 1, just like opacity did. The main advantage of using RGBa over opacity is that when using RGBa, the transparency isn&#8217;t applied to child elements. What this means is that you can have a completely solid object inside a transparent object, whereas when you use opacity, child elements of transparent objects are also transparent.</p>
<p>Using RGBa couldn&#8217;t be simpler:</p>
<pre><code>    div {
        background: rgb(255,0,0); /* The old one */
        background: rgba(255,0,0,0.5); /* The new one */
    }
</code></pre>
<p>As you can see, we have gone from a solid red to a half-transparent red by adding a letter and another argument. RGBa is supported in Firefox 3+, Opera 10+, Safari 3+, and Chrome 1.0+, but not Internet Explorer. <a href="http://css-tricks.com/rgba-browser-support/">CSS-Tricks</a> provides a proprietary filter workaround to make this work in Internet Explorer:</p>
<pre><code>    &lt;!--[if IE]&gt;
        &lt;style type="text/css"&gt;
            .color-block {
                background:transparent;
                filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000050,endColorstr=#99000050);
                zoom: 1;
            }
        &gt;/style&gt;
    &lt;![endif]--&gt;
</code></pre>
<h2>HSL</h2>
<p>HSL is a pretty intuitive way of choosing colors. If you need &#8220;just a little darker&#8221; or &#8220;just a little brighter&#8221;, playing around with hexadecimal combinations takes a bit of time. Luckily, with HSL, it&#8217;s just a simple number change.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/hsl_top.jpg" alt="HSL Color Wheel" class="list-post-img" /></p>
<p>HSL stands for Hue, Saturation, Lightness. Hue is the color in a color wheel (see picture above). Color choice is done using degrees, with 0º being Red, 120º being Green, and 240º being Blue. Of course, you have the different color combinations as in-betweens, so you sort of have this going on:</p>
<ul>
<li style="color:#f00">0º &#8211; Red</li>
<li style="color:#ff0">60º &#8211; Yellow</li>
<li style="color:#0f0">120º &#8211; Green</li>
<li style="color:#0ff">180º &#8211; Cyan</li>
<li style="color:#00f">240º &#8211; Blue</li>
<li style="color:#f0f">300º &#8211; Magenta</li>
</ul>
<p>Saturation is how much of the color we are using. 0% means a greyscale, since we aren&#8217;t using any of the color, whereas 100% means the chosen color in full.</p>
<p>Lightness is basically how bright the color is. A lower setting means darker, and a higher setting means lighter, with 0% and 100% meaning black and white respectively.</p>
<p>So an object with a background of an orange-ish color at 50% saturation and 80% lightness would look like this:</p>
<pre><code>    div {
        background: hsl(30, 50%, 80%);
    }
</code></pre>
<p>Making this a bit lighter or a bit darker would merely entail changing the last argument.</p>
<h2>HSLA</h2>
<p>HSLA would, of course, be just an extension of HSL that, like RGBa, adds a fourth argument of opacity. Usage of HSLA is just as easy as that of RGBa: just stick the extra argument in there:</p>
<pre><code>    div {
        background: hsla(30, 50%, 80%, 0.5);
    }
</code></pre>
<p>The last example is the previously used orange-ish color, but at 50% opacity.</p>
<h2>Conclusion</h2>
<p>Of course, HSL and HSLA are only supported in newer versions of Firefox, Opera, Safari, and Chrome. There are no proprietary workarounds for Internet Explorer for these two as there are for Opacity and RGBa. However, that should never stop you from trying them out and experimenting with them.</p>
<p>See you next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/playing-with-css3-colors/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>How to easily create top navigation with CSS</title>
		<link>http://www.lateralcode.com/top-navigation/</link>
		<comments>http://www.lateralcode.com/top-navigation/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 17:46:13 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1275</guid>
		<description><![CDATA[Navigation is a vital part of all websites. Visitors must have ways to traverse through pages to find what they need. Top navigation is a specific style in which links are placed at the top of a website. In this tutorial, we will explore the creation of a pure CSS top navigation. Note: This article [...]]]></description>
			<content:encoded><![CDATA[<p>Navigation is a vital part of all websites. Visitors must have ways to traverse through pages to find what they need. Top navigation is a specific style in which links are placed at the top of a website. In this tutorial, we will explore the creation of a pure CSS top navigation.</p>
<p class="text-center red"><strong>Note: This article is for CSS beginners!</strong></p>
<p><a href="http://www.flickr.com/photos/jghphoto/3171955569/"><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/nav.png" alt="Navigation" class="list-post-img"/></a></p>
<h2>What makes top navigation so special?</h2>
<p>When a user first visits a site, they immediately see the top half of a web page. For a quick fact, this half is known as the area above the fold.</p>
<p><span id="more-1275"></span></p>
<p>Top navigation concentrates on the above property. By having navigation in the area a user first looks at, <strong>links gain more attention</strong>. This principle makes top navigation a viable alternative to the regular sidebar menu.</p>
<h2>How is a top navigation menu created?</h2>
<p>Top navigation menus are typically created through HTML and CSS, though JavaScript can help spice them up.</p>
<h3>HTML</h3>
<p>A navigation menu is inherently a type of list. Thus, it is only proper to contain this sort of menu in an HTML list:</p>
<pre><code>&lt;ul&gt;
&lt;li&gt;&lt;a href="/"&gt;Home&lt;/li&gt;
&lt;li&gt;&lt;a href="/about/"&gt;About&lt;/li&gt;
&lt;li&gt;&lt;a href="/contact-us/"&gt;Contact Us&lt;/li&gt;
&lt;li&gt;&lt;a href="/portfolio/"&gt;Portfolio&lt;/li&gt;
&lt;li&gt;&lt;a href="/gallery/"&gt;Gallery&lt;/li&gt;
&lt;ul&gt;</code></pre>
<p>The above snippet contains an unordered list with links in each list item. It will be the base for our CSS.</p>
<h3>CSS</h3>
<h4>Bullet Points</h4>
<p>Now, when you first look at an unordered list, you will see something like this:</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-1.png" alt="Unordered List" class="list-post-img"/></p>
<p>Notice how I&#8217;m using firebug and creating custom HTML + CSS within a blank page that has no URL. It is a key add-on to firefox that all web developers should have. With that side-note finished, let&#8217;s return to the problem:</p>
<p>There are little bullet points at the beginning of each element. In our case, these are unnecessary. We need a simple list with no bullet points that can be displayed horizontally. To remove this effect, we can use the <code>list-style-type</code> property:</p>
<pre><code>ul {
list-style-type: none;
}</code></pre>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-2.png" alt="No Bullet Points" class="list-post-img"/></p>
<h4>Horizontal Display</h4>
<p>Next, we must remove the normal vertical-style display of the unordered list. This will take a small bit of work.</p>
<p>The first thing we must notice is that list items are normally displayed in a &#8220;<em>block box</em>.&#8221; This is specified with the CSS property <code>display: list-item;</code>. Unfortunately, this produces a <strong>line break before and after</strong> each list item. We must change this property to display the items in a one single line. This is simply done by changing the <code>display</code> property:</p>
<pre><code>li {
display: inline;
}</code></pre>
<p>The above CSS statement changes the display of the list elements so that they are next to one another in a horizontal line.</p>
<p>Along with this, it is also a good rule of thumb to float each list element to the left. This will remove browser inconsistencies and also place the list in the left most position because floated elements stack. Essentially, this means that the list elements will be placed side by side and not on top of one another:</p>
<pre><code>li {
float: left;
}</code></pre>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-3.png" alt="Horizontal Menu" class="list-post-img"/></p>
<h4>A word of caution</h4>
<p>Let me side-track a bit to explain a problem that you may run into when customizing this menu. Once you complete writing the above code, you might want to add a left-offset to each list element in order to space them out:</p>
<pre><code>li {
float: left;
display: inline;
margin-left: 20px;
}</code></pre>
<p>Do you see anything wrong with this?</p>
<p><strong>The old double-margin trick</strong></p>
<p>An element that is floated left with a left margin. This should immediately put up a flag in your head. When a floated element is given a margin that is on the same side as the float, IE 6 doubles the margin. Just remember to take this into account if you want a left margin.</p>
<p>Now that we&#8217;ve avoided that calamity, let&#8217;s move forward.</p>
<h4>Adding some inital <em>style</em></h4>
<p>Now, I feel that this menu looks very bland at this point. I want to spice it up a bit. Let&#8217;s add a custom font and some link styling:</p>
<pre><code>body {
font: 14px/22px Georgia, "Times New Roman", Times, Serif;
}

a {
color: #DA4B4B;
text-decoration: none;
}

a:hover {
color: #000;
}</code></pre>
<p>That might be a bit much to digest. Let me explain what is going on.</p>
<p>The first thing we do is set an overall font. It has a size of 14px, line-height of 22px, and font-family of Georgia, &#8220;Times New Roman&#8221;, Times, Serif. We then move on to our links and set a color for them. Notice how we also remove the default underlining through <code>text-decoration: none</code>. Finally, we set hover styles. The :hover selector is a <code>psuedo-class</code> that activates every time the mouse hovers over a link. When this does occur, we change the link color to black &#8211; <code>#000</code>.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-4.png" alt="Styled List" class="list-post-img"/></p>
<p>At this point, many of you must be annoyed with how closely each list element is placed next to one another. Let&#8217;s fix this up.</p>
<h4>Styling the links</h4>
<p>If you scroll to the top of the CSS blog, you will notice that a large portion of each navigation element can be hovered over to click on it. In other words, you don&#8217;t have to click directly on &#8220;What&#8217;s new?&#8221;. Instead, you can place your cursor a bit under it and still click to have the same effect.</p>
<p><strong>How can we accomplish this?</strong></p>
<p>It is actually quite simple to create this effect. The key is in each link. Instead of displaying the links normally, <em>we can put them in a block box</em>. When this occurs, the whole area the text takes up will also be a part of the link. Well, you might ask, isn&#8217;t this what links normally do?</p>
<p>Here is where the tricky part comes in. Links do take up the text area, but they do not consider line-height. If a link is displayed as block, <strong>line-height will determine the actual height unless overridden</strong>. This can work to our advantage! We can simply set the line-height of the unordered list to achieve a larger link:</p>
<pre><code>ul {
line-height: 50px;
}

li a {
display: block;
border: 1px solid #000;
}</code></pre>
<p>Notice how I am setting a border around the link so you can see the dimensions of it.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-5.png" alt="Block Link" class="list-post-img"/></p>
<p>We are almost there! At this point, we can finally get rid of that bad spacing. All we need to do is add padding and/or margin to the link element. In this case, I will add a <code>20px</code> left and right padding:</p>
<pre><code>li a {
padding: 0 20px;
}</code></pre>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-6.png" alt="Link With Padding"/></p>
<p>Finally, we can put in a few extra styles to make it look nice:</p>
<pre><code>li a {
background: #ececec;
font-size: 18px;
border: 1px solid #ccc;
}

li a:hover {
background: #f6f6f6;
font-size: 20px;
}</code></pre>
<p>In this above snippet, we just add a background color, border, and font size to each link element. These values then get adjusted when the mouse hovers over them.</p>
<p>Here is the final product:</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/top-nav/menu-7.png" alt="Final Product" class="list-post-img"/></p>
<h4>The Finished CSS</h4>
<pre><code>body {
font: 14px/22px Georgia, "Times New Roman", Times, Serif;
}

a {
color: #DA4B4B;
text-decoration: none;
}

a:hover {
color: #000;
}

ul {
list-style-type: none;
line-height: 50px;
}

li {
display: inline;
float: left;
}

li a {
display: block;
background: #ececec;
padding: 0 20px;
font-size: 18px;
border: 1px solid #ccc;
}

li a:hover {
background: #f2f2f2;
font-size: 20px;
}</code></pre>
<h2>Conclusion</h2>
<p>I hope this helped refine your CSS skills! Stay tuned for more and feel free to drop a comment with any questions/comments/concerns!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/top-navigation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remembering the User’s Preferred Color Scheme</title>
		<link>http://www.lateralcode.com/remember-user-scheme/</link>
		<comments>http://www.lateralcode.com/remember-user-scheme/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 11:00:33 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1221</guid>
		<description><![CDATA[Last time, we showed you how to set up alternate color schemes using PHP. As promised, we will now show you how to remember the user’s choice. We will once again make use of PHP, this time cookies. We will explore how to set the cookie for the user’s choice, and two methods of using [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lateralcode.com/alternate-colors-php/">Last time</a>, we showed you how to set up alternate color schemes using PHP. As promised, we will now show you how to remember the user’s choice.</p>
<p>We will once again make use of PHP, this time cookies. We will explore how to set the cookie for the user’s choice, and two methods of using this information.</p>
<p>First, we shall create a file. For purposes of demonstration, this file shall be called <code>switch.php</code>.</p>
<p><span id="more-1221"></span></p>
<p>This file takes in a parameter <code>color</code>, sets the cookie value to that color, and redirects the user to the previous page. You can use other nomials than <code>color</code> if you wish.</p>
<pre><code>
&lt;?php
	$color = $_GET['color'];
	$_COOKIE['color'] = $color;
	header("Location: " + $_SYSTEM['HTTP_REFERER']);
?&gt;
</code></pre>
<p>Next, we need to add links. The URLS will call <code>switch.php</code> with the relevant color.</p>
<pre><code>
	&lt;a href="switch.php?color=red"&gt;Red scheme&lt;a&gt;
</code></pre>
<p>When a user clicks on the link, the cookie will be set that their choice is their preferred scheme.</p>
<p>Now let’s look at ways of calling this information and showing the right scheme to the user.</p>
<h2>Method One</h2>
<p>The first method requires that your HTML page be done in PHP.</p>
<p>First, let’s look at the call to the CSS file from last time:</p>
<pre><code>
&lt;link rel="stylesheet" type="text/css" file="styles.php?color=green" /&gt;
</code></pre>
<p>What we want to do is make the color variable and not hard-coded. We’ll look for the user’s cookie for this site called <code>color</code>. Remember that you may name it whatever you choose.</p>
<pre><code>
&lt;?php
	$color = $_COOKIE['color'];
	echo '&lt;link rel="stylesheet" type="text/css" file="styles.php?color='.$color.' /&gt;';
?&gt;
</code></pre>
<h2>Method Two</h2>
<p>The second method requires that your CSS file be done in PHP, which it already is. It allows for not passing any argument at all in the HTML page:</p>
<pre><code>
&lt;link rel="stylesheet" type="text/css" file="styles.php" /&gt;
</code></pre>
<p>What this method does is call for the user preference in the CSS file.</p>
<p>In the CSS file from last time, there existed these three lines:</p>
<pre><code>
	$scheme-name = $_GET['color'];
	$scheme = $schemes[$scheme-name];
	if ( !$scheme ) { $scheme = $schemes['green']; }
</code></pre>
<p>We will replace the first line with the following:</p>
<pre><code>
	$scheme-name = $_COOKIE['color'];
</code></pre>
<p>By using one of these two methods, you can now remember the user preference and serve up different color schemes based on their preferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/remember-user-scheme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stunningly Simple CSS Minifier</title>
		<link>http://www.lateralcode.com/css-minifier/</link>
		<comments>http://www.lateralcode.com/css-minifier/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 09:28:56 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1197</guid>
		<description><![CDATA[Creating a beautiful and eye-catching website can often require you to have a hefty CSS file. Unfortunately, this side-effect takes away from your visitors experience; they spend more of their time downloading rather than viewing. In essence, a balance needs to be reached in order for full optimization. Solving the problem One simple way to [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a beautiful and eye-catching website can often require you to have a hefty CSS file. Unfortunately, this side-effect takes away from your visitors experience; they spend more of their time downloading rather than viewing. In essence, a balance needs to be reached in order for full optimization.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/css-minifier.jpg" alt="CSS" class="list-post-img"/></p>
<h2>Solving the problem</h2>
<p>One simple way to achieve this balance is by using a minifier. By taking a CSS file in as input, a minifier removes white space and other unnecessary elements to significantly reduce file size.</p>
<p><span id="more-1197"></span></p>
<h2>Oops, did you forget about something?</h2>
<p>At first glance, this seems to be a zero-drawback system. Upon closer inspection, it becomes apparent that removing white space creates poor formatting, a leading cause of what we call read-once write-once code. You might be able to edit the styles directly after creation, but in a few days or weeks, this task becomes tedious.</p>
<p>This is mainly why using online minifiers aren&#8217;t 100% supported. In fact, by creating your own minifer, there is a way to both <em>keep formatting and produce minified code</em>. You might think these are mutually exclusive. This post, which demonstrates how to create a <strong>stunningly simple CSS minifier</strong>, aims to prove you wrong.</p>
<h2>Meet our dear friend: PHP</h2>
<p>In <a href="http://www.lateralcode.com/alternate-colors-php/">our previous post</a>, we showed you how to generate CSS using PHP. In this article, we will utilize a similar concept.</p>
<p>Before you can actually solve the minifier&#8217;s main problem, it is imperative to first <strong>write a minifier</strong>. Luckily, we have created an extremely simple PHP function to do so. In approximately 10 lines, the following code will finish over 90% of all possible minifications:</p>
<pre><code>function minify( $css ) {
	$css = preg_replace( '#\s+#', ' ', $css );
	$css = preg_replace( '#/\*.*?\*/#s', '', $css );
	$css = str_replace( '; ', ';', $css );
	$css = str_replace( ': ', ':', $css );
	$css = str_replace( ' {', '{', $css );
	$css = str_replace( '{ ', '{', $css );
	$css = str_replace( ', ', ',', $css );
	$css = str_replace( '} ', '}', $css );
	$css = str_replace( ';}', '}', $css );

	return trim( $css );
}</code></pre>
<p>Who knew simplifying CSS could be that easy? Using <code>preg_match</code>, the above code is able to replace extraneous white space with just a single character. It then proceeds to minfy even more elements using <code>str_replace</code>.</p>
<h2>Huh? How am I supposed to use the above code?</h2>
<p>Well, now that we have created our PHP function, you might wonder how to use it. The answer to this question stems, once again, from the previous article. Instead of linking to a <code>css</code> file from our HTML, we will actually refer to a <code>php</code> one:</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" href="minify.php?css=styles.css" /&gt;</code></pre>
<p>Notice how we call our <code>minify.php</code> file with the parameter <code>css</code>. The value of <code>css</code> actually refers to the file we want to minify. With this in place, create the <code>minify.php</code> file and add in the function we previously created. In addition, place the following code at the beginning of the file:</p>
<pre><code>header( "Content-type: text/css" );

$file = isset( $_GET[ 'css' ] ) ? $_GET[ 'css' ] : '';
if( !file || array_pop( split( '\.', $file ) ) != 'css' || strpos( $file, '/' ) !== false )
	die( 'Invalid Parameters' );

$content = @file_get_contents( $file );</code></pre>
<p>The above snippet obtains the contents of the specified css file. To add security, it first verifies that the file name is not blank, ends in <code>.css</code>, and that it is located in the current directory. Feel free to edit the last setting as necessary by removing:</p>
<pre><code>strpos( $file, '/' ) !== false</code></pre>
<p>To complete our CSS minifier, all we have to do is call <code>minify</code> on the obtained content and then print it:</p>
<pre><code>echo minify( $content );</code></pre>
<p>Voila! You now have a fully functioning CSS minifier in minimal code. In addition, the formatting of your code stays 100% in-tact. All you need to do is edit the CSS file that you pass to <code>minify.php</code> in order to make changes.</p>
<p>Here is a simple copy-paste version of our code:</p>
<pre><code>&lt;?php
header( "Content-type: text/css" );

$file = isset( $_GET[ 'css' ] ) ? $_GET[ 'css' ] : '';
if( !file || array_pop( split( '\.', $file ) ) != 'css' || strpos( $file, '/' ) !== false )
	die( 'Invalid Parameters' );

$content = @file_get_contents( $file );
echo minify( $content );

function minify( $css ) {
	$css = preg_replace( '#\s+#', ' ', $css );
	$css = preg_replace( '#/\*.*?\*/#s', '', $css );
	$css = str_replace( '; ', ';', $css );
	$css = str_replace( ': ', ':', $css );
	$css = str_replace( ' {', '{', $css );
	$css = str_replace( '{ ', '{', $css );
	$css = str_replace( ', ', ',', $css );
	$css = str_replace( '} ', '}', $css );
	$css = str_replace( ';}', '}', $css );

	return trim( $css );
}
?&gt;</code></pre>
<p>Thanks for stopping by!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/css-minifier/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Alternate Color Schemes Using PHP</title>
		<link>http://www.lateralcode.com/alternate-colors-php/</link>
		<comments>http://www.lateralcode.com/alternate-colors-php/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 11:00:14 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1188</guid>
		<description><![CDATA[One great use for PHP is alternate content depending on different inputs. In this article, we will show how to serve up alternately colored style sheets via PHP. Disclaimer: This makes use of CSS variables, over which there has been much debate. This article will not discuss whether one should or should not use CSS [...]]]></description>
			<content:encoded><![CDATA[<p>One great use for PHP is alternate content depending on different inputs. In this article, we will show how to serve up alternately colored style sheets via PHP.</p>
<p>Disclaimer: This makes use of CSS variables, over which there has been much debate. This article will not discuss whether one should or should not use CSS variables, only present a way to use them.</p>
<p>First, the call in the HTML will no longer call a CSS file, but a PHP file.</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" file="styles.css" /&gt;</code></pre>
<p>to</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" file="styles.php?color=green" /&gt;</code></pre>
<p>Of course, <code>color</code> can be any nomial you wish, and <code>green</code> can be any color you wish, or even the name of a color scheme, such as <code>hotlava</code>.</p>
<p><span id="more-1188"></span></p>
<p>Now we move on to the CSS file. For the purposes of demonstration, we will be using the following sample CSS file:</p>
<pre><code>
body {
	background: #7BA05B;
}
#header {
	background: url(lush-forest.jpg);
}
#content {
	background: #FFFFFF;
	color: #465945;
}
</code></pre>
<p>First, if you haven’t already, change the extension of your CSS file to <code>.php</code>. For example, <code>styles.css</code> would become <code>styles.php</code></p>
<p>Here is a very important step; don’t omit this. At the top of your new PHP file, add this line:</p>
<pre><code>&lt;?php header("Content-type: text/css"); ?&gt;</code></pre>
<p>This makes the server send the page as CSS. If you do not add this line, it will default to sending as HTML, and your browser will interpret it as this, thus leaving your actual page CSS-less.</p>
<p>The next step is to define some color schemes. For example, let’s add in a red color scheme to our example CSS. The following should go between the <code>header</code> line and the beginning of your CSS.</p>
<pre><code>
&lt;?php
	$schemes = array (
		'green' => array (
			'header' => 'lush-forest.jpg',
			'page-bg' => '#7BA05B',
			'content-bg' => '#FFFFFF',
			'text' => '#465945'
			),
		'red' => array (
			'header' => 'flamin-lava.jpg',
			'page-bg' => '#FA8072',
			'content-bg' => '#FFFFFF',
			'text' => '#800000'
			)
		);
?&gt;
</code></pre>
<p>Now that we have defined the schemes, we need a way to figure out which scheme is being called for.</p>
<pre><code>
/*
 * Because the variable is being specified in the request URL
 * we can use the GET array. You can replace 'color' with
 * whatever you have named your variable
 */
$scheme-name = $_GET['color'];
$scheme = $schemes[$scheme-name];
// If the specified scheme does not exist, default to 'green'
if ( !$scheme ) { $scheme = $schemes['green']; }
</code></pre>
<p>Then, in the CSS part, we replace the colors with PHP <code>echo</code>s</p>
<pre><code>
body {
	background: &lt;?php echo $scheme['page-bg']; ?&gt;;
}
#header {
	background: url(&lt;?php echo $scheme['header']; ?&gt;);
}
#content {
	background: &lt;?php echo $scheme['content-bg']; ?&gt;;
	color: &lt;?php echo $scheme['text']; ?&gt;;
}
</code></pre>
<p>So in whole, the file would look like this:</p>
<pre><code>
&lt;?php
	header("Content-type: text/css");
	$schemes = array (
		'green' => array (
			'header' => 'lush-forest.jpg',
			'page-bg' => '#7BA05B',
			'content-bg' => '#FFFFFF',
			'text' => '#465945'
			),
		'red' => array (
			'header' => 'flamin-lava.jpg',
			'page-bg' => '#FA8072',
			'content-bg' => '#FFFFFF',
			'text' => '#800000'
			)
		);
	$scheme-name = $_GET['color'];
	$scheme = $schemes[$scheme-name];
	if ( !$scheme ) { $scheme = $schemes['green']; }
?&gt;
body {
	background: &lt;?php echo $scheme['page-bg']; ?&gt;;
}
#header {
	background: url(&lt;?php echo $scheme['header']; ?&gt;);
}
#content {
	background: &lt;?php echo $scheme['content-bg']; ?&gt;;
	color: &lt;?php echo $scheme['text']; ?&gt;;
}
</code></pre>
<p>Through this, it is possible to serve up different color schemes from the same file. Stay tuned for our next article in which we will explain how to &#8220;remember&#8221; the user’s preference and serve up the designated color scheme.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/alternate-colors-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>12 Brilliant CSS Frameworks</title>
		<link>http://www.lateralcode.com/12-brilliant-css-frameworks/</link>
		<comments>http://www.lateralcode.com/12-brilliant-css-frameworks/#comments</comments>
		<pubDate>Wed, 20 May 2009 14:30:24 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=967</guid>
		<description><![CDATA[CSS Frameworks are extremely helpful and time-saving. When you are making a website, do you really want to spend a bunch of time figuring out positions and making print stylesheets? CSS Frameworks save you time on everything from resetting styles to common things that Internet Explorer break again and again. 1. blueprint 2. YAML 3. [...]]]></description>
			<content:encoded><![CDATA[<p>CSS Frameworks are extremely helpful and time-saving. When you are making a website, do you really want to spend a bunch of time figuring out positions and making print stylesheets? CSS Frameworks save you time on everything from resetting styles to common things that Internet Explorer break again and again.</p>
<h3>1. <a href="http://www.blueprintcss.org/">blueprint</a></h3>
<p><a href="http://www.blueprintcss.org/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/001.jpg" alt="blueprint" class="list-post-img" /></a></p>
<p><span id="more-967"></span></p>
<h3>2. <a href="http://www.yaml.de/en/">YAML</a></h3>
<p><a href="http://www.yaml.de/en/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/002.jpg" alt="YAML" class="list-post-img" /></a></p>
<h3>3. <a href="http://developer.yahoo.com/yui/grids/">YUI Grids CSS</a></h3>
<p><a href="http://developer.yahoo.com/yui/grids/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/003.jpg" alt="YUI Grids" class="list-post-img" /></a></p>
<h3>4. <a href="http://960.gs/">960 Grid System</a></h3>
<p><a href="http://960.gs/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/004.jpg" alt="960 Grid System" class="list-post-img" /></a></p>
<h3>5. <a href="http://devkick.com/lab/tripoli/">Tripoli</a></h3>
<p><a href="http://devkick.com/lab/tripoli/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/005.jpg" alt="Tripoli" class="list-post-img" /></a></p>
<h3>6. <a href="http://sencss.kilianvalkhof.com/">SenCSs</a></h3>
<p><a href="http://sencss.kilianvalkhof.com/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/006.jpg" alt="SenCSs" class="list-post-img" /></a></p>
<h3>7. <a href="http://docs.jquery.com/UI/Theming/API">jQuery UI CSS Framework</a></h3>
<p><a href="http://docs.jquery.com/UI/Theming/API"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/007.jpg" alt="jQuery UI CSS Framework" class="list-post-img" /></a></p>
<h3>8. <a href="http://code.google.com/p/logicss/">logicss</a></h3>
<p><a href="http://code.google.com/p/logicss/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/008.jpg" alt="logicss" class="list-post-img" /></a></p>
<h3>9. <a href="http://layout.constantology.com/">___layouts</a></h3>
<p><a href="http://layout.constantology.com/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/009.jpg" alt="___layouts" class="list-post-img" /></a></p>
<h3>10. <a href="http://elements.projectdesigns.org/">Elements</a></h3>
<p><a href="http://elements.projectdesigns.org/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/010.jpg" alt="Elements" class="list-post-img" /></a></p>
<h3>11. <a href="http://bluetrip.org/">BlueTrip</a></h3>
<p><a href="http://bluetrip.org/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/011.jpg" alt="BlueTrip" class="list-post-img" /></a></p>
<h3>12. <a href="http://unobtrusivecss.com/">Unobtrusive CSS</a></h3>
<p><a href="http://unobtrusivecss.com/"><img src="http://www.lateralcode.com/wp-content/uploads/css-frame/012.jpg" alt="Unobtrusive CSS" class="list-post-img" /></a></p>
<p>Hopefully these will save you time and frustration!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/12-brilliant-css-frameworks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Solid CSS List Posts</title>
		<link>http://www.lateralcode.com/5-solid-css-list-posts/</link>
		<comments>http://www.lateralcode.com/5-solid-css-list-posts/#comments</comments>
		<pubDate>Thu, 07 May 2009 14:20:08 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=945</guid>
		<description><![CDATA[CSS is arguably the second most important element in modern web development, with the first being HTML. After all, without CSS, HTML would just be unformatted and hard-to-read. Therefore, it is always good to know more CSS Tricks and Techniques. Thus, I present to you 5 very solid CSS List Posts. 1. Definitive List of [...]]]></description>
			<content:encoded><![CDATA[<p>CSS is arguably the second most important element in modern web development, with the first being HTML. After all, without CSS, HTML would just be unformatted and hard-to-read. Therefore, it is always good to know more CSS Tricks and Techniques. Thus, I present to you 5 very solid CSS List Posts.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/css.png" alt="CSS" title="CSS" width="300" height="150" class="aligncenter size-full wp-image-946" /></p>
<p><span id="more-945"></span></p>
<h3>1. <a href="http://www.w3avenue.com/2009/04/29/definitive-list-of-css-frameworks-pick-your-style/">Definitive List of CSS Frameworks</a></h3>
<p>CSS Frameworks are meant to be used to save precious development time. However, not all of them are right for everyone. Find out about them at this resource.</p>
<h3>2. <a href="http://www.antsmagazine.com/css-tricks-all/">22 Most Amazing Css Tricks</a></h3>
<p>Here you can find a collection of many things you can do with CSS, ranging from things you may use regularly to things that you might never have thought of doing.</p>
<h3>3. <a href="http://www.noupe.com/css/47-excellent-ajax-css-forms.html">47+ Excellent Ajax CSS Forms</a></h3>
<p>Noupe presents a huge amount of different ways you can style Forms using CSS.</p>
<h3>4. <a href="http://designreviver.com/tutorials/10-excellent-css-tips-and-tutorials/">10 Excellent CSS Tips and Tutorials</a></h3>
<p>These are just things that everyone in web development should know, because they come in handy very often.</p>
<h3>5. <a href="http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/">The Mystery Of CSS Sprites: Techniques, Tools And Tutorials</a></h3>
<p>CSS Sprites are quite undoubtedly one of the coolest CSS tricks you can use to optimize your site. The sheer number of examples, tutorials, and generators that this post provides makes it very much worth reading.</p>
<p>I hope that these have helped you grow as a web developer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/5-solid-css-list-posts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
