Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS counter in url

Tags:

html

css

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?

like image 835
Richard Parnaby-King Avatar asked Mar 27 '13 09:03

Richard Parnaby-King


People also ask

How do I add a counter in CSS?

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.

What is CSS counter-increment?

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.

How do I use automatic numbering in CSS?

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.

How do you set a counter?

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.


2 Answers

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.

like image 140
BlueMagma Avatar answered Oct 01 '22 04:10

BlueMagma


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

like image 40
Pavlo Avatar answered Oct 01 '22 05:10

Pavlo