You get a bonus - 1 coin for daily activity. Now you have 1 coin

CSS Identifiers

Lecture



The identifier (also called the “ID selector”) defines a unique element name that is used to change its style and access it through scripts.

The syntax for using the identifier is as follows.

# Identifier name {property1: value; property 2: value; ...}

When describing an identifier, you first specify a hash sign (#), followed by the identifier name. It must begin with a Latin character and can contain the hyphen (-) and underscore (_) characters. The use of Russian letters in identifier names is not allowed. Unlike classes, identifiers must be unique, in other words, they appear only once in the document code.

The identifier is accessed in the same way as classes, but the id attribute is used as a keyword for the tag, the value of which is the identifier name (example 9.1). The grid symbol is no longer indicated.

Example 9.1. Use id

HTML5CSS 2.1IECrOpSaFx

<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Идентификаторы</title> <style> #help { position: absolute; /* Абсолютное позиционирование */ left: 160px; /* Положение элемента от левого края */ top: 50px; /* Положение от верхнего края */ width: 225px; /* Ширина блока */ padding: 5px; /* Поля вокруг текста */ background: #f0f0f0; /* Цвет фона */ } </style> </head> <body> <div id="help"> Этот элемент помогает в случае, когда вы находитесь в осознании того факта, что совершенно не понимаете, кто и как вам может помочь. Именно в этот момент мы и подсказываем, что помочь вам никто не сможет. </div> </body> </html> 


In this example, the style of the <div> tag is defined using an identifier named help (Fig. 9.1).

  CSS Identifiers

Fig. 9.1. The result of the use of the identifier

As with the use of classes, identifiers can be applied to a specific tag. The syntax will be as follows.

Tag # identifier name {property1: value; property 2: value; ...}

First, the name of the tag is indicated, then without spaces, the lattice character and the name of the identifier. Example 9.2 shows the use of an identifier as applied to the <p> tag.

Example 9.2. ID with tag

 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Идентификаторы</title> <style> P { color: green; /* Зеленый цвет текста */ font-style: italic; /* Курсивное начертание текста */ } P#opa { color: red; /* Красный цвет текста */ border: 1px solid #666; /* Параметры рамки */ background: #eee; /* Цвет фона */ padding: 5px; /* Поля вокруг текста */ } </style> </head> <body> <p>Обычный параграф</p> <p id="opa">Параграф необычный</p> </body> </html> 

The result of this example is shown in Fig. 9.2.

  CSS Identifiers

Fig. 9.2. Type of text after applying the style

In this example, the style is entered for the <p> tag and for the same tag, but with the indication of the identifier opa.

Questions to check

1. In what situations can the names of identifiers and classes be called the same?

  1. Never, this is unacceptable.
  2. Anyway.
  3. Only if they apply to a single element.
  4. Only if they apply to different elements.
  5. Only if they appear in the code once.

2. What identifier name is spelled incorrectly?

  1. id_1id1
  2. aaa-1-1-1
  3. L0g0
  4. bla-bla
  5. cravedko

3. What error is contained in the following code?

<div class = "frame1">
<div id = "_ nav"> <a href="209.html"> Connecting to MySQL via PHP </a> </ div>
<div id = "_ nav"> <a href="213.html"> Creating tables in phpMyAdmin </a> </ div>
<div id = "_ nav"> <a href="211.html"> Database Structure </a> </ div>
</ div>

  1. The class name is spelled incorrectly.
  2. Identifier names are spelled incorrectly.
  3. Incorrect tagging.
  4. Duplicate ids.
  5. Different identifiers for similar elements.

4. How to set the correct style for the <div> tag with the loom identifier?

  1. loom {font-size: bold; }
  2. div {font-size: bold; }
  3. .loom {font-size: bold; }
  4. # loom # {font-size: bold; }
  5. #loom {font-size: bold; }

Answers

1. In any case.

2. cravedko

3. Duplicate identifiers.

4. #loom {font-size: bold; }

created: 2014-10-19
updated: 2021-03-13
133074



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Cascading CSS / CSS3 Style Sheets

Terms: Cascading CSS / CSS3 Style Sheets