CSS: Formatting Visual Data
Illustration by John Hersey

Adding custom number characters


From:

CSS: Formatting Visual Data

with Joseph Lowery

Video: Adding custom number characters

By default, browsers place a period after the automatically generated marker of a list item and in ordered list regardless if it's type is decimal, roman numeral, or letter. Periods are quite functional but they're constant use as a trailing character are a tad on the boring side. In this lesson, I'll show you how to replace the period with the character of your choosing, whether it's a colon, a dash, a parenthesis or, gasp, nothing at all. Here I have a page with a basic ordered list. I don't declare a type, so standard decimals are used. And of course, there's a period after each number. Let's go to the CSS for this page, which is main.css file. I'm going to scroll to the bottom, where my only rule targeting the ordered list can be found, to add in a custom trailing character, I'm going to need to insert a new declaration.

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course CSS: Formatting Visual Data
1h 37m Intermediate Mar 26, 2013

Viewers: in countries Watching now:

Having a complete toolbox at your disposal to properly structure and display data is critically important to a successful web design. In this course, author Joseph Lowery covers basic styling for numbered, bulleted, and definition lists, plus structuring and formatting tables with CSS. He also includes instructions on creating charts and graphs with the HTML5 Canvas element. Each section of the course highlights advanced CSS, HTML5, and JavaScript techniques that increase interactivity, yield responsive designs, and heighten the user experience.

Topics include:
  • Adding custom number characters to lists
  • Managing hanging indents
  • Styling nested lists
  • Understanding definition lists
  • Highlighting table content
  • Creating alternating row colors (zebra stripes)
  • Building bar graphs and pie charts
Subject:
Web
Software:
CSS
Author:
Joseph Lowery

Adding custom number characters

By default, browsers place a period after the automatically generated marker of a list item and in ordered list regardless if it's type is decimal, roman numeral, or letter. Periods are quite functional but they're constant use as a trailing character are a tad on the boring side. In this lesson, I'll show you how to replace the period with the character of your choosing, whether it's a colon, a dash, a parenthesis or, gasp, nothing at all. Here I have a page with a basic ordered list. I don't declare a type, so standard decimals are used. And of course, there's a period after each number. Let's go to the CSS for this page, which is main.css file. I'm going to scroll to the bottom, where my only rule targeting the ordered list can be found, to add in a custom trailing character, I'm going to need to insert a new declaration.

To the OL rule and then add two more rules for the list items themselves let's start by ammending the existing OL rule. I'm going to put in a property called counter-reset and I'm going to give it a variable name. Item. The counter reset property identifies the variable that we're going to be using and resets it to one for the start of the ordered list. Next we'll need to set up the list item properly. So I'm going to create a new rule called main content LI. For the list item.

And the first thing we're going to do is set the display property to block. This will essentially remove all automatic numbering so that we can insert our custom values as a replacement. Next, I'll add a margin left value to move it to the right place. Let me hit a couple of extra lines just to move it up a tad. Finally, let's set up our replacement content. This is handled using the before pseudo selector, so our full selector reads Main Content, LI, before.

here we're going to set our display to in line block. Next we'll use the content property to write out the number we want, and the custom trailing character. So there's the content property. Now we'll use the keyword counter. And in parenthesis the variable item. Which we previously identified with the counter reset property.

And your recall it's called item. Right after that we'll put in quotes. Any content that we want to have, and the content we want to have is a closing parenthesis, followed by a space. Now close that declaration with a semicolon. Now it's time to increment our counter, with the cleverly named property counter increment. The value you give it is the name of the counter that you want to increment, and ours is Item. Finally, let's set the width of the entire pre-string to 1.5M and then position it with a margin left.

Equal to negative 2M. Let me save the page and now let's see how it looks in the browser. After I hit refresh, great, there is our closing parentheses after each number and there is not a period to be seen in our ordered list. You can use this same technique combining the counter reset content and counter increment properties to automatically number subsections of an ordered list as they do when legal documents.

I'll demonstrate that technique in the lesson styling nested list later in this chapter.

There are currently no FAQs about CSS: Formatting Visual Data.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Formatting Visual Data.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.