CSS :nth-child() pseudo-class
How do I make an css :nth-child() pseudo-class?
Very basic examples of how to use the :nth-child() pseudo-class.. What is a css :nth-child() pseudo-class? How do you make a css :nth-child() pseudo-class? This script and codes were developed by Ricardo Zea on 28 September 2022, Wednesday.
CSS :nth-child() pseudo-class - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>CSS :nth-child() pseudo-class</title> <link rel='stylesheet prefetch' href='css/https___s3_us_west_2_amaz.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>CSS <code>:nth-child()</code> pseudo-class</h1>
<p>Very basic examples of how to use the <code>:nth-child()</code> pseudo-class.</p>
<div class="flex-ctnr"> <ol class="ex1"> <li>Alpha</li> <li>Beta</li> <li>Gamma</li> <li>Delta</li> <li>Epsilon</li> <li>Zeta</li> <li>Eta</li> <li>Theta</li> <li>Iota</li> <li>Kappa</li> </ol> <ol class="ex2"> <li>Alpha</li> <li>Beta</li> <li>Gamma</li> <li>Delta</li> <li>Epsilon</li> <li>Zeta</li> <li>Eta</li> <li>Theta</li> <li>Iota</li> <li>Kappa</li> </ol> <ol class="ex3"> <li>Alpha</li> <li>Beta</li> <li>Gamma</li> <li>Delta</li> <li>Epsilon</li> <li>Zeta</li> <li>Eta</li> <li>Theta</li> <li>Iota</li> <li>Kappa</li> </ol> <ol class="ex4"> <li>Alpha</li> <li>Beta</li> <li>Gamma</li> <li>Delta</li> <li>Epsilon</li> <li>Zeta</li> <li>Eta</li> <li>Theta</li> <li>Iota</li> <li>Kappa</li> </ol>
</div>
<section class="external-resources"> <h2>Resources for <code>:nth</code></h2> <ul> <li>Lea Verou’s - <em>CSS3 structural pseudo-class selector tester</em>: <a href="http://lea.verou.me/demos/nth.html" target="_blank" title="Link opens in a new tab">http://lea.verou.me/demos/nth.html</a></li> <li>CSS-Tricks’ - <em>:nth Tester</em>: <a href="https://css-tricks.com/examples/nth-child-tester/" target="_blank" title="Link opens in a new tab">https://css-tricks.com/examples/nth-child-tester/</a></li> </ul>
</section>
</body>
</html>
CSS :nth-child() pseudo-class - Script Codes CSS Codes
//1. Select the second child. Only Beta will be red
.ex1 :nth-child(2) { color: #2963BD; }
//2. Select every other child starting with the second. Beta, Delta, Zeta, Theta and Kappa will be red
.ex2 :nth-child(2n) { color: #429032; }
//Which is the same as selecting all EVEN child elements
.ex2 :nth-child(even) { color: #429032; }
//3. Select every other child starting with the first. Alpha, Gamma, Epsilon, Eta and Iota will be red
.ex3 :nth-child(2n+1) { color: #c03; }
//Which is the same as selecting all ODD child elements
.ex3 :nth-child(odd) { color: #c03; }
//4. Select every other child starting from the sixth. Zeta, Theta and Kappa will be red:
.ex4 :nth-child(2n+6) { color: #c90; }
//Styling stuff not needed for demo
h1 { text-transform: none; border-bottom: #636363 1px dotted; code { display: inline-block; margin-bottom: 10px; color: $y; background: none; box-shadow: none; }
}
code { font-size: .8em; }
ol { width: 200px; margin: 10px 10px 30px; padding: 20px 20px 10px 50px; border-radius: 2px; text-align: left; font-size: 1em; background: rgba(black,.2); position: relative; &:before { display: inline-block; padding: 10px; position: absolute; top: -27px; left: 0; line-height: .5; color: rgba(white,.6); font-size: 14px; border-radius: 5px 5px 0 0; background: rgba(black,.5); }
}
.ex1:before { content: "example 1"; color: $b; }
.ex2:before { content: "example 2"; color: $g; }
.ex3:before { content: "example 3"; color: $r; }
.ex4:before { content: "example 4"; color: $y; }
.flex-ctnr { display: flex; flex-wrap: wrap; justify-content: center; max-width: 900px; margin: 60px auto 0;
}
.external-resources { text-align: left;
}
Developer | Ricardo Zea |
Username | ricardozea |
Uploaded | September 28, 2022 |
Rating | 3 |
Size | 4,306 Kb |
Views | 20,240 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
03 - Custom CSS Grid - Floats | 5,018 Kb |
Responsive Table CSS | 7,571 Kb |
Line-On-Sides Headers | 2,259 Kb |
Simple Sass Mixin for Width and Height | 4,523 Kb |
Sass Mixin for Links | 3,743 Kb |
CSS Blinking Text Cursor | 3,294 Kb |
CSS Shapes with Sass | 5,726 Kb |
Sass mixin for Inside Borders | 17,268 Kb |
CSS Triangles and Arrows | 4,360 Kb |
Simple aqua button with CSS | 5,106 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Count up | Alanshortis | 2,391 Kb |
Pure CSS Tooltip | APinix | 2,815 Kb |
Nice textured background | Hans | 2,659 Kb |
Retina canvas w. resize | Erikterwan | 1,882 Kb |
Awesome Full Page Menu Nav | Ey_intuitive | 4,194 Kb |
Portfolio page | Bhavya_j | 2,804 Kb |
Front in Aracaju Logo Pure CSS | Shankarcabus | 2,581 Kb |
Clock Face Idea | Chrisburnell | 3,196 Kb |
Test | Dviate | 2,668 Kb |
Awesome | Samarthpd | 2,901 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!