Home>Article>Web Front-end> How to select elements in css

How to select elements in css

藏色散人
藏色散人 Original
2021-04-29 09:41:33 2385browse

Css method of selecting elements: first create an HTML sample file; then create multi-line text in the body; finally use the ":nth-of-type(n)" selector or ":last-child" Selector to select elements.

How to select elements in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

To use CSS to achieve one-to-one, one-to-many or many-to-one control of elements in an HTML page, you need to use CSS selectors. Elements in HTML pages are controlled through CSS selectors.

How to select elements in css?

css can use the :nth-of-type(n) selector or :last-child selector to select elements. The :nth-of-type(n) selector matches the nth sibling element of the same type. The :last-child selector matches every element that is the last child of its parent.

Use: nth-of-type selector to select elements Example:

      

This is a heading

The first paragraph.

The second paragraph.

The third paragraph.

The fourth paragraph.

Rendering:

How to select elements in css

Use last-child selector Example of selecting elements:

    

这是标题

第一个段落。

第二个段落。

第三个段落。

第四个段落。

第五个段落。

Rendering:

How to select elements in css

For more detailed HTML/CSS knowledge, please visit theCSS Video Tutorialcolumn !

The above is the detailed content of How to select elements in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn