Tutorials

Latest Word » Tutorials » Table of Contents Style Layout with CSS
Table of Contents Style Layout with CSS

Table of Contents Style Layout with CSS

Tags:

For a recent project, I was designing a price guide that was basically very similar to a typical Table of Contents type of layout. I hope it can come in handy for some of you.

HTML

<ul class="tablel_content">
	<li>
		<strong>Chapter 1</strong>
		<em>4</em>
	</li>
	<li>
		<strong>Chapter 2</strong>
		<em>10</em>
	</li>
</ul>

CSS

We will be using a background image that would repeat the dotted lines across each list item. Using the background positioning we will keep it aligned with the rest of the text and use the padding to cover the areas where it should not overlap.

ul.tablel_content {
	width: 500px;
	margin: 0 auto;
	padding: 0;
	list-style: none;
	font-size: 1.7em;
}
ul.tablel_content li {
	margin: 0;
	padding: 10px 0;
	text-align:right;
	background: url(dotted.gif) repeat-x left 22px;
}
ul.tablel_content li strong, ul.tablel_content li em {
	float: left;
	background: #1d1d1d; /*--Combined Property with 'li em'--*/
	padding: 0 10px; /*--Combined Property with 'li em'--*/
}
ul.tablel_content li em {
	float: none;
}

Conclusion

This technique requires a background image to repeat the dotted lines, I was messing around with a version that just relies on the border property. Here is a quick sample , it works but requires more code and relies on absolute positioning (To fix an IE6 Bug I had to use this method). Let me know if you have other ways to style this up!

Related Posts

Author Bio

My name is Soh Tanaka and I am a Los Angeles based designer/front-end developer specializing in CSS driven web design with an emphasis on usability and search engine optimization. I also run a CSS Gallery which is updated daily with the best CSS websites from around the world. Come check it out!

You can learn more about me or Twitter  Follow me on twitter for more updates and resources!

Did You Enjoy This Post?

subscribe  Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.

+ Add Comment3 Peeps Have Spoken Their Minds...

  1. Petr

    You should use definition list (dl, dt, dd) instead of ul and li

  2. Lukasz Bachur

    Have you any idea what to do if my title (the left one) is long and it breaks to the second line?

  3. MattCoops

    Petr, definition lists are for, well… definitions. There is nothing wrong with using a list. Although, in the case of a table of contents, I would probably consider using an ordered list rather than an unordered.

Speak Your Mind...

Post HTMLNeed to Post HTML Code? Use Postable to post code friendly html. *Wrap all html code in <pre></pre> tags.
Post HTMLNeed to Keep Updated with Comments? Subscribe to comments now.

CSS Gallery