Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在第n个子项后选择标记_Html_Css_Css Selectors - Fatal编程技术网

Html 在第n个子项后选择标记

Html 在第n个子项后选择标记,html,css,css-selectors,Html,Css,Css Selectors,如何使用CSS在给定的:n-child()之后选择元素 div:nth-child(1) + p { font-size: 40pt; } 不为我工作,我很困惑 将选择div:n子项(3)中的每个p标记作为直接子项 div:nth-child(3) p { font-size: 40pt; } 将选择div:n子元素(3)中的每个p标记,即使在dom中嵌套了多个级别。在这种情况下,div:n子元素(3)和p之间的空间是重要的字符 div:nth-child(3) + p { font-si

如何使用CSS在给定的
:n-child()之后选择元素

div:nth-child(1) + p { font-size: 40pt; }
不为我工作,我很困惑

将选择div:n子项(3)中的每个p标记作为直接子项

div:nth-child(3) p { font-size: 40pt; }
将选择div:n子元素(3)中的每个p标记,即使在dom中嵌套了多个级别。在这种情况下,div:n子元素(3)和p之间的空间是重要的字符

div:nth-child(3) + p { font-size: 40pt; }
将选择一个p标记,该标记是同一dom级别上div:n子元素(3)之后的第一个元素(不在其他元素内部)


将选择位于同一dom级别的第n个子项(3)之后的每个p标记。

如果要选择第n个子项(3)之后的p标记,为什么不选择第n个子项(4)
? 直接为后面的子项尝试第n个子项(3)+div。 为之后的每个孩子尝试
nht child(3)~div


关于smashing magazine的更多信息:

+p
==下一步,
>p
==直接后代它实际上取决于HTML的结构。您是否尝试过
div:nth child(3)p
?您是否也可以发布标记?您的代码所做的是选择一个
p
,它是第三个
div
元素的子元素。选择哪个
p
取决于您的选择器。您可能应该花点时间阅读W3联盟关于的文档。好的@Michael_B,我做了。我尝试了这个,但不知道我做错了什么。您正在使用相邻同级(+)选择器,但您想进入:是,thx。但是我只需要第一个直接的,所以+不起作用。我需要进入并选择第一个或第n个孩子,thx div:nth child(1)>p:first child{font size:40pt;}
div:nth-child(3) + p { font-size: 40pt; }
div:nth-child(3) ~ p { font-size: 40pt; }