The :nth-child() CSS pseudo-class matches elements based on the indexes of the elements in the child list of their parents. In other words, the :nth-child() selector selects child elements according to their position among all the sibling elements within
The child combinator (>) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first.
The :only-child CSS pseudo-class represents an element without any siblings. This is the same as :first-child:last-child or :nth-child(1):nth-last-child(1), but with a lower specificity.
The :nth-last-child() CSS pseudo-class matches elements based on their position among a group of siblings, counting from the end.
Toggle history 9.5 Toggle history 3.1 Toggle history 18 Toggle history 4 Toggle history 10.1 Toggle history 4 Toggle history 1.0 Toggle history 37 Toggle history Matches elements with no parent 57 Toggle history 79 Toggle history 52 Toggle history ...
对于p:nth-child(2),如果它是一个段落,它将选择其父元素的第二个元素,而p:nth-of-type(2)将...
Use of the:nth-childselector can often help to remove need for classes like.item--lastor.item--clear. If you need to style in an iterative way, you can keep all styles contained in your CSS instead of adding extra classes to your HTML. ...
CSS selector: `:only-child` Global usage 96.88% + 0% = 96.88% IE ❌ 6 - 8: Not supported ✅ 9 - 10: Supported ✅ 11: Supported Edge ✅ 12 - 130: Supported ✅ 131: Supported Firefox ✅ 2 - 131: Supported ✅ 132: Supported ✅ 133 - 135: Supported Chrome ✅ 4 ...
CSS cssCopy to Clipboardplay p:first-child { color: lime; background-color: black; padding: 5px; } Result playStyling a list HTML htmlCopy to Clipboardplay <ul> <li>Item 1</li> <li>Item 2</li> <li> Item 3 <ul> <li>Item 3.1</li> <li>Item 3.2</li> <li>Item 3.3</li...
MDN Docs Also Known As… The child combinator is what the spec calls it, but you’ll also hear it called: child selector direct descendent selector direct descendant combinator Browser Support ChromeSafariFirefoxOperaIEAndroidiOS AnyAnyAnyAny7+AnyAny ...