ComputersProgramming

CSS, pseudo-class, pseudo-element: hover, child, target

Combining HTML and CSS, you can manage absolutely all elements of a web page. With styles, you easily change the appearance of any block or line. Often, a coder needs to perform a more complex task - to change the appearance of not the element itself, but its individual part or certain state. In this case, CSS pseudo-classes come to the rescue.

Pseudo-classes work on the same principle as regular classes in markup, but they are not physically present on the page. With their help, you can select items based on the information that is not included in the document, which can not be selected with the usual selector. Here's a simple example: you have a red button, and you want it to turn blue when you hover it. Theoretically it can be implemented in JavaScript, but why such complexity? Much more convenient to use : hover CSS. With its help, you can give the unit any parameters that will work only when you hover the mouse cursor.

The CSS pseudo-class list is updated regularly. Perhaps while you are reading this material, several new ones will appear. First, let's look at the ones that appeared in the CSS3 specification.

: Nth-of-type

Suppose you have a list in which you want to use the alternation of colors, i.e. the first line will, for example, be written in red, and the second line will be blue, the third red again, the fourth again blue. Previously, you had to create new classes for this. Past makeers added each element of the list to the class, and then changed their appearance in the style sheet. It was not very convenient and polluted the layout.

Now everything is easier. Use the CSS pseudo class: nth-of-type. This will give an opportunity to get the necessary visual effect without changing anything in the markup. The principle of operation is simple: you specify a selector, and in parentheses after its name, write a formula or keyword that will find the required elements. For example: nth-of-type (even) finds all even elements, and: nth-of-type (odd) - odd. There are a large number of formulas that are used for the most accurate control. In parentheses, you can specify a number - in which case the styles will be applied to the element whose index is equal to this number.

: Nth-child

This CSS pseudo-class is similar to the previous one, but unlike it works exclusively with the children of the selected element. For example, if you want to use it to customize the appearance of the

  • tags in the list, you need to use the ul: nth-child construct, since
  • Similar articles

     

     

     

     

    Trending Now

     

     

     

     

    Newest

    Copyright © 2018 en.unansea.com. Theme powered by WordPress.