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?
To use a counter it must first be initialized to a value with the counter-reset property. The counter's value can then be increased or decreased using counter-increment property. The current value of a counter is displayed using the counter() or counters() function, typically within a pseudo-element content property.
Definition and Usage The counter-increment property increases or decreases the value of one or more CSS counters. The counter-increment property is usually used together with the counter-reset property and the content property. Default value: none.
Simple Numbering In the CSS we are going to do three key things: Initialize the counter on the parent div using counter-reset. Increment the counter value by 1 on the child div p using counter-increment. Add the counter variables before the div p content using the :before pseudo selector.
The counter-set CSS property sets a CSS counter to a given value. It manipulates the value of existing counters, and will only create new counters if there isn't already a counter of the given name on the element.
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.
counter()
function can only be used for content
property. URL composition, like the one you are trying to create above, is impossible in CSS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With