Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing with HTML's ordered list number bullets

Can anyone think of a way to use the numbers in an ol/li list to label images?

<ol>
  <li><img /></li>
  <li><img /></li>
  <li><img /></li>
</ol>

With some CSS applied should output the following:

------ ------ ------
|    | |    | |    |
|    | |    | |    |
|   1| |   2| |   3|
------ ------ ------

Where each square is a small profile picture.

I know I can insert a new element in the li with a numeral in it and manipulate that as needed, but I'd like to do it with the inbuilt ol numbering.

like image 708
JP. Avatar asked Dec 09 '22 03:12

JP.


1 Answers

Easy enough:

ol {
    counter-reset: listCount;
}
li {
    float: left;
    border: 3px solid #f90;
    counter-increment: listCount;
    position: relative;
}
li:after {
    content: counter(listCount,decimal-leading-zero);
    position: absolute;
    bottom: 0;
    right: 0;
    width: 2em;
    height: 2em;
    color: #fff;
    background-color: rgba(0,0,0,0.5);
    text-align: center;
    line-height: 2em;
}

JS Fiddle demo.

This does, of course, require the user to have a browser with the capacity for using css-generated-content, which pretty rules out IE.

References:

  • CSS-generated counters.
like image 69
David Thomas Avatar answered Dec 11 '22 16:12

David Thomas