How the Pseudo and Classes and Pseudo Elements works
|
|
|
|
| Articles Reviews CSS | |
| Written by Bogdan V | |
| Tuesday, 28 November 2006 | |
|
{mos_sb_discuss:19}
Most of the time you need to select part of a web page that is not having any tags per se, but they are very easy to identify, like the first line of a paragraph, or a link when you move your mouse over it. On CSS you find the way to give you a handful of selectors for these doohickeyspseudo-classes and pseudo-elements.
Pseudo-Classes give your format links in four different states based on how a visitor is interected with tha link. The links are indenfity in one of the following four states: a:link selects only links that a visitor hasn’t visited yet or while the mouse isn’t hovering over or clicking it. This style is for unused Web link. or when your visitors mouse over it. a:active lets you determine how the links looks when a visitors clicks on them. In other words, it covers the brief nanosecond when someone's pressing the mouse button, before releasing it. More Pseudo-Classes and –Elements The CSS guidelines define several powerful pseudo-class and element selectors beside the ones covered so far. Unfortunately, the most popular browser aroundInternet Explorer 6 for Windowsdoesn't recognize them. So most Web surfers can't appreciate any design elements you create with these selectors (at least until they upgrade to IE 7 or switch to Mozilla Firefoxor trade in their PCs for Macs). before The :before pseudo-element does something no other selector can: It lets you add content preceding a given element. For example, say you wanted to put "HOT TIP!" before certain paragraphs to make them stand out, like the boxes in this book that say "UP TO SPEED" and "POWER USERS' CLINIC." Instead of typing that text in your page's HTML, you can let the :before selector do it for you. This approach not only saves on code, but if you decide to change the message from "HOT TIP!" to, say, "Things to know," then you can change every page on your site with one quick change to your style sheet. (The downside is that this special message is invisible to browsers that don't understand CSS or don't understand the :before selector.) First, create a class (.tip, say) and apply it to the paragraphs that you want to precede with the message, like so: . Then, add your message text to the style sheet: p.tip:before {content: "HOT TIP!" }
tag, it dutifully inserts the text "HOT TIP!" just before the paragraph. Whether you realize it or not, browsers generate their own content all the time, like the bullets in bulleted lists and numbers in ordered lists. If you want, you can even use the :before selector to define how a browser displays its bullets and numbers for lists.
li:first-child { font-weight: bold; }
Powered by jReviews |
|
| Last Updated ( Sunday, 10 June 2007 ) | |
| < Prev | Next > |
|---|







