6.1 The class attribute and the style tag
But that's not all. After hundreds of "styles" were invented, the question arose: how to use them? And then they came up with the idea of grouping them into “classes”. These are, of course, not the same classes as in Java. Just special style groups.
And if before using “classes” you had a picture:
<img src="logo.png" style="width=100px;height=100px;opacity=0.5">
Now it could be written as:
<img src="logo.png" class="picture">
<style>
img.picture {
width=100px;
height=100px;
opacity=0.5
}
</style>
We created a special one «style» picture
and transferred the style values from the style
. And then we tied the <img> and the "style" picture with the tag class
.
6.2 Selector, types of selectors
These styles, rendered separately, became known as classes
or selectors
. They have several important features.
One html-element
can have multiple selectors. Their names are indicated with a space. Example:
<img src="logo.png" class="picture main">
One reason we've touched on selectors here is because they can be applied automatically. And this useful property will be used very often in the future. Including Java developers.
Here is a short list of them:
# | Selector | Example | Description |
---|---|---|---|
1 | * |
|
Applies to all elements of an HTML document. |
2 | #id |
|
The # is followed by the id of the element to which the given style is to be applied. |
3 | tag |
|
Applies to all tables in the document. |
4 | tag.selector |
|
Applies to all document tables that have the class attribute specified. |
5 | .selector |
|
Applies to all elements that have the class attribute specified. Any tag. |
6 | parent child |
|
Applies to all elements where the parent tag contains the main class and the child tag contains the article class. |
7 | tag: link |
|
The :link pseudo-class is used to style links that the user hasn't clicked on yet. |
8 | tag:visited |
|
The :link pseudo-class is used to style links that the user has already clicked on. |
9 | tag:checked |
|
This pseudo-class will select only checked UI elements: radio buttons or checkboxes. |
10 | tag: hover |
|
This pseudo-class allows you to change the style of an element when hovering over it with the mouse. |
eleven | tag:first child |
|
This pseudo-class will only allow the first child element to be selected. |
You don't have to memorize it all. But it would be good if you studied this table a couple of times and all this was deposited in your head. Without the web in modern life, nowhere, and on the web - nowhere without selectors.
GO TO FULL VERSION