5

I am interested in setting the images next to list items dynamically based on it's position. You can see below that I am using the counter feature of CSS to keep track of the list items, and that I am trying to specify an image as the list style type using the counter.

ul{
    counter-reset:list;
}
li
{
    counter-increment:list;
    list-style:disc outside url("http://dummyimage.com/" counter(list) "x" counter(list) "");
}
<ul>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
</ul>

What is the correct way of getting the counter to work in a url declaration? Is it even possible?

1
  • Would've been so cool if this actually worked. Commented Feb 7, 2016 at 16:43

3 Answers 3

4

url cannot be compose out of multiple string

for example, this work:

url("http://dummyimage.com/10x10");

but this doesn't work :

url("http://dummyimage.com/" "10x10");

the counter has nothing to do with it

On the other hand, you could be able to do it using variables, try to take a look at LessCSS for axample.

Sign up to request clarification or add additional context in comments.

Comments

4

counter() function can only be used for content property. URL composition, like the one you are trying to create above, is impossible in CSS.

Comments

1

I'm not sure, what you are trying to achieve, but here's the sample code that you mind find useful: sample code

html

<ul>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
</ul>

css

ul { counter-reset: list; }
li {
  counter-increment: list;
  list-style: disc outside url("http://placekitten.com/20/20");
}
li:before {
  counter-increment: section;
  content:"Item " counter(list) ". ";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.