How can I access the numbers (1 and 2 in the example below) at the end of the paragraph’s class string via CSS?
<p class="cooking-step-1">
<!-- Second step ... -->
</p>
<p class="cooking-step-2">
<!-- Second step ... -->
</p>
I can access these paragraphs via the following selector: p[class^="cooking-step-"]
I want to add the paragraph’s number in front of the text inside of it via the CSS content property. How do I achieve this?
That is possible using counters. However, browser support is spotty and I think the spec changed for CSS3.
Basically, you do not even need the
cooking-step-Nclass. If you use a class likecooking-step, you can simply let the engine do the counting for you. Increment it on each.cooking-stepand use itscounter()for thecontent.