为什么第三个元素中的nth-of-type元素无法正常工作?

huangapple go评论61阅读模式
英文:

Why do nth-of-type elements fail to work at third-element?

问题

I have some question about Css nth-of-type.
In the code below,
nth-of-type(2) and nth-of-type(3) is work ,
but nth-of-type(4) and nth-of-type(5) can't work.

Is there anything wrong in my code?

<div id="insideCircle">
    <div class="outsideNumber"></div>
    <div class="outsideNumber"></div>
    <div class="outsideNumber"></div>
    <div class="outsideNumber"></div>
    <div class="outsideNumber"></div>
</div>
.outsideNumber{
  width: 0px;
  height: 250px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.outsideNumber:nth-of-type(2){
  width: 1px;
  background-color: red;
  transform: translate(-50%,-50%) rotate(30deg);
}
.outsideNumber:nth-of-type(3){
  width: 1px;
  background-color: yellow;
  transform: translate(-50%,-50%) rotate(60deg);
};

.outsideNumber:nth-of-type(4){
  width: 1px;
  background-color: green;
  transform: translate(-50%,-50%) rotate(90deg);
};

.outsideNumber:nth-of-type(5){
  width: 1px;
  background-color: lightblue;
  transform: translate(-50%,-50%) rotate(120deg);
}

When I disable nth-of-type(2), the 3 and 4 element work but 5 not.
It seems like nth-of-type(4) can be selected, but when it becomes the third element, it's broken.
I wonder why nth-of-type is broken after the third element?

And also I want to know, does nth-of-type work on class?
I see some documents say it can only select HTML tags.
If it can't work on classes, then why does .outsideNumber:nth-of-type(2) work?

英文:

I have some question about Css nth-of-type.
In the code below,
nth-of-type(2) and nth-of-type(3) is work ,
but nth-of-type(4) and nth-of-type(5) can't work.

Is there anything wrong in my code?

&lt;div id=&quot;insideCircle&quot;&gt;
      &lt;div class=&quot;outsideNumber&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;outsideNumber&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;outsideNumber&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;outsideNumber&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;outsideNumber&quot;&gt;&lt;/div&gt;
&lt;div&gt;
.outsideNumber{
  width: 0px;
  height: 250px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.outsideNumber:nth-of-type(2){
  width: 1px;
  background-color: red;
  transform: translate(-50%,-50%) rotate(30deg);
}
.outsideNumber:nth-of-type(3){
  width: 1px;
  background-color: yellow;
  transform: translate(-50%,-50%) rotate(60deg);
};

.outsideNumber:nth-of-type(4){
  width: 1px;
  background-color: green;
  transform: translate(-50%,-50%) rotate(90deg);
};

.outsideNumber:nth-of-type(5){
  width: 1px;
  background-color: lightblue;
  transform: translate(-50%,-50%) rotate(120deg);
}

When I disable nth-of-type(2) the 3 and 4 element work but 5 not.
It seems like nth-of-type(4) can be select but when it become the third element,it's broken.
I wonder why nth-of-type broken after the third element?

and also I want to know is nth-of-type work on class?
I see some document say it can only select html tag.
If it can't work on class,then why the .outsideNumber:nth-of-type(2) work?

答案1

得分: -1

代码是正确的。只有一个分号,所以你需要移除它,就这样。

.outsideNumber:nth-of-type(3){	
  width: 1px;	
  background-color: yellow;	
  transform: translate(-50%,-50%) rotate(60deg);	
}
.outsideNumber:nth-of-type(4){	
  width: 1px;	
  background-color: green;	
  transform: translate(-50%,-50%) rotate(90deg);	
}

希望这对你有帮助。

英文:

The code is correct only.
you have been given a semi-colon, so you have to remove that's it.

.outsideNumber:nth-of-type(3){	
  width: 1px;	
  background-color: yellow;	
  transform: translate(-50%,-50%) rotate(60deg);	
}
.outsideNumber:nth-of-type(4){	
  width: 1px;	
  background-color: green;	
  transform: translate(-50%,-50%) rotate(90deg);	
}

I hope this worked for you.

huangapple
  • 本文由 发表于 2023年5月17日 14:26:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定