A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/html-css-exercise/css-properties/counter-increment-answer.php below:

Website Navigation


CSS Properties: How to set a number sections and sub-sections with Section?

CSS Properties: How to set a number sections and sub-sections with Section?Last update on February 22 2024 12:45:04 (UTC/GMT +8 hours)

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Specifies the document type and version of HTML -->
<html>
<head>
<title>How to set a number sections and sub-sections with Section</title><!-- Sets the title of the HTML document -->
<style type="text/css"> /* Begins a CSS style block */
body {
counter-reset: section; /* Resets the counter named "section" for the entire document */
}
h1 {
counter-reset: subsection; /* Resets the counter named "subsection" for each <h1> element */
}
h1:before {
counter-increment: section; /* Increments the counter named "section" */
content: "Section " counter(section) ". "; /* Sets the content before each <h1> element to "Section" followed by the current value of the "section" counter */
}
h2:before {
counter-increment: subsection; /* Increments the counter named "subsection" */
content: counter(section) "." counter(subsection) " "; /* Sets the content before each <h2> element to the current value of the "section" counter followed by a dot and the current value of the "subsection" counter */
}
</style><!-- Ends the CSS style block -->
</head>
<body>
<h1>HTML tutorials</h1><!-- Inserts an <h1> element with the specified content -->
<h2>HTML Tutorial</h2><!-- Inserts an <h2> element with the specified content -->
<h2>CSS Tutorial</h2><!-- Inserts an <h2> element with the specified content -->
<h2>HTML5 Tutorial</h2><!-- Inserts an <h2> element with the specified content -->
<h1>Database tutorials</h1><!-- Inserts an <h1> element with the specified content -->
<h2>SQL</h2><!-- Inserts an <h2> element with the specified content -->
<h2>MySQL</h2><!-- Inserts an <h2> element with the specified content -->
<h2>PostgreSQL</h2><!-- Inserts an <h2> element with the specified content -->
<h1>Exercises</h1><!-- Inserts an <h1> element with the specified content -->
<h2>HTML CSS</h2><!-- Inserts an <h2> element with the specified content -->
<h2>JavaScript</h2><!-- Inserts an <h2> element with the specified content -->
<h2>jQuery</h2><!-- Inserts an <h2> element with the specified content -->
<h2>PHP</h2><!-- Inserts an <h2> element with the specified content -->
</body>
</html>

Explanation:

Live Demo:

See the Pen counter-increment-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4