Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between first-of-type and first child in css

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the difference between first-of-type and first child in css, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

(1) first-child

H2:first-child: H2 element is selected because H2 element is the first child element of div.

P:first-child: select no element, because p is not the first child element of div, but the second child element of div.

Span:first-child: no element can be selected because span is not the first child element of div, but the third child element of div

(2): first-of-type

H2:first-of-type: H2 element is selected, because H2 element is the first H2 element of all H2 elements in div, in fact, there is only one child element of H2

P:first-of-type: the p element is selected, because the p element is the first p element of all p elements in div, and in fact there is only one child element of p

Span:first-of-type: the span element of id= "first" is selected, because there are two span elements in the div element, and we choose the first of the two.

Summary:

": first-child" selects the first child element under the parent element (regardless of element type), while ": first-of-type" selects the first child element of an element type under the parent element (distinguishing element type).

": last-child" and ": last-of-type", "nth-child (n)" and ": nth-of-type (n)" can also be understood in the same way, which is no longer cumbersome here.

Thank you for reading this article carefully. I hope the article "what is the difference between first-of-type and first child in css" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report