Sử dụng bộ chọn CSS:nth-of-type (n) để tạo kiểu cho mọi phần tử
là phần tử thứ n
của phần tử cha của nó. Bạn có thể thử chạy mã sau để triển khai:bộ chọn thứ n-of-type (n)
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-of-type(2) {
background: yellow;
}
</style>
</head>
<body>
<p>This is demo text 1.</p>
<p>This is demo text 2.</p>
<p>This is demo text 3.</p>
<p>This is demo text 4.</p>
</body>
</html>