| Business Forum | Buy, Sell & Trade | Search Engine Forum | Domains & Webhosting |
| |||||||
| REMOVE the ads below ! |
![]() |
| | LinkBack | Thread Tools |
| |||
| Advanced Selectors In CSS 2 and 3 Selectors are the way you reference the parts of your HTML documents with the styles you want to have applied to them. CSS2 and CSS3 brought with them a host of new selector specifications, designed to allow greater access to the elements and parts of those elements that make up each and every webpage. These new syntax rules allow greater flexibility and accuracy in defining exactly which parts of your page get styled. Combinators _________________________________________________ The advanced combinators allow you to define styles that are based on a more complex rule that will be applied to more specific elements. Originally, it was possible to get to descendant-elements through contextual styles. For instance: HTML Code: p em {font-size: larger; } Adjacent Sibling Combinator _________________________________________________ The adjacency combinator (a plus sign, +) allows you to style an element if it has been directly preceded by another specified element. This comes in very handy when working out margins and such. For instance, you may give your headings large margins so they stand out from normal text, but if two headings come one after the other, you may want to control the margin between them as a special case, like so: HTML Code: h1, h2 {margin: 3em 0; }
h1 + h2 {margin-top: 1em; } _________________________________________________ The child combinator (denoted by the greater-than symbol, >) can be used to combine two elements, and will only be applied if the second element comes directly after the first. It looks like this: HTML Code: p > em {font-size: larger; } HTML Code: <p> Do <em>not</em> visit <a href="index.html"><em>this</em> page</a>! </p> _________________________________________________ The universal selector (denoted by a star, * ), affects every element on a page. HTML Code: * {color: #bb0; } The two rules below are equivalent: HTML Code: * p {text-indent: 2em; }
p {text-indent: 2em; } HTML Code: p > * > em {font-size: larger; } HTML Code: <p> Seriously, <strong>do not visit <a href="index.html"><em>this</em> page</a>!</strong> </p> Attribute Selectors _________________________________________________ CSS2 also allows you to apply styling to an element based on the attributes it has defined in it, or even based on the values of these attributes. Firstly, to select the elements with an attribute defined, you infix the attribute name surrounded by square brackets: HTML Code: abbr[title] {border-bottom: 1px dashed #0c0; } Taking this a step further, you can select an element that has a precise value specified: HTML Code: a[href="www.geekpoint.net"] {font-weight: bold; } While this could quickly make your CSS file very big and clumsy-looking, it’s undoubtedly a useful power to have at your disposal. This selector comes into its own when you’re styling an XML document, where much of an element’s information may be written in as an attribute value. There’s also a basic pattern-match selector which can look for a single word in an attribute’s value. If the value is a space-separated list (a sentence, in other words), you can write a rule to look out for certain words. HTML Code: a[title~="Mail"] {text-decoration: none; } HTML Code: <p> Send me <a href="mailto:address@server.com" title="Mail me">email</a>. </p> HTML Code: p[align="right"][class="intro"] {line-height: 1.8em; } Hope you all webmasters find this piece of info very useful. The credit for this article goes to "Ross Shannon" ![]() Thanx, Shadab | |||
|
![]() |
| Thread Tools | |