O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting by ID

Another way of selecting elements is by their ID values, which you set with an ID attribute. To create a selector that targets elements with a certain ID, you use the syntax ELEMENT_NAME#ID_VALUE. For example, here's how I create a rule for <P> elements with the ID value of "TOP":

Listing . ch09_10.css
 
TITLE {display: block; font-size: 24pt; font-weight: bold;
text-align: center; text-decoration: underline}
AUTHOR {display: block; font-size: 18pt; font-weight: bold;
text-align: center}
SECTION {display: block; font-size: 16pt; font-weight: bold;
text-align: center; font-style: italic}
P {display: block; margin-top: 10}
P#TOP {display: block; margin-top: 30}
				

To give an element the ID "TOP", I can add an ID attribute like this, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required