Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Managing Style Sheets > 11.3. Assigning Style Sheet Rules to an Individual ...

Assigning Style Sheet Rules to an Individual Element

Problem

You want a single element to stand out by having its own style sheet rule.

Solution

Define an ID selector for a style rule and assign that same selector name to the id attribute of an element. An ID selector name is preceded by a hash mark (#), as in the following example:

	#special {border:5px; border-style:ridge; border-color:red}

This rule applies to the following element:

	<div id="special>...</div>

When you create your HTML, assign an identifier to no more than one element on the page. Duplicate identifiers assigned to id attributes of multiple elements just confuse scripts.

Discussion

ID names are entirely up to you, but you should follow the same restrictions for these identifiers as those detailed for class names in Assigning Style Sheet Rules to a Subgroup of Elements. Be aware that if an element has both a class and id value assigned to it and those names have style rules associated with them, the style rule for the id takes precedence over the one for the class value wherever a conflict arises. This should be of concern to you only if the style rules for both the class and id values adjust the same style properties.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint