<?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>Web design studio &#187; Css</title>
	<atom:link href="http://blog.web-design-studio.ro/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.web-design-studio.ro</link>
	<description>Apopii Dumitru - Freelancer, front-end developer</description>
	<lastBuildDate>Fri, 11 Mar 2011 09:07:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Top 5 Greseli care duc la CSS-uri masive</title>
		<link>http://blog.web-design-studio.ro/top-5-greseli-care-duc-la-css-uri-masive/</link>
		<comments>http://blog.web-design-studio.ro/top-5-greseli-care-duc-la-css-uri-masive/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 09:05:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Object-Oriented CSS]]></category>

		<guid isPermaLink="false">http://blog.web-design-studio.ro/?p=259</guid>
		<description><![CDATA[Doar pentru ca nu poti merge la o conferinta extraordinara despre metodele de optimizarea a fisierelor CSS,  asta nu inseamna ca nu poti vedea inregistrea. Aceasta prezentare de Stoyan Stefanov si Nicole Sullivan detaileaza uriasele performante pe care le poti obtine folosing Object-Oriented CSS .]]></description>
			<content:encoded><![CDATA[<p>Doar pentru ca nu poti merge la o conferinta extraordinara despre metodele de optimizarea a fisierelor <strong>CSS</strong>,  asta nu inseamna ca nu poti vedea inregistrea.</p>
<p>Aceasta prezentare de <strong>Stoyan Stefanov</strong> si <strong>Nicole Sullivan</strong> detaileaza uriasele performante pe care le poti obtine folosing <strong>Object-Oriented CSS .<br />
</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="584" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/j6sAm7CLoCQ?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="584" height="385" src="http://www.youtube.com/v/j6sAm7CLoCQ?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.web-design-studio.ro/top-5-greseli-care-duc-la-css-uri-masive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The 30 CSS Selectors you Must Memorize</title>
		<link>http://blog.web-design-studio.ro/the-30-css-selectors-you-must-memorize/</link>
		<comments>http://blog.web-design-studio.ro/the-30-css-selectors-you-must-memorize/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 19:14:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Css]]></category>

		<guid isPermaLink="false">http://blog.web-design-studio.ro/?p=86</guid>
		<description><![CDATA[So you learned the base id, class, and descendant selectors – and then called it a day? If so, you’re missing out on an enormous level of flexibility. While many of the selectors mentioned in this article are part of the CSS3 spec, and are, consequently, only available in modern browsers, you owe it to]]></description>
			<content:encoded><![CDATA[<p>So you learned the base <code>id</code>, <code>class</code>, and <code>descendant</code> selectors – and then called it a day? If so, you’re missing out on an  enormous level of flexibility. While many of the selectors mentioned in  this article are part of the CSS3 spec, and are, consequently, only  available in modern browsers, you owe it to yourself to commit these to  memory.</p>
<hr />
<h2>1. *</h2>
<pre>* {
 margin: 0;
 padding: 0;
}</pre>
<p>Let’s knock the obvious ones out, for the beginners, before we move onto the more advanced selectors.</p>
<p>The star symbol will target every single element on the page. Many developers will use this trick to zero out the <code>margin</code>s and <code>padding</code>. While this is certainly fine for quick tests, I’d advise you to never use this in production code. It adds too much <em>weight</em> on the browser, and is unnecessary.</p>
<p>The <code>*</code> can also be used with child selectors.</p>
<pre>#container * {
 border: 1px solid black;
}</pre>
<p>This will target every single element that is a child of the <code>#container</code> <code>div</code>. Again, try not to use this technique very much, if ever.</p>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>2. #X</h2>
<pre>#container {
   width: 960px;
   margin: auto;
}</pre>
<p>Prefixing the hash symbol to a selector allows us to target by <code>id</code>. This is easily the most common usage, however be cautious when using <code>id</code> selectors.</p>
<blockquote><p>Ask yourself: do I absolutely need to apply an <code>id</code> to this element in order to target it?</p></blockquote>
<p><code>id</code> selectors are rigid and don’t allow for reuse. If  possible, first try to use a tag name, one of the new HTML5 elements, or  even a pseudo-class.</p>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>3. .X</h2>
<pre>.error {
  color: red;
}</pre>
<p>This is a <code>class</code> selector. The difference between <code>id</code>s and <code>class</code>es is that, with the latter, you can target multiple elements. Use <code>class</code>es when you want your styling to apply to a group of elements. Alternatively, use <code>id</code>s to find a needle-in-a-haystack, and style only that specific element.</p>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>4. X Y</h2>
<pre>li a {
  text-decoration: none;
}</pre>
<p>The next most comment selector is the <code>descendant</code> selector. When you need to be more specific with your selectors, you use these. For example, what if, rather than targeting <em>all</em> anchor tags, you only need to target the anchors which are within an  unordered list? This is specifically when you’d use a descendant  selector.</p>
<blockquote><p><strong>Pro-tip</strong> – If your selector looks like <code>X Y Z A B.error</code>, you’re doing it wrong. Always ask yourself if it’s absolutely necessary to apply all of that <em>weight</em>.</p></blockquote>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>5. X</h2>
<pre>a { color: red; }
ul { margin-left: 0; }</pre>
<p>What if you want to target all elements on a page, according to their <code>type</code>, rather than an <code>id</code> or <code>class</code>name? Keep it simple, and use a type selector. If you need to target all unordered lists, use <code>ul {}</code>.</p>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>6. X:visited and X:link</h2>
<pre>a:link { color: red; }
a:visted { color: purple; }</pre>
<p>We use the <code>:link</code> pseudo-class to target all anchors tags which have yet to be clicked on.</p>
<p>Alternatively, we also have the <code>:visited</code> pseudo class, which, as you’d expected, allows us to apply specific styling to only the anchor tags on the page which <em>have</em> been clicked on, or <em>visited</em>.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>7. X + Y</h2>
<pre>ul + p {
   color: red;
}</pre>
<p>This is referred to as an adjacent selector. It will select <em>only</em> the element that is immediately preceded by the former element. In this case, only the first paragraph after each <code>ul</code> will have red text.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>8. X &gt; Y</h2>
<pre>div#container &gt; ul {
  border: 1px solid black;
}</pre>
<p>The difference between the standard <code>X Y</code> and <code>X &gt; Y</code> is that the latter will only select direct children. For example, consider the following markup.</p>
<pre>   &lt;div id="container"&gt;
      &lt;ul&gt;
         &lt;li&gt; List Item
           &lt;ul&gt;
              &lt;li&gt; Child &lt;/li&gt;
           &lt;/ul&gt;
         &lt;/li&gt;
         &lt;li&gt; List Item &lt;/li&gt;
         &lt;li&gt; List Item &lt;/li&gt;
         &lt;li&gt; List Item &lt;/li&gt;
      &lt;/ul&gt;
   &lt;/div&gt;</pre>
<p>A selector of <code>#container &gt; ul</code> will only target the <code>ul</code>s which are direct children of the <code>div</code> with an <code>id</code> of <code>container</code>. It will not target, for instance, the <code>ul</code> that is a child of the first <code>li</code>.</p>
<p>For this reason, there are performance benefits in using the child  combinator. In fact, it’s recommended particularly when working with  JavaScript-based CSS selector engines.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>9. X ~ Y</h2>
<pre>ul ~ p {
   color: red;
}</pre>
<p>This sibling combinator is similar to <code>X + Y</code>, however, it’s less strict. While an adjacent selector (<code>ul + p</code>) will only select the first element that is <em>immediately</em> preceded by the former selector, this one is more generalized. It will select, referring to our example above, any <code>p</code> elements, as long as they follow a <code>ul</code>.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>10. X[title]</h2>
<pre>a[title] {
   color: green;
}</pre>
<p>Referred to as an <em>attributes selector</em>, in our example above, this will only select the anchor tags that have a <code>title</code> attribute. Anchor tags which do not will not receive this particular styling. But, what if you need to be more specific? Well…</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>11. X[href="foo"]</h2>
<pre>a[href="http://net.tutsplus.com"] {
  color: #1f6053; /* nettuts green */
}</pre>
<p>The snippet above will style all anchor tags which link to <em>http://net.tutsplus.com</em>; they’ll receive our branded green color. All other anchor tags will remain unaffected.</p>
<blockquote><p>Note that we’re wrapping the value in quotes. Remember to also do this  when using a JavaScript CSS selector engine. When possible, always use  CSS3 selectors over unofficial methods.</p></blockquote>
<p>This works well, though, it’s a bit rigid. What if the link does indeed direct to Nettuts+, but, maybe, the path is <em>nettuts.com</em> rather than the full url? In those cases we can use a bit of the regular expressions syntax.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>12. X[href*="nettuts"]</h2>
<pre>a[href*="tuts"] {
  color: #1f6053; /* nettuts green */
}</pre>
<p>There we go; that’s what we need. The star designates that the proceeding value must appear <em>somewhere</em> in the attribute’s value. That way, this covers <em>nettuts.com</em>, <em>net.tutsplus.com,</em> and even <em>tutsplus.com</em>.</p>
<p>Keep in mind that this is a broad statement. What if the anchor tag linked to some non-Envato site with the string <em>tuts</em> in the url? When you need to be more specific, use <code>^</code> and <code>&amp;</code>, to reference the beginning and end of a string, respectively.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>13.  X[href^="http"]</h2>
<pre>a[href^="http"] {
   background: url(path/to/external/icon.png) no-repeat;
   padding-left: 10px;
}</pre>
<p>Ever wonder how some websites are able to display a little icon next  to the links which are external? I’m sure you’ve seen these before;  they’re nice reminders that the link will direct you to an entirely  different website.</p>
<p>This is a cinch with the carat symbol. It’s most commonly used in  regular expressions to designate the beginning of a string. If we want  to target all anchor tags that have a <code>href</code> which begins with <code>http</code>, we could use a selector similar to the snippet shown above.</p>
<blockquote><p>Notice that we’re not searching for <code>http://</code>; that’s unnecessary, and doesn’t account for the urls that begin with <code>https://</code>.</p></blockquote>
<p>Now, what if we wanted to instead style all anchors which link to, say, a photo? In those cases, let’s search for the <em>end</em> of the string.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>14. X[href$=".jpg"]</h2>
<pre>a[href$=".jpg"] {
   color: red;
}</pre>
<p>Again, we use a regular expressions symbol, <code>$</code>, to refer  to the end of a string. In this case, we’re searching for all anchors  which link to an image — or at least a url that ends with <code>.jpg</code>. Keep in mind that this certainly won’t work for <code>gifs</code> and <code>pngs</code>.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>15. X[data-*="foo"]</h2>
<pre>a[data-filetype="image"] {
   color: red;
}</pre>
<p>Refer back to number eight; how do we compensate for all of the various image types: <code>png</code>, <code>jpeg,</code><code>jpg</code>, <code>gif</code>? Well, we could create multiple selectors, such as:</p>
<pre>a[href$=".jpg"],
a[href$=".jpeg"],
a[href$=".png"],
a[href$=".gif"] {
   color: red;
}</pre>
<p>But, that’s a pain in the butt, and is inefficient. Another possible  solution is to use custom attributes. What if we added our own <code>data-filetype</code> attribute to each anchor that links to an image?</p>
<pre>&lt;a href="path/to/image.jpg" data-filetype="image"&gt; Image Link &lt;/a&gt;</pre>
<p>Then, with that <em>hook</em> in place, we can use a standard attributes selector to target only those anchors.</p>
<pre>a[data-filetype="image"] {
   color: red;
}</pre>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>16. X[foo~="bar"]</h2>
<pre> a[data-info~="external"] {
   color: red;
}

a[data-info~="image"] {
   border: 1px solid black;
}</pre>
<p>Here’s a special one that’ll impress your friends. Not too many people know about this trick. The tilda (<code>~</code>) symbol allows us to target an attribute which has a spaced-separated list of values.</p>
<p>Going along with our custom attribute from number fifteen, above, we could create a <code>data-info</code> attribute, which can receive a space-separated list of anything we need  to make note of. In this case, we’ll make note of external links and  links to images — just for the example.</p>
<pre>"&lt;a href="path/to/image.jpg" data-info="external image"&gt; Click Me, Fool &lt;/a&gt;</pre>
<p>With that markup in place, now we can target any tags that have  either of those values, by using the ~ attributes selector trick.</p>
<pre>/* Target data-info attr that contains the value "external" */
a[data-info~="external"] {
   color: red;
}

/* And which contain the value "image" */
a[data-info~="image"] {
  border: 1px solid black;
}</pre>
<p>Pretty nifty, ay?</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>17. X:checked</h2>
<pre>input[type=radio]:checked {
   border: 1px solid black;
}</pre>
<p>This pseudo class will only target a user interface element that has been <em>checked</em> &#8211; like a radio button, or checkbox. It&#8217;s as simple as that.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>18. X:after</h2>
<p>The <code>before</code> and <code>after</code> pseudo elements kick  butt. Every day, it seems, people are finding new and creative ways to  use them effectively. They simply generate content around the selected  element.</p>
<p>Many were first introduced to these classes when they encountered the clear-fix hack.</p>
<p><ins><ins id="google_ads_frame1_anchor"></ins></ins></p>
<pre>.clearfix:after {
    content: "";
    display: block;
    clear: both;
    visibility: hidden;
    font-size: 0;
    height: 0;
    }

.clearfix {
   *display: inline-block;
   _height: 1%;
}</pre>
<p>This <em>hack</em> uses the <code>:after</code> pseudo element to  append a space after the element, and then clear it. It&#8217;s an excellent  trick to have in your tool bag, particularly in the cases when the <code>overflow: hidden;</code> method isn&#8217;t possible.</p>
<p>For another creative use of this, refer to my quick tip on creating shadows.</p>
<blockquote><p>According to the CSS3 Selectors specification, you should technically use the pseudo element syntax of two colons <code>::</code>. However, to remain compatible, the user-agent will accept a single colon usage as well.</p></blockquote>
<h3>Compatibility</h3>
<ul>
<li>IE8+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>19. X:hover</h2>
<pre>div:hover {
  background: #e3e3e3;
}</pre>
<p>Oh come on. You know this one. The official term for this is <code>user action pseudo class</code>.  It sounds confusing, but it really isn&#8217;t. Want to apply specific  styling when a user hovers over an element? This will get the job done!</p>
<blockquote><p>Keep in mind that older version of Internet Explorer don&#8217;t respond when the <code>:hover</code> pseudo class is applied to anything other than an anchor tag.</p></blockquote>
<p>You&#8217;ll most often use this selector when applying, for example, a <code>border-bottom</code> to anchor tags, when hovered over.</p>
<pre>a:hover {
 border-bottom: 1px solid black;
}</pre>
<blockquote><p><strong>Pro-tip</strong> &#8211; <code>border-bottom: 1px solid black;</code> looks better than <code>text-decoration: underline;</code>.</p></blockquote>
<h3>Compatibility</h3>
<ul>
<li>IE6+ (In IE6, :hover must be applied to an anchor element)</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>20.  X:not(selector)</h2>
<pre>div:not(#container) {
   color: blue;
}</pre>
<p>The <code>negation</code> pseudo class is particularly helpful. Let&#8217;s say I want to select all divs, except for the one which has an <code>id</code> of <code>container</code>. The snippet above will handle that task perfectly.</p>
<p>Or, if I wanted to select every single element (not advised) except for paragraph tags, we could do:</p>
<pre>*:not(p) {
  color: green;
}</pre>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>21.  X::pseudoElement</h2>
<pre>p::first-line {
   font-weight: bold;
   font-size: 1.2em;
}</pre>
<p>We can use pseudo elements (designated by <code>::</code>) to style  fragments of an element, such as the first line, or the first letter.  Keep in mind that these must be applied to block level elements in order  to take effect.</p>
<blockquote><p>A pseudo-element is composed of two colons: <code>::</code></p></blockquote>
<h4>Target the First Letter of a Paragraph</h4>
<pre>p::first-letter {
   float: left;
   font-size: 2em;
   font-weight: bold;
   font-family: cursive;
   padding-right: 2px;
}</pre>
<p>This snippet is an abstraction that will find all paragraphs on the  page, and then sub-target only the first letter of that element.</p>
<p>This is most often used to create newspaper-like styling for the first-letter of an article.</p>
<h4>Target the First Line of a Paragraph</h4>
<pre>p::first-line {
   font-weight: bold;
   font-size: 1.2em;
}</pre>
<p>Similarly, the <code>::first-line</code> pseudo element will, as expected, style the first line of the element only.</p>
<blockquote><p>&#8220;For compatibility with existing style sheets, user agents must also  accept the previous one-colon notation for pseudo-elements introduced in  CSS levels 1 and 2 (namely, :first-line, :first-letter, :before and  :after). This compatibility is not allowed for the new pseudo-elements  introduced in this specification.&#8221; &#8211; <a href="http://www.w3.org/TR/css3-selectors/">Source</a></p></blockquote>
<h3>Compatibility</h3>
<ul>
<li>IE6+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>22. X:nth-child(n)</h2>
<pre>li:nth-child(3) {
   color: red;
}</pre>
<p>Remember the days when we had no way to target specific elements in a stack? The <code>nth-child</code> pseudo class solves that!</p>
<p>Please note that <code>nth-child</code> accepts an integer as a parameter, however, this is not zero-based. If you wish to target the second list item, use <code>li:nth-child(2)</code>.</p>
<p>We can even use this to select a variable set of children. For example, we could do <code>li:nth-child(4n)</code> to select every fourth list item.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
</ul>
<hr />
<h2>23. X:nth-last-child(n)</h2>
<pre>li:nth-last-child(2) {
   color: red;
}</pre>
<p>What if you had a huge list of items in a <code>ul</code>, and only needed to access, say, the third to the last item? Rather than doing <code>li:nth-child(397)</code>, you could instead use the <code>nth-last-child</code> pseudo class.</p>
<p>This technique works almost identically from number sixteen above,  however, the difference is that it begins at the end of the collection,  and works its way back.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>24. X:nth-of-type(n)</h2>
<pre>ul:nth-of-type(3) {
   border: 1px solid black;
}</pre>
<p>There will be times when, rather than selecting a <code>child</code>, you instead need to select according to the <code>type</code> of element.</p>
<p>Imagine mark-up that contains five unordered lists. If you wanted to style only the third <code>ul</code>, and didn&#8217;t have a unique <code>id</code> to hook into, you could use the <code>nth-of-type(n)</code> pseudo class. In the snippet above, only the third <code>ul</code> will have a border around it.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
</ul>
<hr />
<pre>ul:nth-last-of-type(3) {
   border: 1px solid black;
}</pre>
<p>And yes, to remain consistent, we can also use <code>nth-last-of-type</code> to begin at the end of the selectors list, and work our way back to target the desired element.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>26. X:first-child</h2>
<pre>ul li:first-child {
   border-top: none;
}</pre>
<p>This structural pseudo class allows us to target only the first child  of the element&#8217;s parent. You&#8217;ll often use this to remove borders from  the first and last list items.</p>
<p>For example, let&#8217;s say you have a list of rows, and each one has a <code>border-top</code> and a <code>border-bottom</code>. Well, with that arrangement, the first and last item in that set will look a bit odd.</p>
<p>Many designers apply classes of <code>first</code> and <code>last</code> to compensate for this. Instead, you can use these pseudo classes.</p>
<h3>Compatibility</h3>
<ul>
<li>IE7+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>27. X:last-child</h2>
<pre>ul &gt; li:last-child {
   color: green;
}</pre>
<p>The opposite of <code>first-child</code>, <code>last-child</code> will target the last item of the element&#8217;s parent.</p>
<h3>Example</h3>
<p>Let&#8217;s build a simple example to demonstrate one possible use of these classes. We&#8217;ll create a styled list item.</p>
<h4>Markup</h4>
<pre>  &lt;ul&gt;
     &lt;li&gt; List Item &lt;/li&gt;
     &lt;li&gt; List Item &lt;/li&gt;
     &lt;li&gt; List Item &lt;/li&gt;
  &lt;/ul&gt;</pre>
<p>Nothing special here; just a simple list.</p>
<h4>CSS</h4>
<pre>ul {
 width: 200px;
 background: #292929;
 color: white;
 list-style: none;
 padding-left: 0;
}

li {
 padding: 10px;
 border-bottom: 1px solid black;
 border-top: 1px solid #3c3c3c;
}</pre>
<p>This styling will set a background, remove the browser-default padding on the <code>ul</code>, and apply borders to each <code>li</code> to provide a bit of depth.</p>
<div><img src="http://d2o0t5hpnwv4c1.cloudfront.net/840_cssSelectors/extraBorders.png" alt="Styled List" /></div>
<blockquote><p>To add depth to your lists, apply a <code>border-bottom</code> to each <code>li</code> that is a shade or two darker than the <code>li</code>&#8216;s background color. Next, apply a <code>border-top</code> which is a couple shades <em>lighter</em>.</p></blockquote>
<p>The only problem, as shown in the image above, is that a border will  be applied to the very top and bottom of the unordered list &#8211; which  looks odd. Let&#8217;s use the <code>:first-child</code> and <code>:last-child</code> pseudo classes to fix this.</p>
<pre>li:first-child {
    border-top: none;
}

li:last-child {
   border-bottom: none;
}</pre>
<div><img src="http://d2o0t5hpnwv4c1.cloudfront.net/840_cssSelectors/fixed.png" alt="Fixed" /></div>
<p>There we go; that fixes it!</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<p><em>Yep &#8211; IE8 supported <code>:first-child</code>, but not <code>:last-child</code>. Go figure. </em></p>
<hr />
<h2>28. X:only-child</h2>
<pre>div p:only-child {
   color: red;
}</pre>
<p>Truthfully, you probably won&#8217;t find yourself using the <code>only-child</code> pseudo class too often. Nonetheless, it&#8217;s available, should you need it.</p>
<p>It allows you to target elements which are the <em>only</em> child of its parent. For example, referencing the snippet above, only the paragraph that is the only child of the <code>div</code> will be colored, red.</p>
<p>Let&#8217;s assume the following markup.</p>
<pre>&lt;div&gt;&lt;p&gt; My paragraph here. &lt;/p&gt;&lt;/div&gt;

&lt;div&gt;
   &lt;p&gt; Two paragraphs total. &lt;/p&gt;
   &lt;p&gt; Two paragraphs total. &lt;/p&gt;
&lt;/div&gt;</pre>
<p>In this case, the second <code>div</code>&#8216;s paragraphs will not be targeted; only the first <code>div</code>. As soon as you apply more than one child to an element, the <code>only-child</code> pseudo class ceases to take effect.</p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>29. X:only-of-type</h2>
<pre>li:only-of-type {
   font-weight: bold;
}</pre>
<p>This structural pseudo class can be used in some clever ways. It will  target elements that do not have any siblings within its parent  container. As an example, let&#8217;s target all <code>ul</code>s, which have only a single list item.</p>
<p>First, ask yourself how you would accomplish this task? You could do <code>ul li</code>, but, this would target <em>all</em> list items. The only solution is to use <code>only-of-type</code>.</p>
<pre>ul &gt; li:only-of-type {
   font-weight: bold;
}</pre>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>30. X:first-of-type</h2>
<p>The <code>first-of-type</code> pseudo class allows you to select the first siblings of its type.</p>
<h4>A Test</h4>
<p>To better understand this, let&#8217;s have a test. Copy the following mark-up into your code editor:</p>
<pre>&lt;div&gt;
   &lt;p&gt; My paragraph here. &lt;/p&gt;
   &lt;ul&gt;
      &lt;li&gt; List Item 1 &lt;/li&gt;
      &lt;li&gt; List Item 2 &lt;/li&gt;
   &lt;/ul&gt;

   &lt;ul&gt;
      &lt;li&gt; List Item 3 &lt;/li&gt;
      &lt;li&gt; List Item 4 &lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;</pre>
<p>Now, without reading further, try to figure out how to target only <em>&#8220;List Item 2&#8243;</em>. When you&#8217;ve figured it out (or given up), read on.</p>
<h4>Solution 1</h4>
<p>There are a variety of ways to solve this test. We&#8217;ll review a handful of them. Let&#8217;s begin by using <code>first-of-type</code>.</p>
<pre>ul:first-of-type &gt; li:nth-child(2) {
   font-weight: bold;
}</pre>
<p>This snippet essentially says, &#8220;find the first unordered list on the  page, then find only the immediate children, which are list items. Next,  filter that down to only the second list item in that set.</p>
<h4>Solution 2</h4>
<p>Another option is to use the adjacent selector.</p>
<pre>p + ul li:last-child {
   font-weight: bold;
}</pre>
<p>In this scenario, we find the <code>ul</code> that immediately proceeds the <code>p</code> tag, and then find the very last child of the element.</p>
<h4>Solution 3</h4>
<p>We can be as obnoxious or as playful as we want with these selectors.</p>
<pre>ul:first-of-type li:nth-last-child(1) {
   font-weight: bold;
}</pre>
<p>This time, we grab the first <code>ul</code> on the page, and then find the very first list item, but starting from the bottom! <img src="http://net.tutsplus.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" /></p>
<h3>Compatibility</h3>
<ul>
<li>IE9+</li>
<li>Firefox 3.5+</li>
<li>Chrome</li>
<li>Safari</li>
<li>Opera</li>
</ul>
<hr />
<h2>Conclusion</h2>
<p>If you&#8217;re compensating for older browsers, like Internet Explorer 6, you  still need to be careful when using these newer selectors. But, please  don&#8217;t let that deter you from learning these. You&#8217;d be doing a huge  disservice to yourself. Be sure to refer here for a browser-compatibility list. Alternatively, you can use Dean Edward&#8217;s excellent IE9.js script to bring support for these selectors to older browsers.</p>
<p>Secondly, when working with JavaScript libraries, like the popular  jQuery, always try to use these native CSS3 selectors over the library&#8217;s  custom methods/selectors, when possible. It&#8217;ll make your code faster, as the selector engine can use the browser&#8217;s native parsing, rather than its own.</p>
<p>Thanks for reading, and I hope you picked up a trick or two!</p>
<p>Sursa: <a href="http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/" target="_blank">http://net.tutsplus.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.web-design-studio.ro/the-30-css-selectors-you-must-memorize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

