<?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>csslearn.com &#187; CSS selectors</title>
	<atom:link href="http://csslearn.com/tag/css-selectors/feed" rel="self" type="application/rss+xml" />
	<link>http://csslearn.com</link>
	<description>learn style with style</description>
	<lastBuildDate>Mon, 01 Mar 2010 02:17:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Types of CSS selectors</title>
		<link>http://csslearn.com/types-of-css-selectors</link>
		<comments>http://csslearn.com/types-of-css-selectors#comments</comments>
		<pubDate>Tue, 24 Nov 2009 17:49:52 +0000</pubDate>
		<dc:creator>kunal</dc:creator>
				<category><![CDATA[CSS Basic]]></category>
		<category><![CDATA[CSS selectors]]></category>

		<guid isPermaLink="false">http://csslearn.com/?p=25</guid>
		<description><![CDATA[In the previous example, the most basic style of selector was used: an element selector. This defines the visual appearance of the relevant HTML tag. In the sections that follow, we’ll examine some other regularly used (and well-supported) CSS selectors: class, ID, grouped, and contextual.
Class selectors
In some cases, you may wish to modify an element [...]


Related posts:<ol><li><a href='http://csslearn.com/creating-alternatives-with-classes-and-spans' rel='bookmark' title='Permanent Link: Creating alternatives with classes and spans'>Creating alternatives with classes and spans</a> <small>It’s common in web design to define alternatives to the...</small></li>
<li><a href='http://csslearn.com/using-cascade-order' rel='bookmark' title='Permanent Link: Using Cascade Order'>Using Cascade Order</a> <small>CSS allows you to assign the same rule to the...</small></li>
<li><a href='http://csslearn.com/the-rules-of-css' rel='bookmark' title='Permanent Link: The rules of CSS'>The rules of CSS</a> <small>Style sheets consist of a number of rules that define...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>In the previous example, the most basic style of selector was used: an element selector. This defines the visual appearance of the relevant HTML tag. In the sections that follow, we’ll examine some other regularly used (and well-supported) CSS selectors: class, ID, grouped, and contextual.</p>
<h2><strong>Class selectors</strong></h2>
<p>In some cases, you may wish to modify an element or a group of elements. For instance, you may wish for your general website text to be blue, as in the examples so far, but some portions of it to be red. The simplest way of doing this is by using a class selector. In CSS, a class selector’s name is prefixed by a period (.), like this:<br />
.warningText {<br />
color: red;<br />
}<br />
This style is applied to HTML elements in any web page the style sheet is attached to using<br />
the class attribute, as follows:</p>
<h2 class="warningText"><span style="color: #ff0000;">This heading is red.</span></h2>
<p class="warningText"><span style="color: #ff0000;">This text is red.</span></p>
<p>This is a paragraph, <span class="warningText">and this text is å red</span>.</p>
<p>You don’t have to lay out CSS rules as done in this section; rather, you can add rules as one long string. However, the formatting shown here is more readable in print. Note that in the files available for download, the formatting is changed slightly again: the property/value pairs and closing curly bracket are both tabbed inward, enabling rapid vertical scanning of a CSS document’s selectors.</p>
<p>If you want a make a class specific to a certain element, place the relevant HTML tag before the period in the CSS rule:<br />
p.warningText {<br />
color: red;<br />
}<br />
If you used this CSS rule with the HTML elements shown previously, the paragraph’s text would remain red, but not the heading or span, due to the warningText class now being exclusively tied to the paragraph selector only. Usefully, it’s possible to style an element by using multiple class values. This is done by listing multiple values in the class attribute, separated by spaces:</p>
<p class="warningText hugeText">The previous example’s content would be styled as per the rules .warningText and .hugeText.</p>
<h2><strong> ID selectors</strong></h2>
<p class="warningText hugeText">ID selectors can be used only once on each web page. In HTML, you apply a unique identifier<br />
to an HTML element with the id attribute:</p>
<p>To style this element in CSS, precede the ID name with a hash mark (#):<br />
p#footer {<br />
padding: 20px;<br />
}<br />
In this case, the footer div would have 20 pixels of padding on all sides. Essentially, then, classes can be used multiple times on a web page, but IDs cannot. Typically, IDs are used to define one-off page elements, such as structural divisions, whereas classes are used to define the style for multiple items. Grouped selectors Should you wish to set a property value for a number of different selectors, you can use grouped selectors, which take the form of a comma-separated list:<br />
h1, h2, h3, h4, h5, h6 {<br />
color: green;<br />
}<br />
In the preceding example, all the website’s headings have been set to be green. Note that you’re not restricted to a single rule for each element—you can use grouped selectors for common definitions and separate ones for specific property values, as follows:</p>
<p>h1, h2, h3, h4, h5, h6 {<br />
color: green;<br />
}<br />
h1 {<br />
font-size: 1.5em;<br />
}<br />
h2 {<br />
font-size: 1.2em;<br />
}</p>
<p><em><strong>If you define a property value twice, browsers render your web element depending on<br />
each rule’s position in the cascade. See the section “The cascade” later in the chapter<br />
for more information.</strong></em></p>
<h2>Contextual selectors</h2>
<p>This selector type is handy when working with advanced CSS. As the name suggests, contextual selectors define property values for HTML elements depending on context. Take, for instance, the following example:</p>
<p>I am a paragraph.</p>
<p>So am I.</p>
<div id="navigation">
<p>I am a paragraph within the navigation div.</p>
<p>Another paragraph within the navigation div.</p></div>
<p>You can style the page’s paragraphs as a whole and then define some specific values for those within the navigation div by using a standard element selector for the former and a contextual selector for the latter:<br />
p {<br />
color: black;<br />
}<br />
#navigation p {<br />
color: blue;<br />
font-weight: bold;<br />
}<br />
As shown, syntax for contextual selectors (#navigation p) is simple—you just separate the individual selectors with some whitespace. The two rules shown previously have the following result:<br />
The p rule colors the web page’s paragraphs black. The #navigation p rule overrides the p rule for paragraphs within the navigation div, coloring them blue and making them bold.By working with contextual selectors, it’s possible to get very specific with regard to styling things on your website; we’ll be using these selectors regularly.</p>
<p><strong><em>There are other types of selectors used for specific tasks. These will be covered as relevant<br />
later in this Blog.</em></strong></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcsslearn.com%2Ftypes-of-css-selectors&amp;linkname=Types%20of%20CSS%20selectors"><img src="http://csslearn.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>

<p>Related posts:<ol><li><a href='http://csslearn.com/creating-alternatives-with-classes-and-spans' rel='bookmark' title='Permanent Link: Creating alternatives with classes and spans'>Creating alternatives with classes and spans</a> <small>It’s common in web design to define alternatives to the...</small></li>
<li><a href='http://csslearn.com/using-cascade-order' rel='bookmark' title='Permanent Link: Using Cascade Order'>Using Cascade Order</a> <small>CSS allows you to assign the same rule to the...</small></li>
<li><a href='http://csslearn.com/the-rules-of-css' rel='bookmark' title='Permanent Link: The rules of CSS'>The rules of CSS</a> <small>Style sheets consist of a number of rules that define...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://csslearn.com/types-of-css-selectors/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
