Home >Web Front-end >CSS Tutorial >How to Create Leading Dots for Table of Contents using Only CSS?
Creating Leading Dots for Table of Contents using CSS
Achieving leading dots in a table of contents can be tricky, but CSS offers an effective solution.
CSS-Only Approach:
As suggested by a reputable source, the following CSS-only technique elegantly addresses this issue:
ul.leaders { max-width: 40em; padding: 0; overflow-x: hidden; list-style: none; } ul.leaders li:before { float: left; width: 0; white-space: nowrap; content: ". . . . . . . . . . . . . . . . . . . . " ". . . . . . . . . . . . . . . . . . . . " ". . . . . . . . . . . . . . . . . . . . " ". . . . . . . . . . . . . . . . . . . . "; } ul.leaders span:first-child { padding-right: 0.33em; background: white; } ul.leaders span + span { float: right; padding-left: 0.33em; background: white; }
HTML Structure:
To utilize this technique, structure your HTML as follows:
<ul class="leaders"> <li><span>Salmon Ravioli</span> <span>7.95</span></li> <li><span>Fried Calamari</span> <span>8.95</span></li> <li><span>Almond Prawn Cocktail</span> <span>7.95</span></li> <li><span>Bruschetta</span> <span>5.25</span></li> <li><span>Margherita Pizza</span> <span>10.95</span></li> </ul>
This approach effectively creates leading dots without resorting to images or complex JavaScript solutions, providing a clean and visually appealing presentation.
The above is the detailed content of How to Create Leading Dots for Table of Contents using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!