Flux rss

CSS - Style Classes


Classes and IDs

Classes

A web designer might want to assign different styles to the same tags. For this reason, the CSS specifications introduced the concept of classes.

The definition of classes is as simple as that of styles. It involves specifying a selected tag (as with declaring the style), then adding a decimal point (.) and the name that you want to give the class. The name of the class may be composed of letter, digits, and dashes:

Tag_selector.Name-of-class {
style property: Value;
style property: Value;
...;
}

Where "Name-of-class" represents the name given to the class.

Invoking a class

To invoke a class within the HTML code, just add the class attribute to a tag:
For the class red applied to tag b:

B.red {font: Verdana 12px; color: #FF0000; }
To invoke this class within the code, use the following syntax:
<B class="red">Text that will be red and in bold</B>

Universal classes

It is possible to not specify a tag, in which case the class may be used in any tag in which the style selected has meaning. These are called universal classes (sometimes independent classes). Such a class is defined by putting a decimal point before the name of a class:

.Name-of-class {style property: Value; style property: Value; ...}

For the class "major":

.major {font-type: arial; color: red; font-weight: bold}

Invoking this class can be done using any HTML element in which the definition is valid:

<h1 class="major">This is a warning</h1>
<i class="major">(Please read carefully)</i>

Note: Note the absence of a decimal point when invoking the class.

Pseudo-classes

Pseudo-classes are used to further improve the style applied to certain tags, by defining how they react to an event or their relative position within other tags.

Unlike classes, the names of pseudo-classes are predefined, so it is impossible to create your own pseudo-classes. There are several types of pseudo-classes :

Dynamic pseudo-classes

Dynamic pseudo-classes are used to change the style of a tag when an event occurs (such as moving the mouse, clicking, or pressing a key). There are three of them:

  • The pseudo-class :hover is used to apply a style to a selected tag when the mouse cursor hovers over the text:
    A:hover {font-decoration: underline;}
  • The pseudo-class :focus is used to put a selected tag into a certain style when it is being focused on (such as when an element in a form is clicked on):
    TEXTAREA:focus {color: #FF0000;}
  • The pseudo-class :active is used for putting a selected tag into a certain style when the user clicks on the element (between the moment the user clicks on the mouse button and the moment they release it):
    A:active {color: #FF0000;}
Note: Dynamic pseudo-classes are not rendered the same way by all browsers.

Link pseudo-classes

Link pseudos-classes are pseudo-classes used with the <A> tag:

  • The pseudo-class :link is used for defining the style of hyperlinks which the user has not yet clicked on.
  • The pseudo-class :visited is used to define the style of hyperlinks which the client has already visited.
Note: Some browsers might consider a link to be unvisited if it has not been clicked on for a long period of time.

The descendant pseudo-class

A descendant pseudo-class is used to apply a style to the first tag within an element. This pseudo-class's syntax is as follows:

Parent_Element > Tag:first-child {style;}
So the following declaration applies to the first tag within a<P> </P> set of tags, if that first tag is <A>:
P > A:first-child {color: #00FF00;}
Thus, this <A> tag will have the style:
<P align="justify">
<A href="http://en.kioskea.net/">CCM</A>
</P>
This next <A> tag, on the other hand, will not, as it is not the first tag after the P tag <P>:
<P align="justify">
<BR/>
<A href="http://en.kioskea.net/">CCM</A>
</P>

Text pseudo-classes

Text pseudo-classes are used to apply a style to a portion of text delimited by the appropriate tags. For this reason, text pseudo-classes are generally used in conjunction with the paragraph tag (<P>).

There are two text pseudo-classes:

  • :first-line: used for applying a style to the first line of a paragraph.
    P:first-line { text-transform: uppercase }
  • :first-letter: used for applying a style to the first letter of a paragraph in order to produce a typographical effect. The following example doubles the font size and bolds the first letter of a paragraph:
    P:first-letter { font-size: 200%; font-weight: bold; }

Language pseudo-classes

A style can be defined based on the document's language (specified in the HTTP header or the metatags) or the language of an HTML or XML element (specified with the optional attribute LANG) if it is given.

A language pseudo-class uses the following notation:

  • :lang(Langue). The following language pseudo-class is used if, for whatever reason, you wish to use French-style quotation marks:
    HTML:lang(fr) { quotes: '&laquo; ' ' &raquo;' }

Page pseudo-classes

The selector @page is used to change the layout settings of an HTML page when the page is printed, such as the margins (margin-left, margin-top, margin-right, margin-bottom) or the size (size). To do so, the web page must be imagined as a series of pages in a printed work.

The page pseudo-classes are used to select left-hand and right-hand pages, or the first page in a document.

There are different page pseudo-classes:

  • @page:left: used to set properties for left-hand pages.
    @page:left { size: landscape; margin-left: 2cm; }
  • @page:right: used to set properties for right-hand pages.
    @page:right { size:landscape; margin-left: 2.5cm; }
  • @page:first: used for defining the properties of the first page in a document.
    @page:first { size: portrait;
    margin-left: 2.5cm;
    margin-right: 2cm;
    margin-bottom: 1cm;
    margin-top: 4cm;}

ID selectors

ID selectors (identifiers) are used to reference a single page element as indicated by its identifier. IDs are mainly used to isolate HTML elements with JavaScript.

An ID selector's syntax is:

#nom_ID { style }

This style is called in the following manner:

<BALISE ID="nom_ID" > ... </BALISE>

There can be only one ID per page! Also, note the absence of the # when invoking the ID selector.This document entitled « CSS - Style Classes » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.

CSS - Declaring a style sheet Style sheets are not directly integrated into the W3C's HTML recommendations. For this reason, you need to include elements in the HTML code indicating both the type of document, meaning the version of the HTML and CSS recommendations used by the... en.kioskea.net/css/cssimplant.php3
Style sheets - Introduction The concept of style sheets first appeared in 1996 when the W3C published a new recommendation entitled "Cascading Style Sheets", or CSS for short. The principle behind style sheets involves using a single document to store the page layout... en.kioskea.net/css/cssintro.php3
HTML 4.0 - Positioning elements Using style sheets along with the and tags, you can specify the location of text or images down to the pixel. This is possible with versions 4 and higher of Netscape and Internet Explorer; however, the technique is still problematic and... en.kioskea.net/css/cssposition.php3
Create CSS easilyCreate CSS easily Easy links CSS is a short term for Cascading Style Sheets. CSS is used to alter the display of the HTML coded environment. For example, using CSS can change the appearance of your scroll bar, the color, headings... en.kioskea.net/faq/sujet-593-create-css-easily
How to count number of words in MS Words sheet!How to count number of words in MS Words sheet! It is quite simple to count the number of words in a Microsoft word sheet. This tip might be very useful for example, if you wish to make a presentation on Microsoft word for an approximate number... en.kioskea.net/faq/sujet-354-how-to-count-number-of-words-in-ms-words-sheet
How to insert picture background on Microsoft!How to insert picture background on Microsoft! To make a work sheet more appealing, you can add picture to your background. Below is a tip for doing so. Open your Microsoft and select “Format”> “Backgrounds” > “Printed... en.kioskea.net/faq/sujet-334-how-to-insert-picture-background-on-microsoft
To prepare Attendence Report with Excel sheetHello, I will describe what I want to do . I have 60 residents working in our department. They attend morning report everyday. So I have prepared excel sheet( Named Attendance Table) which has column A1:A60 with names of residents B1:B60 with... en.kioskea.net/forum/affich-22740-to-prepare-attendence-report-with-excel-sheet
Html code in shell script..........Hello, I want to share one of article of a recent magazine to write html code in shell script.......... any title Our content information goes here this is written in shell script as... en.kioskea.net/forum/affich-17105-html-code-in-shell-script
Excel: Macro HelpHello, I ned some help setting up a macro for Excel. I have a lost of IDs/SKUs on Sheet 1, and a partial list on Sheet2. What I would like to do is cross-check the two sheets and delete all the rows on Sheet1 that's already listed on sheet2. The... en.kioskea.net/forum/affich-5884-excel-macro-help
Download ShellOpacitySeveral editors offer topics to change the graphic appearance of Windows. But sometimes little is enough so that your interface changes look. ShellOpacity is a tool allowing to change simply the opacity of your bar of task of the menu to start. On... en.kioskea.net/telecharger/telecharger-665-shellopacity
Download ShellExViewShellEXView is a free tool used to install and manage shell extensions in Windows.Shell extensions enable users to view program specific menus when right clicking various file types.The ShellExView utility displays the details of shell extensions... en.kioskea.net/telecharger/telecharger-884-shellexview
Download Electric SheepElectric Sheep is a screen of wakefulness source open created by Scott Draves. He can be installed on any operating system Windows or Mac.During the alerting of your computer, the screen of wakefulness is displayed and the computer is connected to... en.kioskea.net/telecharger/telecharger-753-electric-sheep
Newest BlackBerry aims to keep Apple iPhone at bayA visitor walks past a display of Blackberry "Smart Phones" at the CeBIT trade fair in Hanover. Research in Motion unveiled Monday its latest BlackBerry smartphone with new styling and technology that aims to bite into Apple's juicy iPhone... en.kioskea.net/actualites/newest-blackberry-aims-to-keep-apple-iphone-at-bay-10364-actualite.php3
Techno-savvy Iraqis surf the cyber wavesAn Iraqi woman talks on her mobile phone as she walks on campus at Baghdad's Al-Mustansiriyah University on March 16, 2008. Saddam Hussein deemed Iraqis could live without modern technology such as mobile phones and the Internet. Now that his... en.kioskea.net/actualites/techno-savvy-iraqis-surf-the-cyber-waves-10227-actualite.php3
Virtual games a hit among retired US seniorsJeanne Gildea (R), 81, reacts to a shot as she plays in a bowling tournament against fellow community members, including Elaine Fowler (L), 82, on the Nintendo Wii game system, at the Riderwood Retirement Community in Silver Spring, Maryland, on... en.kioskea.net/actualites/virtual-games-a-hit-among-retired-us-seniors-10025-actualite.php3
CSS - Units With style sheets, you can use numeric values to set style properties in multiple ways: absolutely, meaning in units which are independent of the form of output (such as in centimetres); relatively, meaning in units relative to an element. Style... en.kioskea.net/css/css-unites.php3
Linux - The shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines that are entered by the latter.... en.kioskea.net/linux/linshell.php3
HTML - Style tags Style tags modify the typography of the text. They can overlap with other style tags, as with word processing programs. Here is a list of style tags recognised by most browsers (although some of which may produce identical effects in certain... en.kioskea.net/html/htmlstyle.php3
Answers for « Style sheets »