英文:
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?
<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 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论