<?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>Joseph Scott &#187; css</title>
	<atom:link href="http://josephscott.org/archives/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://josephscott.org</link>
	<description></description>
	<lastBuildDate>Mon, 06 Sep 2010 17:44:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://josephscott.org/?pushpress=hub'/>
		<item>
		<title>Database Powered CSS in WordPress Themes</title>
		<link>http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/</link>
		<comments>http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:59:04 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[parse_request]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp_head]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=1869</guid>
		<description><![CDATA[A popular ability in WordPress themes is to add custom CSS driven by options. This brings up a common question, how should the theme inject custom CSS? I&#8217;ll outline three different approaches on how to do this. These aren&#8217;t new, &#8230; <a href="http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A popular ability in WordPress themes is to add custom CSS driven by options.  This brings up a common question, how should the theme inject custom CSS?  I&#8217;ll outline three different approaches on how to do this.  These aren&#8217;t new, many people have written about these; forums, blog posts, email lists and IRC.  I&#8217;m still seeing questions about this though, so I wanted to address this specific question with specific solutions.</p>
<p>For the purposes of code examples I&#8217;ll assume that you have an option called <code>my_background_color</code> and that you want to do something like this:</p>
<pre class="brush: css;">
body {
    background-color: &lt;?php echo $theme_opt['my_background_color']; ?&gt;
}
</pre>
<p>We&#8217;ll start with the simplest method.</p>
<h3>header.php</h3>
<p>Most themes have a <code>header.php</code> file that contains template code for the top of the HTML output.  This makes it easy to add custom CSS with options, just echo it out inside the HEAD section of the HTML:</p>
<pre class="brush: xml;">
&lt;style type='text/css'&gt;
body {
    background-color: &lt;?php echo $theme_opt['my_background_color']; ?&gt;
}
&lt;/style&gt;
</pre>
<p>The advantages to this approach is that it&#8217;s very simple, you already have a <code>header.php</code> so adding a few more lines doesn&#8217;t take much work.  The disadvantage is that this solution isn&#8217;t very flexible, if you have complex rules about when and how to include the CSS then your <code>header.php</code> file gets a lot extra &#8220;stuff&#8221; that may not need for every page.</p>
<p>If your needs are simple then this works great.  If not, I suggest using either wp_head or parse_request.</p>
<h3>wp_head</h3>
<p>Each theme calls a WordPress action at the end of the HTML HEAD section &#8211;  <a href="http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head">wp_head</a> &#8211; that can be used to include the custom CSS:</p>
<pre class="brush: php;">
&lt;?php
add_action( 'wp_head', 'my_custom_css_hook' );
function my_custom_css_hook( ) {
    # get theme options
?&gt;

&lt;style type='text/css'&gt;
body {
    background-color: &lt;?php echo $theme_opt['my_background_color']; ?&gt;
}
&lt;/style&gt;

&lt;?php
}
</pre>
<p>The only real difference between this approach and the previous one is that it&#8217;s less clutter in <code>header.php</code>.  Instead of having all that code in <code>header.php</code> it can be moved out to a separate file and WordPress will include it at runtime whenever the <code>wp_head</code> action fires.</p>
<h3>parse_request</h3>
<p>WordPress can provide your theme with custom URLs, these can turn around and serve up what ever you want, including CSS.  This technique takes a little bit more work, but provides the maximum degree of flexibility.  There are a couple steps to this one, first what you&#8217;ll need to have in <code>header.php</code>:</p>
<pre class="brush: xml;">
&lt;link rel='stylesheet' type='text/css' href=&quot;&lt;?php bloginfo( 'url' ); ?&gt;/?my-custom-content=css&quot; /&gt;
</pre>
<p>The <code>my-custom-content=css</code> just needs to be something unique to your theme so that it doesn&#8217;t conflict with plugins that might be using parse_request as well.</p>
<p>Next we need to tell WordPress how we want to handle this request:</p>
<pre class="brush: php;">
add_action( 'parse_request', 'my_custom_wp_request' );
function my_custom_wp_request( $wp ) {
    if (
        !empty( $_GET['my-custom-content'] )
        &amp;&amp; $_GET['my-custom-content'] == 'css'
    ) {
        # get theme options
        header( 'Content-Type: text/css' );
?&gt;

body {
    background-color: &lt;?php echo $theme_opt['my_background_color']; ?&gt;
}

&lt;?php
        exit;
    }
}
</pre>
<p>A few things in there that I want to point out.  Pay attention to line 8, this tells the browser what sort of content we are sending back.  In this case it was CSS, but it could have been JavaScript or anything else.  Also note that I didn&#8217;t add any cache related headers, it&#8217;s worth reading up on cache control in HTTP headers so that you know how that works.  Line 16 is also important, we don&#8217;t want WordPress attempting to do any further processing after we return the CSS so the right thing to do is exit as soon as possible.</p>
<p>And if you wanted to keep the CSS in a separate file ( <code>custom-css.php</code> for our example ) that looked more like a normal CSS file then the <code>my_custom_wp_request</code> function could look like:</p>
<pre class="brush: php;">
function my_custom_wp_request( $wp ) {
    if (
        !empty( $_GET['my-custom-content'] )
        &amp;&amp; $_GET['my-custom-content'] == 'css'
    ) {
        # get theme options
        header( 'Content-Type: text/css' );
        require dirname( __FILE__ ) . '/custom-css.php';
        exit;
    }
}
</pre>
<p>allowing your <code>custom-css.php</code> to look like:</p>
<pre class="brush: css;">
body {
    background-color: &lt;?php echo $theme_opt['my_background_color']; ?&gt;
}
</pre>
<p>basically just enough PHP to fill in the option blanks, other wise a normal looking CSS file.  I rather like this approach, it provides a nice degree of separation and control.</p>
<h3>Conclusion</h3>
<p>Now you have three methods for including database powered CSS in your WordPress theme.  I like using parse_request with the CSS in a separate file ( the last example ), for a little bit of extra work you get lots of flexibility and a nice layer of separation that makes managing the CSS portion easier.</p>
<p>Having any tips on how to improve on this?  <a href="#comments">Leave a comment below!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>CSS Border Radius Percentages and Elliptical Borders</title>
		<link>http://josephscott.org/archives/2010/01/css-border-radius-percentages-and-elliptical-borders/</link>
		<comments>http://josephscott.org/archives/2010/01/css-border-radius-percentages-and-elliptical-borders/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 02:09:52 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[internet-explorer]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=1814</guid>
		<description><![CDATA[When using CSS border radius I&#8217;ve always specified the radius in pixels (px), something like this: .round-box { border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; } This got me to wondering, does it support percentages as well? So I tried this: &#8230; <a href="http://josephscott.org/archives/2010/01/css-border-radius-percentages-and-elliptical-borders/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When using CSS border radius I&#8217;ve always specified the radius in pixels (px), something like this:</p>
<pre class="brush: css;">
.round-box {
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
}
</pre>
<p>This got me to wondering, does it support percentages as well?  So I tried this:</p>
<pre class="brush: css;">
.round-box {
    border-radius: 5%;
    -moz-border-radius: 5%;
    -webkit-border-radius: 5%;
}
</pre>
<p>This worked in Firefox 3.6 but not in Chrome.  Some searching around revealed the <a href="https://developer.mozilla.org/en/CSS:-moz-border-radius">Mozilla -moz-border-radius</a> page.  For border radius it specifically mentions that it supports <a href="https://developer.mozilla.org/en/CSS/length">length units</a> as well as percentages:</p>
<blockquote><p>
A percentage, relative to the width of the box (the percentage is relative to the width even when specifying the radius for a height).
</p></blockquote>
<p>That page also mentioned support for elliptical borders.  To do that you add another radius value separated by a slash:</p>
<pre class="brush: css;">
.round-box {
    border-radius: 15px / 50px;
    -moz-border-radius: 15px / 50px;
    -webkit-border-radius: 15px / 50px;
}
</pre>
<p>The elliptical border worked on Chrome as well.  If you bend this tight enough you can get pretty close to a circle.</p>
<p>I wanted Internet Explorer to add support for border radius before; now that I&#8217;ve got even more radius toys to play with I&#8217;m practically begging.  I&#8217;m sorry Internet Explorer users but I&#8217;m tired of various border hacks when there are simple and clean CSS methods available.</p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2010/01/css-border-radius-percentages-and-elliptical-borders/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
