Friday 9 January 2015


CORE ATTRIBUTES:

The four core attributes that you can use on the majority of HTML elements (although not all) are:
id ,title ,class ,style.These attributes are revisited when they have special meaning for an element that differs from the description given here; otherwise their use can generally be described as you see in the subsections that follow.

ID ATTRIBUTE:

You can use the id attribute to uniquely identify any element within a page. You might want to
uniquely identify an element so that you can link to that specific part in the document or to specify
that a CSS style or piece of JavaScript should apply to the content of just that one element within
the document.The syntax for the id attribute is as follows (where string is your chosen value for the attribute):
id="string"
For example, you can use the id attribute to distinguish between two paragraph elements, like so:
<p id="accounts">This paragraph explains the role of the accounts department.</p>
<p id="sales">This paragraph explains the role of the sales department.</p>
Following are some special rules for the value of the id attribute:
➤➤ Must begin with a letter (A–Z or a–z) and can then be followed by any number of letters,digits (0–9), hyphens, underscores, colons, and periods. (You may not start the value with a digit, hyphen, underscore, colon, or period.)
➤➤ Must remain unique within that document; no two id attributes may have the same value within one HTML page. This case should be handled by the class attribute.

CLASS ATTRIBUTE:

You can use the class attribute to specify that an element belongs to a class of elements. For example,
you might have a document that contains many paragraphs, and a few of those paragraphs might contain a summary of key points, in which case you could add a class attribute whose value is summary to the relevant <p> elements to differentiate those paragraphs from the rest in the document.
<p class="summary">Summary goes here</p>
It is commonly used with CSS. The syntax of the class attribute is as follows:
class="className"
The value of the attribute may also be a space-separated list of class names, for example:
class="className1 className2 className3"

TITLE ATTRIBUTE:

The title attribute gives a suggested title for the element. The syntax for the title attribute is
as follows:
title="string"
The behavior of this attribute depends upon the element that carries it; although, it is often displayed
as a tooltip or while the element loads. Not every element that can carry a title attribute actually
needs one, so when you meet an element that particularly benefits from use of this attribute, you will
see the behavior it has when used with that element.

STYLE ATTRIBUTE:

The style attribute enables you to specify CSS rules within the element. You meet CSS later,but for now, here is an example of how it might be used:
<p style="font-family:arial; color:#FF0000;">Some text.</p>
As a general rule, however, it is best to avoid the use of this attribute. If you want to use CSS rules
to govern how an element appears, it is better to use a separate style sheet instead. The only place
where this attribute is still commonly used is when it is set with JavaScript. You learn more about that later, “Working with jQuery,” when you’re introduced to jQuery’s powerful tools for
manipulating HTML elements.


No comments:

Post a Comment