Automatic Table of Contents
How do I make an automatic table of contents?
What is a automatic table of contents? How do you make a automatic table of contents? This script and codes were developed by Chris Coyier on 01 December 2022, Thursday.
Automatic Table of Contents - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Automatic Table of Contents</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { background: #eee; padding: 20px;
}
article { max-width: 50em; background: white; padding: 2em; margin: 1em auto;
}
.table-of-contents { float: right; width: 40%; background: #eee; font-size: 0.8em; padding: 1em 2em; margin: 0 0 0.5em 0.5em;
}
.table-of-contents ul { padding: 0;
}
.table-of-contents li { margin: 0 0 0.25em 0;
}
.table-of-contents a { text-decoration: none;
}
.table-of-contents a:hover,
.table-of-contents a:active { text-decoration: underline;
}
h3:target { animation: highlight 1s ease;
}
@keyframes highlight { from { background: yellow; } to { background: white; }
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <article> <h1>Documentation</h1> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <div class="all-questions"> <h3 id="one">How do you smurf a murf?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="two">How do many licks does a giraffe?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="three">Which Frank is?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="four">Is fourteen enough?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="five">Is a circle an oval y/n?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="six">Many mongerals manifest mountains</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="seven">How would you like a soda drink?</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="eight">I would very much like a soda drink.</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> <h3 id="nine">Thank you for accepting the soda drink.</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p> </div>
</article> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Automatic Table of Contents - Script Codes CSS Codes
body { background: #eee; padding: 20px;
}
article { max-width: 50em; background: white; padding: 2em; margin: 1em auto;
}
.table-of-contents { float: right; width: 40%; background: #eee; font-size: 0.8em; padding: 1em 2em; margin: 0 0 0.5em 0.5em;
}
.table-of-contents ul { padding: 0;
}
.table-of-contents li { margin: 0 0 0.25em 0;
}
.table-of-contents a { text-decoration: none;
}
.table-of-contents a:hover,
.table-of-contents a:active { text-decoration: underline;
}
h3:target { animation: highlight 1s ease;
}
@keyframes highlight { from { background: yellow; } to { background: white; }
}
Automatic Table of Contents - Script Codes JS Codes
var ToC = "<nav role='navigation' class='table-of-contents'>" + "<h2>On this page:</h2>" + "<ul>";
var newLine, el, title, link;
$("article h3").each(function() { el = $(this); title = el.text(); link = "#" + el.attr("id"); newLine = "<li>" + "<a href='" + link + "'>" + title + "</a>" + "</li>"; ToC += newLine;
});
ToC += "</ul>" + "</nav>";
$(".all-questions").prepend(ToC);
Developer | Chris Coyier |
Username | chriscoyier |
Uploaded | December 01, 2022 |
Rating | 4 |
Size | 2,869 Kb |
Views | 26,312 |
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 |
Voting is our Voice | 3,883 Kb |
Bookmarklet to make the text between 45 and 75 characters turn red. | 2,974 Kb |
Play Button for YouTube | 2,975 Kb |
JQuery Draggable with out jQuery UI | 2,216 Kb |
Row and Column Highlighting with CSS Only | 2,180 Kb |
Merging Flexbox Syntaxes | 2,654 Kb |
Animation to Explain CSS Triangles | 4,964 Kb |
Simple Responsive Form | 2,698 Kb |
Airtable Emoji Poll | 3,194 Kb |
Stairway Hover Nav | 3,213 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 |
A Pen by Michael Parenteau | Michaelparenteau | 2,133 Kb |
Kudos Please | TimPietrusky | 6,624 Kb |
Border-radius animation | Yukulele | 2,480 Kb |
Menu | Vivi_Lai | 1,210 Kb |
Whyutils | LeYvan | 3,752 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Hello People | Danburrows | 2,365 Kb |
Sticky menu on scroll | Senff | 2,869 Kb |
Revolving Text Landing Page Trial | TimRuby | 2,976 Kb |
Wikipedia Viewer | Thalpha | 4,426 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!