Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making the example clearer #2996

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions files/en-us/web/css/_colon_nth-of-type/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ <h4 id="HTML">HTML</h4>
<pre class="brush: html">&lt;div&gt;
&lt;div&gt;This element isn't counted.&lt;/div&gt;
&lt;p&gt;1st paragraph.&lt;/p&gt;
&lt;p&gt;2nd paragraph.&lt;/p&gt;
&lt;p class="fancy"&gt;2nd paragraph.&lt;/p&gt;
&lt;div&gt;This element isn't counted.&lt;/div&gt;
&lt;p&gt;3rd paragraph.&lt;/p&gt;
&lt;p class="fancy"&gt;4th paragraph.&lt;/p&gt;
&lt;p class="fancy"&gt;3rd paragraph.&lt;/p&gt;
&lt;p&gt;4th paragraph.&lt;/p&gt;
&lt;/div&gt;</pre>

<h4 id="CSS">CSS</h4>
Expand All @@ -62,15 +62,21 @@ <h4 id="CSS">CSS</h4>
font-weight: bold;
}

/* This has no effect, as the .fancy class is only on the 4th p element, not the 1st */
p.fancy:nth-of-type(1) {
/* This will match the 3rd paragraph as it will match elements which are 2n+1 AND have a class of fancy.
The second paragraph has a class of fancy but is not matched as it is not :nth-of-type(2n+1) */
p.fancy:nth-of-type(2n+1) {
text-decoration: underline;
}
</pre>

<h4 id="Result">Result</h4>

<p>{{EmbedLiveSample('Basic_example', 250, 200)}}</p>
<p>{{EmbedLiveSample('Basic_example', 250, 250)}}</p>

<div class="notecard note">
<h4>Note</h4>
<p>There is no way to select the nth-of-class using this selector. The selector looks at the type only when creating the list of matches. You can however apply CSS to an element based on <code>:nth-of-type</code> location <strong>and</strong> a class, as shown in the example above.</p>
</div>

<h2 id="Specifications">Specifications</h2>

Expand Down