Đối với các yếu tố cấp độ bên trong, giải pháp đầu tiên hoạt động hoàn hảo.
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
ĐọcBàn luậnXem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Syntax:
div ul + ul {
background-color: #900;
}
0Example:
div ul + ul {
background-color: #900;
}
6div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
8div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
0div ul + ul {
background-color: #900;
}
7div li~li {
color: red;
}
2div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4div ul + ul {
background-color: #900;
}
7div li~li {
color: red;
}
6div li~li {
color: red;
}
7div li~li {
color: red;
}
6div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4div ul + ul {
background-color: #900;
}
7ul:not(:first-of-type) {}
2div ul + ul {
background-color: #900;
}
9ul:not(:first-of-type) {}
4ul:not(:first-of-type) {}
5ul:not(:first-of-type) {}
4ul:not(:first-of-type) {}
7ul:not(:first-of-type) {}
4ul:not(:first-of-type) {}
9ul:not(:first-of-type) {}
4div ul:nth-child(n+2) {
background-color: #900;
}
1div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:nth-child(n+2) {
background-color: #900;
}
3div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:nth-child(n+2) {
background-color: #900;
}
5div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:nth-child(n+2) {
background-color: #900;
}
7div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:nth-child(n+2) {
background-color: #900;
}
9Bàn luận
div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:not(:first-child) li{
background-color: #900;
}
3ul:not(:first-of-type) {}
4ul:not(:first-of-type) {}
9ul:not(:first-of-type) {}
4div ul:not(:first-child) li{
background-color: #900;
}
7div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:not(:first-child) li{
background-color: #900;
}
9ul:not(:first-of-type) {}
4ul:not(:first-of-type) {}
9div li~li {
color: red;
}
4<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3ul:not(:first-of-type) {}
2div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
0<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3div li~li {
color: red;
}
2div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
0div ul + ul {
background-color: #900;
}
7p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
2div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4div ul + ul {
background-color: #900;
}
7p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
6p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
7p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
6div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4div ul + ul {
background-color: #900;
}
7p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
6<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>
</ul>
</li>
</ul>
3p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
6div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4div ul + ul {
background-color: #900;
}
7<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>
</ul>
</li>
</ul>
8div ul + ul {
background-color: #900;
}
9Bộ chọn này được sử dụng để chọn mọi yếu tố không phải là con đầu tiên của phần tử cha. Nó được biểu diễn như một đối số dưới dạng: không phải phần tử (đầu tiên).
div ul:nth-child(n+2) {
background-color: #900;
}
2div ul:not(:first-child) li{
background-color: #900;
}
1div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
06div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
12div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9ul:not(:first-of-type) {}
4<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
2div ul + ul {
background-color: #900;
}
9ul:not(:first-of-type) {}
4div ul + ul {
background-color: #900;
}
7ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
2div ul + ul {
background-color: #900;
}
9div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
26div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
32div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
38div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9ul:not(:first-of-type) {}
4<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
2div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
4<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3<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>
</ul>
</li>
</ul>
8div ul + ul {
background-color: #900;
}
9div li~li {
color: red;
}
0<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3p:first-child {
color: lime;
background-color: black;
padding: 5px;
}
2div ul + ul {
background-color: #900;
}
9ul:not(:first-of-type) {}
4div ul + ul {
background-color: #900;
}
7ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
2 ul:not(:first-of-type) {}
2ul li {
color: blue;
}
ul li:first-child {
color: red;
font-weight: bold;
}
4__95div ul:nth-child(n+2) {
background-color: #900;
}
2div ul + ul {
background-color: #900;
}
7div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
00____div ul + ul {
background-color: #900;
}
4div ul + ul {
background-color: #900;
}
9
Explanation: The above example shows that a is a container Tag. It contains
Tag so it selects all child elements of tag except its first-child.
<div>
<p>This text is selected!</p>
<p>This text isn't selected.</p>
</div>
<div>
<h2>This text isn't selected: it's not a `p`.</h2>
<p>This text isn't selected.</p>
</div>
3div ul + ul {
background-color: #900;
}
8div ul + ul {
background-color: #900;
}
55 The browser supported by :not:(first-child) selectors are listed below:
- Apple Safari 3.1
- Google Chrome 4.0
- Firefox 3.0
- Opera 9.6
- Internet Explorer 7.0
Làm thế nào để tôi không bao gồm đứa con đầu lòng của tôi trong CSS?
Bộ chọn này được sử dụng để chọn mọi yếu tố không phải là con đầu tiên của phần tử cha.Nó được biểu diễn như một đối số dưới dạng: không phải phần tử (đầu tiên).Giải thích: Ví dụ trên cho thấy A là thẻ container.
:not(first-child) element. Explanation: The above example shows that a
is a container Tag.
Làm thế nào để tôi đề cập đến đứa trẻ thứ hai trong CSS?
Bất kể,: nth-of-type là cách đúng đắn để làm điều đó.Nếu bạn có một mỗi, thì bạn có thể muốn nói.container li: nth-of-type (2) a.Lưu câu trả lời này.
Làm cách nào để áp dụng CSS cho mỗi đứa trẻ thứ ba?
Có, bạn có thể sử dụng những gì được gọi là: Bộ chọn Nth-Child.Trong trường hợp này, bạn sẽ sử dụng: li: nth-child (3n) {// kiểu dáng cho mỗi yếu tố thứ ba ở đây.}li:nth-child(3n) { // Styling for every third element here. }
Làm cách nào để sử dụng CSS với đứa con đầu lòng?
Các: CSS Pseudo-Class duy nhất đại diện cho một yếu tố không có anh chị em.Điều này giống như: First-Child: Last-Chill hoặc: Nth-Child (1): Nth-Last-Child (1), nhưng với độ đặc hiệu thấp hơn.first-child:last-child or :nth-child(1):nth-last-child(1) , but with a lower specificity.