<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<meta name="keywords" content="thinkquest,web,toolkit,design,development,internet,websites,site,html,xhtml,css" />
<meta name="description" content="A web building guide for ThinkQuesters" />
<meta name="revised" content="ttk, 08/04/07" />

<title>TQ Toolkit - CSS - Advanced Selectors</title>

<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="stylesheet" href="styles/copy.css" media="print" />

</head>
<body><!-- tql_banner_head --><script type="text/javascript" src="/banner/banner.js"></script></script><script>tql_drawTop();</script>
<a id="top" style="display:block"></a>
<h1 class="title">Advanced Selectors</h1>
<hr />
<a class="external" href="#contentarea" onclick="ajaxpage('toolkit.html','content');ajaxpage('navigator002.html','Answer12');">Toolkit</a> &gt; <a class="external" href="#contentarea" onclick="ajaxpage('css.html','content');ajaxpage('navigator016.html','Answer12');">CSS</a> &gt; Advanced Selectors <br />

<div id="contentjump">
<h2>Content Jump</h2>
<ul class="contenttext">
	<li><a href="#p1" class="external">Combining Selectors</a></li>
	<li><a href="#p2" class="external">Selector Grouping</a></li>
	<li><a href="#p3" class="external">Pseudo-class selectors</a></li>
</ul>
</div>

<a id="p1" style="display:block"></a>
<h2 class="subtitle">Combining Selectors</h2>
<a class="showhide" id="Answer22" onclick="showHide(22);showHide(23);">Show</a>
<div id="Answer23">
<a class="showhide" onclick="showHide(22);showHide(23);">Hide</a>
<p class="contenttext">
Selectors may be combined to be a single selector.
<br /> <br />
Let's consider the following scenario:
<br /> <br />
.first { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-size : large; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text-align : center; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br />
<br /> <br />
The above class selector, would style all elements assigned to the class &quot;first&quot;. Let's say that you want to style all the paragraphs assigned to the class &quot;first&quot;. By combining the class and type selectors, we get the following:
<br /> <br />
p.first { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color : red; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-size : large; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text-align : center; <br />
}
<br /> <br />
Now, paragraph elements which have been assigned the class &quot;first&quot;, will have a large font size, be centered and colored red.
<br /> <br />
<a href="#top"><span class="hidden" style="display:none;cursor:pointer;color:#FF6633;">TOP</span><img src="images/top.jpg" class="topbut" alt="Top" /></a> <br />
</p>
</div>

<a id="p2" style="display:block"></a>
<h2 class="subtitle">Selector Grouping</h2>
<a id="Answer26" class="showhide" onclick="showHide(26);showHide(27);">Show</a>
<div id="Answer27">
<a class="showhide" onclick="showHide(26);showHide(27);">Hide</a>
<p class="contenttext">
p { <br />
&nbsp;&nbsp;&nbsp;&nbsp;color: black; <br />
&nbsp;&nbsp;&nbsp;&nbsp;font-family: Garamond, serif; <br />
&nbsp;&nbsp;&nbsp;&nbsp;}
<br /> <br />
h1 { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color: red; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-family: Garamond, serif; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br /> <br />
Consider the above rules. Notice that both share a common property: &quot;font : Garamond&quot;. Suppose that you wish to change all the text with the font Garamond to another font, say, Verdana. It would be very troublesome to change every rule with specifies the font Garamond.
<br /> <br />
You should group all the elements with the same properties into the same selector. In this case, the following rule should be inserted:
<br /> <br />
h1,p { <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-family: Garamond, serif; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br /> <br />
This way, both elements will have the same font type. You can choose as many selectors as you want to group by delimiting them with a comma.
<br /> <br />
<a href="#top"><span class="hidden" style="display:none;cursor:pointer;color:#FF6633;">TOP</span><img src="images/top.jpg" class="topbut" alt="Top" /></a> <br />
</p>
</div>

<a id="p3" style="display:block"></a>
<h2 class="subtitle">Pseudo-class selectors</h2>
<a id="Answer30" class="showhide" onclick="showHide(30);showHide(31);">Show</a>
<div id="Answer31">
<a class="showhide" onclick="showHide(30);showHide(31);">Hide</a>
<p class="contenttext">
Have you ever noticed that hyperlinks on a webpage are of a different color from the other text? When, you visit the hyperlink, you will notice that the color will change once again. This may be achieved by use of pseudo-class selectors.
<br /> <br />
Pseudo-class selectors are used to add special effects to selectors. Pseudo-class selectors are presented in the form:
<br /> <br />
selector:pseudo-class {property: value}
<br /> <br />
In HTML, hyperlinks are presented in the form: <br />
&lt;a href=&quot;http://www.thinkquest.org/&quot;&gt;thinkquest&lt;/a&gt;
<br /> <br />
By default, links are blue. However, you may choose to change the color by using a pseudo-class selector. In this case, the pseudo-class would be link.
<br /> <br />
a:link {color: #FF0000}
<br /> <br />
You may also style other pseudo classes, such as: <br />
a:visited {color: #00FF00}  <br />
[Colour of link of sites you have visited before}
<br /> <br />
a:hover {color: #FF00FF} <br />
[Colour of link when you cursor is over the link]
<br /> <br />
a:active {color: #0000FF} <br />
[Colour of link when you have clicked on it]
<br /> <br />
Please note that the sequence of this rules are <b>IMPORTANT</b> for them to work. You can omit any of them if no changes are to be made, say, on active.
<br /> <br />
<img src="images/flash.png" class="largeIcon" alt="Flash Content" />
<a href="#p3" class="external" rel="external" onclick="popup('flash/css_pseudo.html','TQ Toolkit - CSS pseudo-class Selectors',800,600);">View Flash illustration of using pseudo-class selectors</a></p>
</div>

<div id="references">
<hr />
References:
	<ol>
		<li><a href="http://www.w3schools.com/css/" class="external" rel="external">CSS Tutorial</a>. W3Schools. 1/3/2007</li>
		<li><a href="http://htmlhelp.com/reference/css/" class="external" rel="external">Cascading Style Sheets</a>. Web Design Group. 1/3/2007</li>
		</ol>
Visit the <a href="#contentarea" class="external" onclick="ajaxpage('references.html','content');">References Page</a> for all references used in the site.
</div>

<a href="#top"><span class="hidden" style="display:none;cursor:pointer;color:#FF6633;">TOP</span><img src="images/top.jpg" class="topbut" alt="Top" /></a>
<!-- tql_banner_foot --><script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-174705-4']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })(); </script></body>
</html>