Html 如何在 :not() 中使用 css first-child

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43279368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:34:00  来源:igfitidea点击:

How to use css first-child with :not()

htmlcsscss-selectors

提问by TyForHelpDude

There is a parent divwith id = "cooldiv". It has many divelements inside. Now I need to set a css property to all the child div-s except the first one.

有一位家长divid = "cooldiv". 它div里面有很多元素。现在我需要为div除第一个之外的所有子-s设置一个 css 属性。

So, this is what I've tried so far to accomplish this task:

所以,这是我迄今为止为完成这项任务所做的尝试:

#cooldiv .row:not(first-child) {
    top: -50px;
}

But, of course, it didn't work out. What's wrong here? This is the screenshot of the source code:

但是,当然,它没有成功。这里有什么问题?这是源代码的截图:

enter image description here

在此处输入图片说明

回答by curveball

Try #cooldiv .row:not(:first-child). It seems you missed :before first-child. Maybe that's why it doesn't function?

试试#cooldiv .row:not(:first-child)。看来你:之前错过了first-child。也许这就是它不起作用的原因?

回答by user3161374

Try something like that

尝试这样的事情

#cooldiv .row:first-child {
    top:0px;
} #cooldiv .row {
    top:-50px;
}