Css3: last-of-type has no effect on the use of class names?

<!DOCTYPE html>
<html>
<head>
<style> 
.p:last-of-type
{
background:-sharpff0000;
}
</style>
</head>

<body class="body">

<h1></h1>

<p class="p">

<p class="p">

<p class="p">

<div>11</div> </body> </html>

doesn"t work on the class name .p.last-of-type, just change it to p.last-of-type, why doesn"t it work on the class name?

Css
Aug.24,2021

this selector is also related to tags. You can try
to verify that

<p class="p">

<p class="p">

<p class="p">

<div></div>

change the last one to a non -'p 'element to get the desired result
validation 2:

<p class="p">

<p class="p">

<p class="p">

<div class='p'></div>

found that the last p element and div are both selected
clipboard.png


.p: last-of-type means classname contains p and is the last


of a type element under the parent element. The

selector first finds the corresponding element according to .p, and then starts to find the sibling node of the same type (p) according to the tag (p) of the corresponding element. If this element is the last of the siblings, it is true, otherwise it does not hold

.

if there are many sibling nodes of an element, it is impossible to use last-of-type to find the last element of a class.

here is an example

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <style>
  .p:last-of-type {
    background: -sharpff0000;
  }
  
  div.p:last-of-type{
    color:blue;
  }
  </style>
</head>

<body class="body">
  <h1 class="p"></h1>
  <h1 class="p">2</h1>

  <p class="p">

<p class="p">

<p class="p">

<div>div 111</div> <div class="p">div 222</div> </body> </html>

this is two css selectors.
different css selectors are mixed together on the premise that one is a child of the other or a lower-level relationship.

: nth-of-type () matches each element of the Nth child element of a specific type of parent element. Limited to the same element tag.
n can be a number, a keyword, or a formula.
1. First find the parent class
2 of the pseudo-class caller (element), and then find the nth child element of the same element name under the parent class. If so, apply css, or do not apply

.
-sharp 
img:nth-of-type(2n+1) { float: right; }
img:nth-of-type(2n) { float: left; }

-sharp 
.className:nth-of-type(2n+1) { float: right; }
.className:nth-of-type(2n) { float: left; }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54d0f-452d1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54d0f-452d1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?