<?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>TimKadlec.com &#187; CSS</title>
	<atom:link href="http://timkadlec.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://timkadlec.com</link>
	<description>A Wisconsin based web developer writing about the web.</description>
	<lastBuildDate>Tue, 13 Jul 2010 01:30:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Developing Smarter with Progressive Enhancement</title>
		<link>http://timkadlec.com/2009/06/developing-smarter-with-progressive-enhancement/</link>
		<comments>http://timkadlec.com/2009/06/developing-smarter-with-progressive-enhancement/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[progressive enhancement]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/developing-smarter-with-progressive-enhancement-2/</guid>
		<description><![CDATA[It is alright if your site doesn't look exactly the same in every browser. Getting clients to accept that fact is important because it can save them both time and money (not to mention save you a few headaches).]]></description>
			<content:encoded><![CDATA[<p>Progressive enhancement is not only a smart idea, but it&#8217;s the right idea for anyone looking to produce cost-effective websites. It is alright if your site doesn&#8217;t look exactly the same in every browser. In fact, because of factors like font rendering, it&#8217;s impossible to maintain the exact same appearance across all browsers. Getting clients to accept that fact is important because it can save them both time and money (not to mention save you a few headaches).</p>
<p>Let&#8217;s take an example. Let&#8217;s say that our client, Great Sprockets Inc., wants a design with a few rounded corners and semi-transparent backgrounds sprinkled in. We decide not to use progressive enhancement. Everybody should get these rounded corners and semi-transparent backgrounds.</p>
<p>So, we oblige. We create some 24-bit PNGs for the backgrounds. IE6 doesn&#8217;t support PNG24 transparency natively, so we add in a call to a script to fix that. We create a few images for the rounded corners, add a couple of extra element to our markup to position them, and we&#8217;re good to go.</p>
<p>Now our other client, Even Greater Sprockets Inc., also wants rounded corners and semi-transparent backgrounds. However, recognizing that neither is important to the actual branding of the site, they agree to practice a bit of progressive enhancement.</p>
<p>So, using two lines of CSS, we give rounded corners to all Firefox and Webkit-based browsers. Again, using CSS, we use <a href="http://www.timkadlec.com/post.asp?q=61">RGBa</a> to create semi-transparent backgrounds in the browsers that support them, and let others fall back to a fully opaque background color. And that&#8217;s it. No images, no extra Javascript calls, and no extra elements in our markup.</p>
<p>One client has ensured that every visitor to their site with a relatively modern browser, regardless of browser capabilities, gets rounded corners and semi-transparent backgrounds. As a result, they added time to the development of their site, and therefore money to their bill. In addition, they&#8217;ve increased the time it takes for their page to load by adding a few extra HTTP requests necessary to load the necessary images and scripts.</p>
<p>The other client has offered these embellishments only to browsers that support them natively. As a result, their development time is lower, and so is their bill and page load time. Their branding is still in tact, and their site still looks good, it&#8217;s just without a few added aesthetic touches.</p>
<p>Which option makes more sense to you?</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2009/06/developing-smarter-with-progressive-enhancement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manageable CSS with CSSDOC</title>
		<link>http://timkadlec.com/2008/12/manageable-css-with-cssdoc/</link>
		<comments>http://timkadlec.com/2008/12/manageable-css-with-cssdoc/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/manageable-css-with-cssdoc/</guid>
		<description><![CDATA[I've been very interested in finding better ways to create CSS stylesheets that are easy to navigate, understand and maintain. One way of managing your stylesheets that's got my attention is CSSDOC.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been very interested in finding better ways to create CSS stylesheets that are easy to navigate, understand and maintain. After leaving a stylesheet alone for awhile, if you didn&#8217;t take the time to organize the stylesheet originally, it&#8217;s really easy to forget why certain rules are being used, or where you defined styles for an area. One way of managing your stylesheets that&#8217;s got my attention is <a href="http://www.cssdoc.net">CSSDOC.</a></p>
<p>CSSDOC was an idea apparently conceived sometime in 2007, and the Second Public Draft of the spec was just released on November 16th. The intent behind CSSDOC is to provide a standardized way of commenting CSS making use of the very well known DocBlock way of commenting source-code.</p>
<p>DocBlock is a very common form of documenting source code in programming that has proven to be very popular for both <a href="http://www.phpdoc.org/">PHP</a> and <a href="http://jsdoc.sourceforge.net/">Javascript</a>. The beauty of the method is that it&#8217;s so simple to use DocBlock to organize your code and since it&#8217;s a standardized format, other developers will be familiar with it and tools can be developed to parse it and auto-generate documentation.</p>
<p>There are a great deal of tags being developed for CSSDOC that can provide a lot of great information. For example, here is a sample header from the CSSDOC draft:</p>
<ol class="code">
<li>/**</li>
<li>* Homepage Style</li>
<li>*</li>
<li>* Standard Layout (all parts) for Big Little Homepage</li>
<li>*</li>
<li>* This style has been designed by Mina Margin. It reflects</li>
<li>* the composition of colors through the years of the</li>
<li>* customers project as well as the boldness it implies.</li>
<li>*</li>
<li>* @project   Big Little Homepage</li>
<li>* @version   0.2.8</li>
<li>* @package   xhtml-css</li>
<li>* @author    Mina Margin</li>
<li>* @copyright 2008 by the author</li>
<li>* @cssdoc    version 1.0-pre</li>
<li>* @license   GPL v3</li>
<li>*</li>
<li>* @colordef  #fff; white</li>
<li>* @colordef  #808080; standard grey</li>
<li>*/</li>
</ol>
<p>Just by this simple header, we&#8217;ve already provided a great deal of information to both future developers and to a documentation parser. In our header we&#8217;ve provided the project we&#8217;re working on, a version number for the project, copyright and author information, and some definitions of recurring colors used in the project.</p>
<p>You then make use of the @section and @subsection comments to divide your CSS file into manageable sections of related styles. I&#8217;d love to see this implemented in editors like <a href="http://macrabbit.com/cssedit/">CSSEdit&#8217;s</a> @group comment. For those of you unfamiliar, the @group comment in CSSEdit is parsed out and made into easy to navigate folders in the sidebar (see the image below).</p>
<p><img src="/rantpics/cssedit_screen.jpg" alt="CSS Edit - Screenshot" /></p>
<p>I won&#8217;t go through all the available comments (the draft can give you that and does a great job of explaining), but suffice it to say there&#8217;s a lot of extremely useful comments available: @affected comment which describes what browsers are affected by a certain bug/workaround; @tested comments to specify what browsers a certain section has been tested on; @fontdef for font definitions, similar to the @colordef rule in the example above; etc.</p>
<p>I&#8217;m very excited by this project and think the team behind the spec has done a fantastic job thus far. The few concerns I had, they&#8217;ve either addressed, or are in the process of doing so. It&#8217;s very easy to get involved with the project as they have been very transparent in the development of the specification.</p>
<p>In addition, if you want to start playing around with CSSDOC a bit on your own CSS, there are bundles made already for editors like Textmate, EditPlus, and KomodoEdit just to name a few. You can keep up to date on new bundles and snippets at <a href="http://cssdoc.net/wiki/EditorIntegration">http://cssdoc.net/wiki/EditorIntegration</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/12/manageable-css-with-cssdoc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Font Equality for Everyone</title>
		<link>http://timkadlec.com/2008/10/font-equality-for-everyone/</link>
		<comments>http://timkadlec.com/2008/10/font-equality-for-everyone/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[fonts]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/font-equality-for-everyone/</guid>
		<description><![CDATA[One of the areas that web design is lacking in, is a way to reliably provide beautiful fonts for our designs. Thankfully, we are close to being able to make use of a CSS rule that makes font use so much simpler.]]></description>
			<content:encoded><![CDATA[<p>One of the areas that web design is lacking in, is a way to reliably provide beautiful fonts for our designs. There&#8217;s a very limited amount of fonts that are actually safe to use on the web, because not everyone is a designer with lots of nice fonts installed on their machine. Sure, with font stacking we can help ease the pain a bit, but it&#8217;s still a small amount of people that will see the fonts we intend, with everyone else getting boring alternates.</p>
<p>There are a few solutions currently being utilized across the web. The simplest, and also probably the worst option of them, is to use background images to display our custom fonts. This is not very ideal at all&#8230;every time we want to change the text on the site, we have to edit the appropriate background image. A couple less &#8220;needy&#8221; options are <abbr title="scalable Inman Flash Replacement">sIFR</abbr> and <abbr title="Facelift Image Replacement">FLIR</abbr>. In both cases, Javascript is utilized to deliver the text in our desired font. <abbr title="scalable Inman Flash Replacement">sIFR</abbr> uses Flash to make this happen and <abbr title="Facelift Image Replacement">FLIR</abbr> uses PHP. But we are still relying on Javascript to load the fonts onto the page, and there is some performance loss.</p>
<p>Thankfully, we are close to being able to make use of a CSS rule that makes font use so much simpler. The newest versions of all major browsers now support the @font-face rule, which gives us a lot of power over the fonts we can use in our sites. Unfortunately, some of them don&#8217;t play too nicely yet. Firefox 3.1 and Safari both implement the @font-face rule very well, but IE only supports <abbr title="Embedded Open Type">EOT</abbr> fonts and I&#8217;ve found Opera 9.6&#8242;s support is a bit unreliable. However, in the name of progressive enhancement, there&#8217;s little reason why we can&#8217;t start making use of this rule to improve our sites now.</p>
<h2>Simply Powerful</h2>
<p>The beauty of the @font-face rule is both how simple it is, and yet how powerful it is. The @font-face rule includes the rule and the font description like so:</p>
<ol class="code">
<li>@font-face {</li>
<li>}</li>
</ol>
<p>The font description is made up of the what are called font descriptors. Simply put, they follow the same format of typical CSS style declarations. The most basic font description is composed of a font-family declaration and a src declaration that points to the font we will be using, like so:</p>
<ol class="code">
<li>@font-face {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;;</li>
<li class="tab1">src: url(BenjaminFranklin.ttf);</li>
<li>}</li>
</ol>
<p>The url can be either remote or on your own site. However, for maximum browser compatibility, your font should reside in the same place as the page using it. Firefox, for instance, does not allow using fonts that don&#8217;t have the same origin of the page. Instead of using a url, we can also use a local path ( local(font-path) ) that would point to a font located on the user&#8217;s computer. We&#8217;ve now set the way for us to make use of the Benjamin Franklin font in our site.</p>
<ol class="code">
<li>h1 {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;, serif;</li>
<li>}</li>
</ol>
<h2>More Than Meets the Eye</h2>
<p>Simple and easy. Here&#8217;s where the fun stuff comes in though. Remember how those declarations, like the font-family declaration above, are called font descriptors? That&#8217;s because they describe the declaration that can be used to trigger that font use. Admittedly, that might not be very clear, so let&#8217;s extend our example:</p>
<ol class="code">
<li>@font-face {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;;</li>
<li class="tab1">src: url(BenjaminFranklin.ttf);</li>
<li class="tab1">font-weight: all;</li>
<li>}</li>
<li>@font-face {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;;</li>
<li class="tab1">src: url(Hansa.ttf);</li>
<li class="tab1">font-weight: bold;</li>
<li>}</li>
<li>h1 {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;, serif;</li>
<li class="tab1">font-weight: bold;</li>
<li>}</li>
<li>h2 {</li>
<li class="tab1">font-family: &#8220;Benjamin Franklin&#8221;, serif;</li>
<li class="tab1">font-weight: normal;</li>
<li>}</li>
</ol>
<p>In the example above, we changed the call to the font being used if the font-weight is bold. If the font-weight is anything but bold, then the Benjamin Franklin font is used. If the font-weight is set to bold, then the Hansa font is used. If you have Safari or the Firefox 3.1 beta you can <a href="font-facetest.asp">take a look at the code in action</a>. (NOTE: The only reason I was using two different fonts here is to make it obvious that the font is changed based on the font-weight. A more subtle example would be to use a variation of the base font, like a bold version.)</p>
<p>Descriptors give you significant power over the fonts you utilize. Instead of relying on the browser to fake a bold or italic version of the font, we can provide the more professional looking actual italicized, or bolded, version of the font, greatly improving the appearance of our design.</p>
<p>I highly encourage taking a look at the <a href="http://www.w3.org/TR/CSS2/fonts.html#font-descriptions">W3C&#8217;s information on the @font-face rule</a> and playing around with it a bit. There&#8217;s some great examples of some of the powerful ways you can make use of the @font-face rules including an interesting example of redefining the basic serif font-family. Remember, for full functionality you&#8217;ll need to either get ahold of Firefox 3.1 or Safari.</p>
<p>Keep in mind that not all fonts are meant to be used in this way. Some font providers encourage you to make use of their fonts freely, other&#8217;s don&#8217;t. So make sure you&#8217;re allowed to make use of the font before embedding it on your site. Both fonts used in the examples, Hansa and Benjamin Franklin, are designed by <a href="http://moorstation.org/typoasis/designers/steffmann/index.htm">Dieter Steffman</a> who graciously allows his fonts to be freely used on the web.</p>
<p>Also, while there is a lot of power and control offered with the @font-face rule, still use it with some level of restraint. There is some time involved in downloading the font, so you should probably stick to using this method for headlines only&#8230;not body text.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/10/font-equality-for-everyone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Behavior in Your Presentation</title>
		<link>http://timkadlec.com/2008/05/behavior-in-your-presentation/</link>
		<comments>http://timkadlec.com/2008/05/behavior-in-your-presentation/#comments</comments>
		<pubDate>Sun, 18 May 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/behavior-in-your-presentation/</guid>
		<description><![CDATA[I've spent some time lately playing around with the WebKit Nightly Build. There are some really cool features being implemented, including CSS gradients, masks and transforms. One new feature, CSS transitions, has me a little on the fence though.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent some time lately playing around with the <a href="http://nightly.webkit.org/">WebKit Nightly Build</a>. In addition to having advanced CSS support, the nightly build also introduces a few new proprietary CSS properties (though the plan is to eventually get W3C to implement them in the CSS specification). There are some really cool features being implemented, including CSS gradients, masks and transforms. One new feature, CSS transitions, has me a little on the fence though.</p>
<p>CSS transitions are definitely a cool idea. Using one simple line of CSS, we can specify how we want a particular style to change. For example, a very common thing to do with CSS is change a link&#8217;s color when hovered over. To do so, you just use the :hover pseudo-class like so:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>a{</li>
<li class="tab1">color: blue;</li>
<li>}</li>
<li>a:hover{</li>
<li class="tab1">color: red;</li>
<li>}</li>
</ol>
<p></code><br />
Browsers make the color change immediately when a user hovers over the link. Using WebKit&#8217;s transition property, we can tell the browser to instead make a smooth transition. For example, to make the color slowly change from blue to red over the course of two seconds, we could do the following:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>a{</li>
<li class="tab1">color: blue;</li>
<li class="tab1">-webkit-transition: color 2s linear;</li>
<li>}</li>
<li>a:hover{</li>
<li class="tab1">color: red;</li>
<li>}</li>
</ol>
<p></code><br />
We tell the browser (line 3) what style we want to animate (color), for how long (2s) and what kind of transition we want to use (linear). If you have the WebKit nightly build, I set up <a href="http://www.timkadlec.com/transition.asp">an example</a> using the CSS above. It works great, and the transition is super smooth. Better yet, the other browsers just disregard it and perform the color change as usual. Simple and cool right?</p>
<h2>Mixing Things Up a Bit</h2>
<p>The problem I have with it is that it I think it starts to put CSS in our behavior layer, which is not so cool. Remember, one of the major benefits to proper use of web standards is being able to separate our content, presentation and behavior onto their own separate layers. By using CSS to make these changes, we make it difficult to interact with these properties using Javascript. Will we have access to information regarding how far into the animation we are? Will the transition fire some sort of onFinish method? Javascript would be needed to add this level of flexibility&#8230;not CSS.</p>
<p>While looking around for more information, I was happy to run across a <a href="http://snook.ca/archives/javascript/css_animations_in_safari/">post from late 2007</a> by Jonathan Snook that shares my opinion on the matter. One thing Jonathan suggested was that while browser animation is not a bad idea perhaps it should have been an extension to the DOM instead. That would offer more robustness and flexibility, and seems to preserve the separation of concerns a bit better.</p>
<p>Don&#8217;t get me wrong&#8230;I&#8217;m very excited about most of the new features on display in the nightly build. I can also see how the line between behavior and presentation is a bit blurred already. After all, isn&#8217;t :hover a bit of a behavioral style? I just think that given the potential interactivity here, I have to agree with Jonathan and say that adding a method to the DOM would make more sense in this case.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/05/behavior-in-your-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Not As Clear As It Seems: CSS3 Opacity and RGBA</title>
		<link>http://timkadlec.com/2008/05/not-as-clear-as-it-seems-css3-opacity-and-rgba/</link>
		<comments>http://timkadlec.com/2008/05/not-as-clear-as-it-seems-css3-opacity-and-rgba/#comments</comments>
		<pubDate>Mon, 05 May 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/not-as-clear-as-it-seems-css3-opacity-and-rgba/</guid>
		<description><![CDATA[One of the many things CSS lets us control is the opacity of elements, starting in CSS3. The opacity property is in fact one of the earliest and most widely implemented CSS3 properties. But CSS3 also defines a more powerful way to control an element's transparency: RGBA values.]]></description>
			<content:encoded><![CDATA[<p>One of the many things CSS lets us control is the opacity of elements, starting in CSS3. The opacity property is in fact one of the earliest and most widely implemented CSS3 properties. It has its problems though, but CSS3 also defines a more powerful way to control an element&#8217;s transparency: RGBA values.</p>
<h2>The Opacity Property</h2>
<p>To change the opacity of an element using the opacity property, you simply give it a value between 0 and 1 to determine the elements&#8217; opacity. For example, if I want a div to be 50% transparent, I would give it the following style:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>div {</li>
<li class="tab1">opacity: .5;</li>
<li class="tab1">color: #fff;</li>
<li class="tab1">background-color: #000;</li>
<li>}</li>
</ol>
<p></code><br />
This works fine in Safari, Opera, and Firefox. Internet Explorer, however, doesn&#8217;t yet support the opacity property. Instead, we have to use their proprietary property Alpha Filter. It&#8217;s really not any more difficult than the opacity selector. One key thing to note hear though is that the Alpha Filter requires you specify the opacity on a scale of 0 to 100. There&#8217;s even a catch to that though&#8230;the element is that you are applying the opacity filter to has to have a <code>hasLayout</code> value of true. While there are many ways of making an element have layout, some of the most common are to set a width, or give the element a zoom value of 1. So now our declaration is as follows:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>div{</li>
<li class="tab1">background: #000;</li>
<li class="tab1">opacity: .5;</li>
<li class="tab1">filter: alpha(opacity='50');</li>
<li class="tab1">zoom: 1;</li>
<li>}</li>
</ol>
<p></code><br />
Simple enough&#8230;but with one catch that may or may not present a problem, depending on your situation. When you use the opacity property, the opacity is set for that element, and any children of that element. This can cause problems in readability and general appearance. If you do have problems in this situation, you may not have to resort to a PNG just yet.</p>
<h2>More Power</h2>
<p>CSS3 also allows for an extended version of the RGB color model that includes a fourth value that is used to specify opacity. Again, like the opacity property, the alpha value in the RGBA model accepts a value between 0 and 1. We can use an RGBA value anywhere that colors values are accepted in CSS: borders, background, font colors, etc. This already offers a higher level of control than the opacity selector.</p>
<p>Even better yet, while the opacity property defines the opacity for an element and all of its children, using the RGBA value only applies that transparency to the given property of an element that we specify. For example:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>div{</li>
<li class="tab1">background-color: rgba(0,0,0,.5);</li>
<li class="tab1">color: #fff;</li>
<li>}</li>
<li> &lt;div&gt;</li>
<li class="tab1">Some white text.</li>
<li>&lt;/div&gt;</li>
</ol>
<p></code><br />
Using the background-color property and assigning an RGBA value to it, we are able to define the transparency for the divs&#8217; background color. The transparency of any text or elements inside of the div is unchanged. In contrast, using the opacity property, the paragraph above would inherit the 50% transparency defined on the div.</p>
<p>Unfortunately, as is often the issue, browser support for RGBA is limited. Both Safari and Firefox 3 offer support for the RGBA color value system, but so far Opera and IE do not. The good news though, is that we can use the RGBA value without worrying about it breaking our design by also defining a fallback color.<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>div{</li>
<li class="tab1">background-color: rgb(0,0,0);</li>
<li class="tab1">background-color: rgba(0,0,0,.5);</li>
<li class="tab1">color: #fff;</li>
<li>}</li>
</ol>
<p></code><br />
In most browsers that do not recognize RGBA values, that declaration is simply ignored, as it should be. In IE though (I know, surprise, suprise), it appears that RGBA values cause IE to not display the background at all. A way to get around this would be to use conditional comments to reset the background to a solid color for IE. So we can just define a solid color for browsers that do not accept RGBA values and leave the transparency for those that can support it&#8230;a prime example of progressive enhancement.</p>
<p>I have set up a <a href="opacity.asp">working comparison</a> of RGBA versus using the opacity property for you to view in each browser. Remember, to see the effects of RGBA, you will have to view the page in Safari or Firefox 3.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/05/not-as-clear-as-it-seems-css3-opacity-and-rgba/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Phantom CSS</title>
		<link>http://timkadlec.com/2008/04/phantom-css/</link>
		<comments>http://timkadlec.com/2008/04/phantom-css/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/phantom-css/</guid>
		<description><![CDATA[At the heart of CSS, of course, are its selectors. They are after all what allow us to apply styles to a given element in our (X)HTML. Sometimes though, there is a desire to apply a style based on an elements state.]]></description>
			<content:encoded><![CDATA[<p>At the heart of CSS, of course, are its selectors. They are after all what allow us to apply styles to a given element in our (X)HTML. Sometimes though, there is a desire to apply a style based on an elements state. That is where pseudo-classes come into play. You&#8217;ve probably all used them at some point&#8230;but there may be more there than you realize. Their value makes it worth taking a closer look.</p>
<h2>Static Pseudo-Classes</h2>
<p>Pseudo-classes allow us to apply an invisible, or &#8220;phantom&#8221;, class to an element in order to style it. For example, let&#8217;s look at the element most often styled using pseudo-classes: the anchor tag (<a>). Some anchor tags point to locations a user has already viewed, and some point to locations the user has not yet visited. Looking at the document structure, we can&#8217;t tell this. No matter if the link is viewed or not, it looks the same in (X)HTML. However, behind the scenes, a &#8220;phantom&#8221; class is applied to the link to differentiate between the two. We can access this &#8220;phantom&#8221; class with pseudo-class selectors, like :link and :visited. (Pseudo-classes are always prefixed by a colon.)</a></p>
<p><a>The :link pseudo-class selector refers to any anchor tag that is a link&#8230;that is any anchor tag that has a href attribute. The :visited pseudo-class selector does exactly what it sounds like&#8230;it refers to any link that has been visited. Using these pseudo-classes allows us to apply different effects to links on the page according to the visited state.<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>a {color:blue;}</li>
<li>a:link {color: red;}</li>
<li>a:visited {color: orange;}</li>
</ol>
<p></code><br />
The above styles for example, will make any anchor tag that does not have a href attribute to be colored blue (line 1). Any link that has a href attribute, but has not been visited will be red (line 2). Finally, if a link is visited (line 3), then it is an orange color.</p>
<p>Another static pseudo-class is :first-child (The :first-child pseudo-class is not supported by IE6). The :first-child selector is used to select elements that are first children of other elements. This can be easily misunderstood. A lot of times, people will try to use it to select the first-child of an element. For example:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>
<div>
<li>Here is some text</li>
</div>
</li>
</ol>
<p></code><br />
Say we want to apply a style to the paragraph element. It is not uncommon to see people try to do this using the following style:<br />
<code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>div:first-child {font-weight: bold;}</li>
</ul>
<p></code><br />
However, this is not how the pseudo-class works. If we think back to the concept of pseudo-classes essentially being &#8220;phantom&#8221; classes, then what we just did was apply a phantom class to the div like so:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>
<div class="first-child">
<li>Here is some text</li>
</div>
</li>
</ol>
<p></code><br />
Obviously that is not what we want. The :first-child selector doesn&#8217;t grab the first child of an element; it just grabs any of the specified element that is a first-child. The correct way to style that would be with the following line:<br />
<code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>p:first-child {font-weight: bold;}</li>
</ul>
<p></code><br />
That&#8217;s probably as clear as mud, so it may help to take another look at the &#8220;phantom&#8221; class:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>
<div>
<li>
<p class="first-child">Here is some text</p>
</li>
</div>
</li>
</ol>
<p></code></p>
<h2>Watch Your Language</h2>
<p>Corny headings aside, we can select elements based on the language using the :lang( ) pseudo-class. For example, we can italicize anything in French using the following style:<br />
<code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>*:lang(fr) {font-style: italic;}</li>
</ul>
<p></code><br />
Where does the language get defined? According to the CSS 2.1 specification, the language can be defined in one of many ways:</p>
<blockquote><p><span>In HTML, the language is determined by a combination of the lang attribute, the META element, and possibly by information from the protocol (such as HTTP headers). XML uses an attribute called xml:lang, and there may be other document language-specific methods for determining the language.</span></p></blockquote>
<h2>Dynamic Pseudo-Classes</h2>
<p>So far, what we have discussed are static pseudo-classes. That is, once the document is loaded, these pseudo-classes don&#8217;t change until the page is reloaded. The CSS 2.1 specification also defines three dynamic pseudo-classes. These pseudo-classes can change a document&#8217;s appearance based on user behavior. They are:</p>
<ul class="reg">
<li><code>:focus</code> &#8211; any element that has input focus</li>
<li><code>:hover</code> &#8211; any element that the mouse pointer is placed over</li>
<li><code>:active</code> &#8211; any element that is activated by user input (ex: a link while being clicked)</li>
</ul>
<p>Usually, these pseudo-classes are applied only to links. However, they can be used on other elements as well. For example, you could use the following style to apply a yellow background to any input field in a form when it has the focus.<br />
<code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>input:focus {background: yellow;}</li>
</ul>
<p></code><br />
The main reason this is not done a lot is because of a lack of support. IE6 does not allow any dynamic pseudo-classes to be applied to anything besides links. IE7 allows the :hover pseudo-class to be applied to all elements, but doesn&#8217;t let the :focus pseudo-class be applied to form elements.</p>
<h2>Complex Pseudo-Classes</h2>
<p>CSS offers us the ability to apply multiple pseudo-classes so long as they aren&#8217;t mutually exclusive. For example, we can chain a :first-child and :hover pseudo-class, but not a :link and :visited.<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>p:first-child:hover {font-weight: bold;} //works</li>
<li>a:link:visited {font-weight: bold;} //link and visited are mutually exclusive</li>
</ol>
<p></code><br />
Again, there is a compliance issue here with IE6. The IE6 browser will only recognize the final pseudo-class mentioned. So in the case of our first style above, IE6 will ignore the :first-child pseudo-class selector and just apply the style to the :hover pseudo-class.</p>
<h2>Looking Forward to CSS3</h2>
<p>In addition to the pseudo-classes laid down in CSS 2.1, CSS 3 provides sixteen new pseudo-classes to allow for even more detailed styling capabilities. The new pseudo-classes are:<br />
<code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>:nth-child(N)</li>
<li>:nth-last-child(N)</li>
<li>:nth-of-type(N)</li>
<li>:nth-last-of-type(N)</li>
<li>:last-child</li>
<li>:first-of-type</li>
<li>:last-of-type</li>
<li>:only-child</li>
<li>:only-of-type</li>
<li>:root</li>
<li>:empty</li>
<li>:target</li>
<li>:enabled</li>
<li>:disabled</li>
<li>:checked</li>
<li>:not(S)</li>
</ul>
<p></code></a></p>
<p><a><br />
For more information about the new pseudo-class selectors laid down in CSS3, take a look at the </a><a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/" target="_blakn">CSS3 selectors working draft</a>, or the excellent write-up by <a href="http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/" target="_blank">Roger Johansson</a>. Currently, very few have decent cross-browser support, but as Johansson says, they can still be used for progressive enhancement&#8230;and in such a quickly changing field, when we can stay ahead of the curve, we should take advantage of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/04/phantom-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Share Your Site with the Masses</title>
		<link>http://timkadlec.com/2008/02/share-your-site-with-the-masses/</link>
		<comments>http://timkadlec.com/2008/02/share-your-site-with-the-masses/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/share-your-site-with-the-masses/</guid>
		<description><![CDATA[Originally, it was never going to get this complex. The internet was never meant to be this popular. However, as time has gone by and this wonderful beast of resource has evolved, it is becoming important to be able to provide our content to a wide variety of devices.]]></description>
			<content:encoded><![CDATA[<p>Originally, it was never going to get this complex. The internet was never meant to be this popular. However, as time has gone by and this wonderful beast of resource has evolved, it is becoming important to be able to provide our content to a wide variety of devices. In addition to simply viewing a site on a computer screen, or printing it, our information may be accessed by Braille feedback devices, speech synthesizers, handheld devices, etc. More often than not, one set of styles will not be adequate to provide our content optimally to each of these devices. That is where media types come into play.</p>
<p>Media types can be extremely useful. For example, there is very little reason to display a site&#8217;s navigation on a print-out. Using the print media type, we can then set up a style that hides our navigation section. Handheld devices which have very small screens and often low-bandwidth, may benefit from not displaying a bunch of images.</p>
<p>CSS 2 offered us 10 media types as a way to designate which styles are applied depending on the device that accesses our site:</p>
<ol class="reg">
<li>All &#8211; all devices (this is default)</li>
<li>Aural &#8211; speech synthesizers</li>
<li>Braille &#8211; Braille tactile feedback devices</li>
<li>Embossed &#8211; paged Braille printers</li>
<li>Handheld &#8211; handheld devices (usually small screen, low bandwidth, possibly monochrome)</li>
<li>Print &#8211; printing or print preview</li>
<li>Projection &#8211; projected presentations (projectors, printing on transparencies)</li>
<li>Screen &#8211; computer screen</li>
<li>Tty &#8211; media using a fixed-pitch character grid (terminals or teletypes)</li>
<li>Tv &#8211; television devices</li>
</ol>
<p>If no media type is declared, the default is &#8220;all&#8221;. Using these media types, we can tell devices to only use certain sets of styles. There are three basic ways of doing this:</p>
<h2>Using Inline Syles</h2>
<p><code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>&lt;style type="text/css"&gt;</li>
<li>@media print{</li>
<li class="tab1">body{ background-color:#FFFFFF; }</li>
<li class="tab1">#heading{ font-size:28px; }</li>
<li>}</li>
<li>&lt;/style&gt;</li>
</ol>
<p></code></p>
<p>Inline style sheets are not a very good solution, as they do not separate content and presentation.</p>
<h2>Imported Stylesheets</h2>
<p><code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>&lt;style type="text/css" media="print"/&gt;</li>
<li>@import "print.css";</li>
<li>&lt;/style&gt;</li>
</ol>
<p></code></p>
<p>Imported style sheets are a much better solution, and are fairly widely used. A distinct advantage of imported style sheets is that a styles sheet is only downloaded if that specific media type is being used. For example, if I defined the above styles to be associated with the handheld media type and someone using a regular computer came to my site, they wouldn&#8217;t have to download the styles.</p>
<h2>Linked Stylesheets</h2>
<p><code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>&lt;link rel="stylesheet" type="text/css" media="print" rel="print.css" /&gt;</li>
</ul>
<p></code></p>
<p>This is the most widely supported. As you may have guessed, a user will download each stylesheet regardless of the media type, and then use the appropriate ones. A bit unfortunate, as it wastes a little bit of time downloading styles we&#8217;re not really going to use.</p>
<p>It is important to note that some styles only have meaning within a certain media type, and others are not applicable to certain media types. For example, the aural media type has no use for the font-size style while the page-break-before style is really only useful in the media types like projection, printing, and tv.</p>
<p>Unfortunately, the support for most media types is quite minimal. You can pretty much depend on all, screen, and print. However, at this point, only Opera supports the projection media type, and the handheld media type isn&#8217;t widely supported yet on handheld devices. Feel free to use them anyway, as even if the user agent doesn&#8217;t recognize the media type named, it will just ignore it.</p>
<h2>Media Types on Steroids: Media Queries</h2>
<p>Media types will eventually become even more useful. CSS3 will implement media queries, which will allow us to check for certain criteria. For example, with media queries we can do something like the following:</p>
<p><code><br />
</code></p>
<p><code></p>
<ul class="code">
<li>&lt;link rel="stylesheet" type="text/css" media="screen and (color)" rel="print.css" /&gt;</li>
</ul>
<p></code></p>
<p>What we are telling the user agent is to only use those styles if the device uses a screen media type AND the device is a color device, not monochromatic. The parentheses are required around the text expression to indicate that it is a query. Media queries will allow us to check for items like, width, height, max-width, max-height, min-width, min-height, color, resolution, etc.</p>
<p>Opera already has some limited support for media queries. You can check for height and width values using the pixel measurement in Opera. Hopefully other browsers won&#8217;t be to far behind. Actually, to try and push the concept forward a bit, media queries are one of the criteria being built into the new Acid 3 browser test.</p>
<p>You can check out a more detailed look at media queries by looking at the W3C <a href="http://www.w3.org/TR/css3-mediaqueries/" target="_blank">candidate recommendation</a> on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/02/share-your-site-with-the-masses/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Detailed Look at Stacking in CSS</title>
		<link>http://timkadlec.com/2008/01/detailed-look-at-stacking-in-css/</link>
		<comments>http://timkadlec.com/2008/01/detailed-look-at-stacking-in-css/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/detailed-look-at-stacking-in-css/</guid>
		<description><![CDATA[Using the z-index to affect stacking order in CSS is a much deeper topic than it may appear at first. The idea seems quite simple, but if we take a look we can see that there is actually quite a bit going on here that warrants a closer examination.]]></description>
			<content:encoded><![CDATA[<p>Using the z-index to affect stacking order in CSS is a much deeper topic than it may appear at first. The idea seems quite simple, but if we take a look we can see that there is actually quite a bit going on here that warrants a closer examination.</p>
<p>Most of the time, stacking order just kind of works behind the scenes and we don&#8217;t really pay any attention to it. However, once we use relative or absolute positioning to move an object around the screen, we will end up with several elements occupying the same space. Which element is displayed on top is determined by the elements stacking order. We can adjust an elements stacking order by using the z-index property.</p>
<p>The z-index is so named because it affects an elements position along the z-axis. The z-axis is the axis that goes from front to back from the user. If we think of the x-axis and y-axis as height and width, then z-axis would be the depth. The higher the z-index of an element, the closer it becomes to the user, and the lower the z-index, the further back on the screen it appears.</p>
<p>If we do not specify any z-index values, the default stacking order from closest to the user to furthest back is as follows:</p>
<ol class="reg">
<li>Positioned elements, in order of appearance in source code</li>
<li>Inline elements</li>
<li>Non-positioned floating elements, in order of appearance in source code</li>
<li>All non-positioned, non-floating, block elements in order of source code</li>
<li>Root element backgrounds and borders</li>
</ol>
<p>Based on the default stacking order above, you can see that any element that has been positioned, whether relative or absolute, will be placed above any element that is not positioned. Both positioned and non-positioned elements are of course, above the background of our root element.</p>
<h2>Mixing Things Up A Bit</h2>
<p>Now let&#8217;s say we want to move some of our elements around in the stacking order so different elements appear on top. We can use the z-index property on any positioned elements to adjust there stacking order. The z-index property can accept an integer, the auto value, or an inherit value. When using integers, the higher the positive number, the further up in the stacking order it will appear. You can use negative z-index values to move the element further down in the stacking order. If we do not use a z-index value on an element, it will render at the rendering layer of 0 and will not be moved. The stacking order now looks like this:</p>
<ol class="reg">
<li>Positioned elements with z-index of greater than 0, first in order of z-index from lowest to highest, then in order of appearance in source code</li>
<li>Positioned elements, in order of appearance in source code</li>
<li>Inline elements</li>
<li>Non-positioned floating elements, in order of appearance in source code</li>
<li>All non-positioned, non-floating, block elements in order of source code</li>
<li>Positioned elements with z-index of less than 0, first in order of z-index from highest to lowest, then in order of appearance in source code.</li>
<li>Root element backgrounds and borders</li>
</ol>
<h2>Stacking Context</h2>
<p>An interesting thing happens though when we set a z-index value to 0 or auto&#8230;we establish a new stacking context. Let&#8217;s say we set #front to have a z-index of 5. Now, we have just established a new stacking context for any element descending from (contained in) #front. If #middle is contained within #front, and I set its z-index to 2, it should still appear above #front. Why? Because since we set a z-index value to #front, every descendant of #front is now being stacked in relation to #front. It may be helpful to look at this as a multiple number system (as demonstrated by Eric Meyer in <a href="http://www.amazon.com/gp/product/0596527330?ie=UTF8&amp;tag=timkadcom-20&amp;link_code=as3&amp;camp=211189&amp;creative=373489&amp;creativeASIN=0596527330" target="_blank">CSS: The Definitive Guide</a>):<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>#front 5.0</li>
<li>#middle 5.2</li>
</ol>
<p></code><br />
Since #front is the ancestor that sets the stacking context, it&#8217;s relative stacking level can be thought of as 0. Now when we set the z-index for middle, we are merely setting it&#8217;s local stacking value. Of course 2 is higher than 0, and therefore even though in our CSS it looks like #middle should be displayed behind #front, we can see that actually it should be displayed on top.</p>
<p>For an example, consider the following code:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li> &lt;div id="one"&gt;</li>
<li class="tab1"> &lt;div id="two"&gt;&lt;/div&gt;</li>
<li>&lt;/div&gt;</li>
<li> &lt;div id="three"&gt;&lt;/div&gt;</li>
</ol>
<p></code><br />
Now, using CSS we position these elements so that there is some overlap:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>#one{</li>
<li class="tab1">position: absolute;</li>
<li class="tab1">left: 0px;</li>
<li class="tab1">top: 20px;</li>
<li class="tab1">z-index: 10;</li>
<li>}</li>
<li>#two{</li>
<li class="tab1">position: absolute;</li>
<li class="tab1">left: 50px;</li>
<li class="tab1">top: 30px;</li>
<li class="tab1">z-index: 15;</li>
<li>}</li>
<li>#three{</li>
<li class="tab1">position: absolute;</li>
<li class="tab1">left: 100px;</li>
<li class="tab1">top: 30px;</li>
<li class="tab1">z-index: 12;</li>
<li>}</li>
</ol>
<p></code><br />
<img src="/rantpics/zindex1.gif" alt="Z-Index Example" /></p>
<p>The result is that #two shows up below #three, even though the z-index value we gave it (line 11) is higher than the z-index value we gave #three (line 17). This is because #two is a descendant of #one, which established a new stacking context. Which means if we use our numbering system, we would get the following stacking order:<br />
<code><br />
</code></p>
<p><code></p>
<ol class="code">
<li>#three 12</li>
<li>#two 10.15</li>
<li>#one 10.0</li>
</ol>
<p></code></p>
<h2>Firefox Gets It Wrong</h2>
<p>Ok&#8230;that felt weird to say. We are all used to Firefox getting most CSS things right, but this is one area it gets wrong. According to CSS 2.1, no element can be stacked below the background of the stacking context (the root element for that particular context). What this means is if we adjust the CSS above to give our #two element a negative z-index, the content of #one should overlap over the content of #two, but the background color should not. The way IE renders this is correct. Both results are shown below:</p>
<p><img src="/rantpics/zindex2.gif" alt="Z-Index Example" /></p>
<p>You can see that in IE, while the content of #one is still set above the content of #two, the background color remains behind it, as specified in CSS 2.1. Firefox on the other hand, shoves the entire #two element, background color and all, behind #one. Until this is fixed, be careful about using negative numbers for the z-index of an element.</p>
<h2>Go Forth and Experiment</h2>
<p>Definetely take this and play around with it. This is a topic that is best understood by setting up some positioned and non-positioned elements and experimenting with different z-index values. If you are feeling bold, check out <a href="http://www.w3c.org/TR/CSS21/zindex.html" target="_blank">the W3C&#8217;s</a> really detailed breakdown of the stacking order of not just elements, but their background colors, background images, and borders. As with most topics in CSS, there is more here to understand than we first realize.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/01/detailed-look-at-stacking-in-css/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Getting Specific With CSS</title>
		<link>http://timkadlec.com/2008/01/getting-specific-with-css/</link>
		<comments>http://timkadlec.com/2008/01/getting-specific-with-css/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 00:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/getting-specific-with-css/</guid>
		<description><![CDATA[One very fundamental and integral part of CSS is understanding specificity. Understanding this basic concept can help to make your CSS development, and more specifically (no pun intended) your troubleshooting go more smoothly.]]></description>
			<content:encoded><![CDATA[<p>One very fundamental and integral part of CSS is understanding specificity. Understanding this basic concept can help to make your CSS development, and more specifically (no pun intended) your troubleshooting go more smoothly.</p>
<p>Every rule in CSS has a specificity value that is calculated by the user agent (the web browser for most web development purposes), and assigned to the declaration. The user agent uses this value to determine which styles should be assigned to an element when there are more than one rule for that particular element.</p>
<p>This is a basic concept most of us have at least a general understanding of. For example, most developers can tell you that the second declaration below carries more weight than the first:<br />
<code></p>
<ol class="code">
<li>h1{color: blue;}</li>
<li>h1#title{color: red;}</li>
</ol>
<p></code><br />
If both styles are defined in the same stylesheet, any h1 with an id of &#8216;title&#8217; will of course be red. But just how is this determined?</p>
<h2>Calculating Specificity</h2>
<p>Specificity in CSS is determined by using four number parts. Each type of value in the style declaration receives some sort of specificity rate:</p>
<ul class="reg">
<li>Each id attribute value is assigned a specificity of 0,1,0,0.</li>
<li>Each class, attribute, or pseudo-class value is assigned a specificity of 0,0,1,0.</li>
<li>Each element or pseudo-element is assigned a specificity of 0,0,0,1.</li>
<li>Universal selectors are assigned a specificity of 0,0,0,0 and therefore add nothing to the specificity value of a rule.</li>
<li>Combinator selectors have no specificity. You will see how this differs from having a zero specificity later.</li>
</ul>
<p>So going back to our previous example, the first rule has one element value, so its specificity is 0,0,0,1. The second rule has one element value and an id attribute, so its specificity is 0,1,0,1. Looking at their respective specificity values, it becomes quite clear why the second rule carries more weight.</p>
<p>Just so we are clear on how specificity is calculated, here are some more examples, listed in order of increasing specificity:<br />
<code></p>
<ol class="code">
<li>h1{color: blue;} //0,0,0,1</li>
<li>body h1{color: silver;} //0,0,0,2</li>
<li>h1.title{color: purple;} //0,0,1,1</li>
<li>h1#title{color: pink;} //0,1,0,1</li>
<li>#wrap h1 em{color: red;} //0,1,0,2</li>
</ol>
<p></code><br />
You should also note that the numbers go from left to right in order of importance. So a specificity of 0,0,1,0 wins over a specificity of 0,0,0,13.</p>
<p>At this point, you may be wondering where the fourth value comes into play. Actually, prior to CSS 2.1, there was no fourth value. However, now the value furthest to the left is reserved for inline styles, which carry a specificity of 1,0,0,0. So, obviously, inline styles carry more weight than styles defined elsewhere.</p>
<h2>It&#8217;s Important</h2>
<p>This can be changed, however, by the !important declaration. Important declarations always win out over standard declarations. In fact, they are considered separately from your standard declarations. To use the !important declaration, you simply insert !important directly in front of the semicolon. For example:<br />
<code></p>
<ol class="code">
<li>h1.title{color:purple !important;}</li>
</ol>
<p></code><br />
Now any h1 with a class of &#8216;title&#8217; will be purple, regardless of what any inline styles may say.</p>
<h2>No Specificity</h2>
<p>As promised, I said I would explain the difference between no specificity and zero specificity. To see the difference, you need a basic understanding of inheritance in CSS. CSS allows us to define styles on an element, and have that style be picked up by the element&#8217;s descendants. For example:<br />
<code></p>
<ol class="code">
<li>h1.title{color: purple;}</li>
<li>
&lt;h1 class="title"&gt;This is &lt;em&gt;purple&lt;/em&gt;&lt;/h1&gt;
</li>
</ol>
<p></code></p>
<p>The em element above is a descendant of the h1 element, so it inherits the purple font color. Inherited values have no specificity, not even a zero specificity. That means that a zero specificity would overrule an inherited property:<br />
<code></p>
<ol class="code">
<li>*{color: gray} //0,0,0,0</li>
<li>h1.title{color: purple;}</li>
<li>
&lt;h1 class="title"&gt;This is &lt;em&gt;purple&lt;/em&gt;&lt;/h1&gt;
</li>
</ol>
<p></code><br />
The em element inherits the purple font color as it is a descendant of h1. But remember, inherited values have no specificity. So even though our universal declaration has a specificity of 0,0,0,0, it will still overrule the inherited property. The result is the text inside of the em element is gray, and the rest of the text is purple.</p>
<p>Hopefully this introduction to specificity will help make your development process go smoother. It is not a new concept, or a terribly difficult one to learn, but understanding it can be very helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2008/01/getting-specific-with-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Less Painful CSS Experience</title>
		<link>http://timkadlec.com/2007/12/a-less-painful-css-experience/</link>
		<comments>http://timkadlec.com/2007/12/a-less-painful-css-experience/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 03:00:00 +0000</pubDate>
		<dc:creator>tkadlec</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://localhost/1969/12/a-less-painful-css-experience/</guid>
		<description><![CDATA[CSS can be a tricky little fellow. It's easy to learn, but difficult to master. Here are a few things that have made CSS development a little smoother for me, and hopefully they can do the same for you.]]></description>
			<content:encoded><![CDATA[<p>CSS can be a tricky little fellow. It&#8217;s easy to learn, but difficult to master. There are, after all, 122 CSS Level 2 Properties. Add to that pseudo-classes, selectors, inheritance, and specificity, and you have yourselves quite a bit of information to try and remember. Here are a few things that have made CSS development a little smoother for me, and hopefully they can do the same for you.</p>
<h2>Know the common bugs</h2>
<p>Different browsers will handle CSS differently. This is something every CSS developer learns early on, sometimes painfully. Make sure when you come across a bug you force yourself to take a few minutes to look into it and gain an understanding of what is causing the problem. You will be surprised by how few fancy CSS hacks you will have to resort to if you know how to dodge the problems in the first place.</p>
<h2>Check your work often</h2>
<p>After every couple rules you put into your stylesheet, you should be checking each browser you have access to so you can see what effect the rule had on the layout. The worst thing you can do, in my opinion, is to create your CSS entirely and then check it in each browser. Now you have to wade through all your CSS and try to find where the problem is coming from. However, if you are checking your work after every couple rules, you will have a pretty good idea where the problem lies, and you will be able to fix it that much more quickly.</p>
<h2>Know your resources</h2>
<p>This may be the most important tip here. Like I said, with so many selectors, properties, bugs, etc. to try and memorize, you will undoubtedly have to turn for help on many occasions. It becomes important for you to know where you can find a solution, and where the solution will be explained in detail enough for you to understand it and be able to avoid it in the future. For example, when I run across a bug that I am not familiar with, the first place I turn to is <a href="http://www.positioniseverything.net" target="_blank">Position Is Everything</a>. They have wonderful write-ups on various bugs you will find in different browsers. If I just need to lookup a CSS property that I don&#8217;t use very often, then I turn to <a href="http://www.amazon.com/gp/product/1590595335?ie=UTF8&amp;tag=timkadcom-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1590595335" target="_blank">&#8220;CSS: The Definitive Guide&#8221;</a>, by Eric Meyer. You need to know the places like this that you can turn to for answers.</p>
<h2>Know how to troubleshoot</h2>
<p>Knowing how to find the problem is half the battle. There&#8217;s plenty of ways to go about doing this, so you just have to find the techniques that work for you. While I can say that I haven&#8217;t ever used diagnostic styling quite to the extent that Eric Meyer posted in his <a href="http://24ways.org/2007/diagnostic-styling" target="_blank">24ways article</a>, I am a huge fan of using bright colored borders on my block elements to help me locate problem areas. Commenting out blocks of code at a time can also help a lot when trying to find out what elements have the troublesome styles applied to them. And I cannot recommend the <a href="https://addons.mozilla.org/en-US/firefox/addon/60" target="_blank">Web Developer Toolbar extension</a> for Firefox highly enough. I am so attached to that thing and its many useful troubleshooting features now that it pains me to work on a computer without it.</p>
<h2>Show patience and have a sense of humor</h2>
<p>Don&#8217;t worry if it seems like it is taking forever to get to the point where you don&#8217;t have to look up every little bug. Patience, young Padawan. There are a lot of bugs out there, and it can take awhile before you get to a point where you can recognize one right away.</p>
<p>No matter how much you know, how many books you&#8217;ve read, or how many designs you&#8217;ve developed, there will still come times where a problem comes up that stumps you for awhile. There is just too much information to digest for you to expect to never run into problems. That&#8217;s when you just need to grin and bear it. Keep plugging away and be willing to laugh at simple mistakes you may make along the way. If CSS wasn&#8217;t challenging at times, wouldn&#8217;t that take some of the fun out of it?</p>
]]></content:encoded>
			<wfw:commentRss>http://timkadlec.com/2007/12/a-less-painful-css-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
