<?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>simonsmith.io &#187; OOCSS</title>
	<atom:link href="http://simonsmith.io/tag/oocss/feed/" rel="self" type="application/rss+xml" />
	<link>http://simonsmith.io</link>
	<description>Portfolio and blog of a London based front-end web developer</description>
	<lastBuildDate>Wed, 27 Feb 2013 23:09:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Extending CSS classes in LESS</title>
		<link>http://simonsmith.io/extending-css-classes-in-less/</link>
		<comments>http://simonsmith.io/extending-css-classes-in-less/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 16:44:59 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[LESS]]></category>
		<category><![CDATA[OOCSS]]></category>
		<category><![CDATA[Twitter Bootstrap]]></category>

		<guid isPermaLink="false">http://simonsmith.io/?p=251</guid>
		<description><![CDATA[If you hadn&#8217;t noticed, CSS preprocessors are all the rage these days, and with good reason. They provide all manner of nice shortcuts and generally make your life easier. LESS is my weapon of choice and Twitter Bootstrap has helped it&#8217;s popularity grow amongst developers. Another great thing that has...]]></description>
				<content:encoded><![CDATA[<p>If you hadn&#8217;t noticed, CSS preprocessors are all the rage these days, and with good reason. They provide all manner of nice shortcuts and generally make your life easier. <a href="http://lesscss.org/">LESS</a> is my weapon of choice and <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a> has helped it&#8217;s popularity grow amongst developers.</p>
<p>Another great thing that has come about from Bootstrap is their use of class names to organise the styling of the framework. I&#8217;m sure the argument about exclusively using CSS classes could rage on but I&#8217;ve found on large sites with multiple developers it has been a great way to keep code modular and easy to change.</p>
<h2>LESS is more</h2>
<p>To give an example, Bootstrap tends to use a &#8216;base&#8217; class and the build from it, like this:</p>
<pre class="prettyprint linenums">&lt;ul class="nav nav-tabs nav-stacked"&gt;
&lt;/ul&gt;</pre>
<p>I&#8217;ve come to enjoy this pattern, because when combined with LESS you can create some really nice, modular blocks of CSS. I&#8217;ll demonstrate with some button classes I have been writing for a design at work:</p>
<pre class="prettyprint linenums">.btn {
    font-size: 14px;
    background-color: #a1a1a1;

    span {
        background-repeat: no-repeat;
    }

    &amp;.btn-rounded {
        .border-radius(5px);
    }

    &amp;.btn-pressed {
        .box-shadow(-1px 1px 2px 0 rgba(0, 0, 0, .1));
    }

    &amp;.btn-prev {
        text-align: left;

        span {
            background-image: url("@{imgPath}buttons/arrow-left.png");
            background-position: left center;
            padding-left: 15px;
        }
    }

    &amp;.btn-next {
        text-align: right;

        span {
            background-image: url("@{imgPath}buttons/arrow-right.png");
            background-position: right center;
            padding-right: 15px;

        }
    }
}</pre>
<p>By using the <code>&amp;</code> combinator we can keep the code nested beneath the <code>.btn</code> base class keeping the code easy to read and the resulting CSS is targeted just to the <code>.btn</code> class which is exactly what we want.</p>
<h2>Overriding</h2>
<p>In the example above I have two classes to control whether the button should have an arrow facing left or right. That&#8217;s great, but now I want to make a larger version of the button which involves overriding the current <code>.btn-prev</code> and <code>.btn-next</code> with new image paths:</p>
<pre class="prettyprint linenums">    &amp;.btn-large {
        @padding: 15px;
        font-size: 16px;
        padding-left: @padding;
        padding-right: @padding;

        &amp;.btn-prev {
           span {
               background-image: url("@{imgPath}buttons/arrow-left-large.png");
               background-position: left 1px;
               padding-left: 20px;
               padding-right: 10px;
           }
        }

        &amp;.btn-next {
           span {
               background-image: url("@{imgPath}buttons/arrow-right-large.png");
               background-position: right 1px;
               padding-left: 8px;
               padding-right: 20px;
           }
        }
    }</pre>
<p>Now when I add a class of <code>.btn-large</code> to my <code>&lt;button/&gt;</code> element the <code>.btn-prev</code> and <code>.btn-next</code> I had already defined will be overridden by the two new definitions.</p>
<p>Once you start to create a little collection of classes like this, it becomes an absolute breeze to alter your designs by just swapping out different CSS classes and modifying existing ones just by adding additional classes.</p>
<p>However, like all things it can be easy to get carried away. So keep a sharp eye on your CSS output and ensure you don&#8217;t create needless selectors just because the nesting looks nice in your LESS files!</p>
]]></content:encoded>
			<wfw:commentRss>http://simonsmith.io/extending-css-classes-in-less/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
