<?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>Not Just a Hat Rack &#187; CSS</title>
	<atom:link href="http://notjustahatrack.com/posts/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://notjustahatrack.com</link>
	<description>Development, design, etc.</description>
	<lastBuildDate>Mon, 18 Apr 2011 16:05:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Image Usage for Developers</title>
		<link>http://notjustahatrack.com/posts/image-usage-for-developers/</link>
		<comments>http://notjustahatrack.com/posts/image-usage-for-developers/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 18:54:25 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Must-Read/Reference]]></category>

		<guid isPermaLink="false">http://notjustahatrack.com/?p=114</guid>
		<description><![CDATA[Another must-read is the image optimization series from Stoyan Stefanov and Yahoo. Before reading those articles, I used PNG fixes indiscriminately, employed GIFs way too much, didn&#8217;t spend a whole lot of time thinking about the optimum image type when slicing a mockup, and certainly never thought of compressing images beyond Photoshop&#8217;s &#8220;save for web&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Another must-read is the <a href="http://yuiblog.com/blog/2008/10/29/imageopt-1/">image optimization series</a> from Stoyan Stefanov and Yahoo.  Before reading those articles, I used PNG fixes indiscriminately, employed GIFs way too much, didn&#8217;t spend a whole lot of time thinking about the optimum image type when slicing a mockup, and certainly never thought of compressing images beyond Photoshop&#8217;s &#8220;save for web&#8221; feature.  The first article in the series, <a href="http://yuiblog.com/blog/2008/10/29/imageopt-1/">The Importance of Images</a>, along with the prevalence of <a href="http://developer.yahoo.com/yslow/">Yahoo&#8217;s YSlow</a>, and more recently <a href="http://code.google.com/speed/page-speed/">Google&#8217;s Page Speed</a>, made me realize just how much image optimization actually matters to page performance.  I figured I would give you my take on the tips in the series, and thoughts on just how to handle difficult, common, transparency cases.  </p>
<p><span id="more-114"></span></p>
<h3>The Right Image Format</h3>
<p>The image optimization series does an excellent job detailing <a href="http://yuiblog.com/blog/2008/11/04/imageopt-2/">which file format to use</a>, and I suggest reading it (especially for the lossy, non-lossy comments), but here&#8217;s their summary:</p>
<blockquote>
<ul>
<li>JPEG is the format for photos.</li>
<li>GIF is the format for animations.</li>
<li>PNG8 is the format for everything else — icons, buttons, backgrounds, graphs…you name it.</li>
</ul>
</blockquote>
<p>After implementing these strategies for a bunch of builds, here&#8217;s my take:</p>
<ul>
<li>JPEGs for photos or images with tons of colors</li>
<li>PNG24 when you <em>really need</em> consistent alpha transparency</li>
<li>PNG8 for everything else</li>
</ul>
<p>The only difference here is that PNG24 definitely still has a place (oh, and really how often do you use animated GIFs?).  The case they mention in which you have to use PNG24 (&#8220;When most of the image is semi-transparent&#8221;) is actually more common than they would leave you to believe.  So how do you handle those cases?</p>
<h3>Transparency and PNG Fixes</h3>
<p>To handle transparent PNGs, <strong>do not use a JavaScript PNG fix</strong>.  Instead, realize what those fixes do, and then actually apply the fix when and where you need it.  The problem with PNG fixes in general is that they typically offer a blanket solution that affects every PNG on the site.  You don&#8217;t want to be applying a alpha filter to a PNG8 that doesn&#8217;t have transparency, so there&#8217;s a lot of wasted effort.  Not to mention the fact that these filters can be <a href="http://yuiblog.com/blog/2008/12/08/imageopt-5/">extremely taxing on the browser</a>.  There&#8217;s a simple CSS solution that can be added to an IE6-only stylesheet (assume #some-element already has a background applied):</p>
<pre><code>
#some-element {
	background: none;
	filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.png', sizingMethod='crop');
}
</code></pre>
<p>That&#8217;s it!  There&#8217;s also a <a href="http://yuiblog.com/blog/2008/12/08/imageopt-5/">VML fix</a>, although the extra markup typically isn&#8217;t worth the better performance.  Either way, the take-away is to apply the fix on a case by case basis, not with a blanket JavaScript add-on.</p>
<h3>Compression</h3>
<p>There&#8217;s a number of add-ons and/or tools online that will reduce the size of your images quickly and efficiently.  The aforementioned <a href="http://developer.yahoo.com/yslow/">YSlow</a> and <a href="http://code.google.com/speed/page-speed/">Google Page Speed</a> are extremely easy to use if you have those add-ons.  A new entrant is <a href="http://www.gracepointafterfive.com/punypng/">punypng</a>, which touts its better performance over the Yahoo and Google offerings.  Regardless, all tools offer bulk uploads, so after a site build, there&#8217;s no reason not to run your pages through these tools and update images that can be compressed.</p>
<p><br/><br />
If nothing else, I hope developers everywhere can remember a couple of things:</p>
<ul>
<li>Think about the optimal file format when saving an image</li>
<li>Don&#8217;t use GIFs (unless they are animated&#8230; but c&#8217;mon)</li>
<li>Don&#8217;t use a blanket PNG fix</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://notjustahatrack.com/posts/image-usage-for-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced CSS Selectors You Can Actually Use</title>
		<link>http://notjustahatrack.com/posts/advanced-css-selectors-you-can-actually-use/</link>
		<comments>http://notjustahatrack.com/posts/advanced-css-selectors-you-can-actually-use/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 16:39:41 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://notjustahatrack.com/?p=69</guid>
		<description><![CDATA[Smashing Magazine had a great article the other day on Taming Advanced CSS Selectors. The article is comprehensive and well-worth a read, but it also contains a bunch of information about selectors you won&#8217;t realistically be able to use for quite some time (mostly due to poor browser support). However, there are a good number [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.smashingmagazine.com/">Smashing Magazine</a> had a great article the other day on <a href="http://www.smashingmagazine.com/2009/08/17/taming-advanced-css-selectors/">Taming Advanced CSS Selectors</a>.  The article is comprehensive and well-worth a read, but it also contains a bunch of information about selectors you won&#8217;t realistically be able to use for quite some time (mostly due to poor browser support).  However, there are a good number of selectors detailed that you can, and probably should be taking advantage of immediately.  After the jump I listed some of the advanced selectors that I use, and how and where I use them.  If all you want is a quick reference, don&#8217;t listen to me, bookmark the excellent <a href="http://www.quirksmode.org/css/contents.html">QuirksMode CSS compatibility chart</a>.</p>
<p><span id="more-69"></span></p>
<h3>(Advanced) Attribute Selectors</h3>
<pre><code>
input[type="text"] { }
a[href$=".pdf"] { }
div[id*="foo"] { }
</code></pre>
<p>How many times have you added a class to text input elements just so you could style them?  How about to external, or document links so you could have a hook there as well?  Well with attribute selectors you don&#8217;t need that extra HTML cruft.  Just make sure you aren&#8217;t using them for function-critical layout, because they won&#8217;t be recognized by IE6.  In general, they are very useful for selecting:</p>
<ul>
<li>Inputs by type (text, checkbox, radio, etc.)</li>
<li>Links by href (external links, document types, etc.)</li>
<li>IDs or classes that contain a specific value</li>
</ul>
<h3>Pseudo-classes</h3>
<pre><code>
ul li:hover { }
input:focus { }
ul li:first-child { }
</code></pre>
<p>Some pseudo-classes (namely hover, active, link, and visited) have been in use for quite some time.  Focus is often overlooked (it gets removed by some CSS resets), but should be declared because of its benefit to accessibility for those that employ keyboard navigation.  Before and after have marginal uses, especially with clearing hacks.  First-child is definitely useful, and should probably be used more than it is currently (you don&#8217;t have to add &#8220;last&#8221; or &#8220;first&#8221; classes to your HTML).  To summarize, use:</p>
<ul>
<li>Link, hover, visited, active for links</li>
<li>Hover and active for other elements, for non-function critical styling (issues with IE compatibility)</li>
<li>Focus, especially if you overwrote focus styles in a CSS reset</li>
<li>First-child</li>
</ul>
<h3>Child Selectors &amp; Combinators</h3>
<p>In my opinion, child selectors and combinators only offer marginal benefit.  For the most part you can accomplish the same thing with carefully crafted specificity rules.  Regardless, since the only browser that doesn&#8217;t support them is IE6, feel free to use them in most cases.  </p>
<p><br/></p>
<p>That&#8217;s it!  To save yourself the headache, don&#8217;t worry about memorizing other added selectors in CSS3 just yet.  General IE support is extremely lacking, and there&#8217;s not a whole lot of value in a selector that isn&#8217;t recognized by the majority of your potential audience.</p>
]]></content:encoded>
			<wfw:commentRss>http://notjustahatrack.com/posts/advanced-css-selectors-you-can-actually-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benefits of CSS Sprites</title>
		<link>http://notjustahatrack.com/posts/benefits-of-css-sprites/</link>
		<comments>http://notjustahatrack.com/posts/benefits-of-css-sprites/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 19:55:24 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://notjustahatrack.com/?p=29</guid>
		<description><![CDATA[I haven&#8217;t used CSS Sprites a lot in the past, but when I finally started to, the benefits were immediately visible. I won&#8217;t go into detail about how to use this technique as it&#8217;s been covered in detail. I will, however, try to elaborate on just how much of a benefit CSS Sprites can offer. [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t used <a href="http://www.alistapart.com/articles/sprites">CSS Sprites</a> a lot in the past, but when I finally started to, the benefits were immediately visible.  I won&#8217;t go into detail about how to use this technique as it&#8217;s been <a href="http://www.google.com/search?q=css+sprites">covered in detail</a>.  I will, however, try to elaborate on just how much of a benefit CSS Sprites can offer.<span id="more-29"></span></p>
<h3>Page Load Speed</h3>
<p>The first immediately noticeable benefit of CSS Sprite usage is the faster loading time of your page.  It may seem counterintuitive, because you would think that the alternative (having many smaller images vs. sometimes extra images for Sprites) would be smaller in total size, but that&#8217;s not true.  There&#8217;s a small amount of extra information in each individual image you use on your site, so depending on the number of images you may end up actually loading less when all is said and done.</p>
<p>Also, one of Yahoo&#8217;s best practices for reducing page load time is to <a href="http://developer.yahoo.com/performance/rules.html#num_http">minimize HTTP requests</a>.  Using the Sprites technique does just that, reduces HTTP requests by combining images in a single file.  CSS Sprites are specifically mentioned in the same Yahoo article as a method to reduce image requests.</p>
<h3>Accessibility</h3>
<p>Depending on your alternative technique, using CSS Sprites could greatly increase the accessibility of your pages.  Let&#8217;s assume we have the following navigation:</p>
<p><img class="example" src="/lib/images/example-navigation.jpg" alt="Navigation Example" /></p>
<p>&#8230;and we want each element to light up on hover:</p>
<p><img class="example" src="/lib/images/example-navigation-on.jpg" alt="Navigation Example" /></p>
<p>You could use individual images for each navigation element, and then switch them out with the latter treatment using JavaScript on hover.  Your HTML would look something like this:</p>
<pre><code>
...
&lt;img src=&quot;nav2.jpg&quot; onmouseover=&quot;changeMe(this);&quot; /&gt;
&lt;img src=&quot;nav3.jpg&quot; onmouseover=&quot;changeMe(this);&quot; /&gt;
&lt;img src=&quot;nav4.jpg&quot; onmouseover=&quot;changeMe(this);&quot; /&gt;
...
</code></pre>
<p>But what happens if a user&#8217;s browser doesn&#8217;t support JavaScript?  Or CSS?  Or images?  Using CSS Sprites, your HTML code could look like this:</p>
<pre><code>
&lt;ul id=&quot;navigation&quot;&gt;
	&lt;li id=&quot;nav1&quot;&gt;&lt;a href=&quot;nav1.html&quot;&gt;Nav 1&lt;/a&gt;&lt;/li&gt;
	&lt;li id=&quot;nav2&quot;&gt;&lt;a href=&quot;nav2.html&quot;&gt;Nav 2&lt;/a&gt;&lt;/li&gt;
	&lt;li id=&quot;nav3&quot;&gt;&lt;a href=&quot;nav3.html&quot;&gt;Nav 3&lt;/a&gt;&lt;/li&gt;
	...
</code></pre>
<p>&#8230;which would degrade much better in older or alternate browsers.</p>
<h3>Time</h3>
<p>CSS Sprites are easier than the alternative.  Slicing up and dealing with multiple images is time-consuming, as is any necessary JavaScript image manipulation.  Plus, there are even several tools that will generate Sprites for you:</p>
<ul>
<li><a href="http://spritegen.website-performance.org/">Website Performance CSS Sprite Generator</a></li>
<li><a href="http://www.csssprites.com/">CSS Sprites Generator</a></li>
<li><a href="http://smartsprites.osinski.name/">SmartSprites</a></li>
</ul>
<p>And these are just some of the benefits of this technique.  If you haven&#8217;t at least tried working with CSS Sprites I highly recommend it.</p>
]]></content:encoded>
			<wfw:commentRss>http://notjustahatrack.com/posts/benefits-of-css-sprites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Color Selector Script</title>
		<link>http://notjustahatrack.com/posts/simple-color-selector-script/</link>
		<comments>http://notjustahatrack.com/posts/simple-color-selector-script/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 18:20:11 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://notjustahatrack.com/?p=25</guid>
		<description><![CDATA[Recently I was tasked with creating a form that allowed the user to specify a color selection from a limited number of options. There are numerous scripts that display a popup color selection on the web, but I needed one that was limited to just a few colors. So I wrote a script that makes [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was tasked with creating a form that allowed the user to specify a color selection from a limited number of options.  There are <a href="http://www.google.com/search?q=colorpicker">numerous scripts that display a popup color selection</a> on the web, but I needed one that was limited to just a few colors.  So I wrote a script that makes all text inputs in a form with the class name of &#8220;color&#8221; display a simple color selection box.  Here&#8217;s what it looks like in action:<span id="more-25"></span></p>
<form name="testForm" action="test.php">
<input type="text" class="color" />
<input type="text" class="color" />
<input type="text" class="color" />
</form>
<link rel="stylesheet" href="/lib/styles/colorPicker.css" type="text/css" media="screen" />
<p><script type="text/javascript" src="/lib/js/colorPicker.js"></script></p>
<h3>Implementation</h3>
<p>Download and store the JavaScript and CSS:</p>
<p><a class="compressed" href="/lib/scripts/colorPicker.zip">Simple Color Selector (.zip)</a><br />
<a class="compressed" href="/lib/scripts/colorPicker.tar.gz">Simple Color Selector (.tar.gz)</a></p>
<p>Then add the following references to your page:</p>
<pre><code>
&lt;link rel=&quot;stylesheet&quot; href=&quot;/lib/styles/colorPicker.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/lib/js/colorPicker.js&quot;&gt;&lt;/script&gt;
</code></pre>
<h3>Usage</h3>
<p>The script creates the color table and assigns click events dynamically, so all you have to do is include the word &#8220;color&#8221; in text input classes like so:</p>
<pre><code>
&lt;input type=&quot;text&quot; class=&quot;color&quot; /&gt;
</code></pre>
<p>By default, the script displays the following colors: White (blank), black, grey, red, yellow, and blue.  You can easily replace the default colors by adding the following after you reference the main JavaScript file:</p>
<pre><code>
&lt;script type=&quot;text/javascript&quot;&gt;
	colorPicker.colors = new Array('', 'black', 'gray', 'red', 'yellow', 'blue', 'teal');
&lt;/script&gt;
</code></pre>
<p>And that&#8217;s it!  The user&#8217;s selection will be hidden within the text inputs, so upon submission you&#8217;ll be able to work with the resulting data.  Feel free to modify functionality within the JavaScript file, or style within the CSS file.</p>
]]></content:encoded>
			<wfw:commentRss>http://notjustahatrack.com/posts/simple-color-selector-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quotations and Multiple Background Images</title>
		<link>http://notjustahatrack.com/posts/quotations-and-multiple-background-images/</link>
		<comments>http://notjustahatrack.com/posts/quotations-and-multiple-background-images/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 15:28:22 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[(X)HTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://notjustahatrack.com/?p=24</guid>
		<description><![CDATA[The HTML specification suggests &#8220;a mechanism for inserting quotation marks before and after a quotation delimited by BLOCKQUOTE in a manner appropriate to the current language context and the degree of nesting of quotations.&#8221; From a usability standpoint, it makes sense to indicate as clearly as possible that everything within a &#60;blockquote&#62; element is a [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.w3.org/TR/html401/struct/text.html#h-9.2.2">HTML specification</a> suggests &#8220;a mechanism for inserting quotation marks before and after a quotation delimited by <code>BLOCKQUOTE </code> in a manner appropriate to the current language context and the degree of nesting of quotations.&#8221; From a usability standpoint, it makes sense to indicate as clearly as possible that everything within a <code>&lt;blockquote&gt;</code> element is a quotation.  To do so, I wanted to add quotation marks, clear indentation, and even a slightly different color to differentiate.  Here&#8217;s what the result looks like in Firefox:<span id="more-24"></span></p>
<p><img src="/lib/images/example-blockquote.gif" alt="Styled Blockquote Example" style="border: 1px solid #ccc;" /></p>
<p>I wanted to accomplish the look strictly with CSS and standards-based XHTML, which initially proved difficult because the lack of <a href="http://www.w3.org/TR/REC-CSS2/">CSS2</a> support for multiple background images.  If more browsers supported <a href="http://www.w3.org/TR/css3-roadmap/">CSS3</a> and it&#8217;s support for multiple background images (only Safari does now), then I could have just used a quote background image for the top left and the bottom right.  I also couldn&#8217;t use one wide background image that contained both quotations because the width and the height of the box would always be unknown.</p>
<p>Then I found an <a href="http://virtuelvis.com/gallery/css/rounded/">interesting tutorial</a> that uses the <a href="http://www.w3.org/TR/REC-CSS2/selector.html#before-and-after">CSS2 pseudo element</a> <code>:after</code> to add additional background images after content.  With a similar method, I was able to apply quotation marks before and after the <code>&lt;blockquote&gt;</code> content via CSS:</p>
<pre><code>
blockquote {
	background: url(quote-open.gif) no-repeat;
	color: #666;
	margin: 0 0 1em 0;
	padding: 0 50px 0 45px;
}
blockquote:after {
	background: url(quote-close.gif) no-repeat right;
	content: '';
	display: block;
	height: 25px;
	margin: -2.25em -40px 0 0;
}
</code></pre>
<p>Works like a charm in browsers that support CSS2, but in IE the <code>:after</code> content isn&#8217;t rendered.  For those browsers, I&#8217;m OK with the second quote not showing up, so I just added some IE-only style to remove the extra padding on the right:</p>
<pre><code>
blockquote {
	padding-right: 0;
}
</code></pre>
<p>That&#8217;s it!  No fancy JavaScript or extraneous HTML tags needed.  The result:</p>
<blockquote><p>
We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness. &#8211;That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed, &#8211;That whenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness. Prudence, indeed, will dictate that Governments long established should not be changed for light and transient causes; and accordingly all experience hath shewn, that mankind are more disposed to suffer, while evils are sufferable, than to right themselves by abolishing the forms to which they are accustomed.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://notjustahatrack.com/posts/quotations-and-multiple-background-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

