-1

I have a markup that looks like this, all items are numbered based on their position. Can you create something like this automatically based on the number of items? Either with css or HTML, I know it's possible with javascript. Ideally I'd like it to write out 01.01, 01.02 etc but if it's possible to do with just one layer, that's ok too.

   <section class="profile__section">
    <h1 class="profile__section__header">01. Colors</h1>
    <div class="container__profile__subsection">
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.01 Blue</h2>
            <p class="profile__subsection__color" style="background: #36314C;">Hex: 36314C</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.07 Topics Blue</h2>
            <p class="profile__subsection__color" style="background: #4A455D;">Hex: 4A455D</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.02 White</h2>
            <p class="profile__subsection__color" style="background: #fff; color: black;">Hex: FFFFFF</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.03 Places Yellow</h2>
            <p class="profile__subsection__color" style="background: #F4BA38;">Hex: F4BA38</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.04 Tag Blue</h2>
            <p class="profile__subsection__color" style="background: #347591;">Hex: 347591</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.05 Tag Blue Light</h2>
            <p class="profile__subsection__color" style="background: #d7e2e2;">Hex: d7e2e2</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">01.06 Time Blue</h2>
            <p class="profile__subsection__color" style="background: #147562;">Hex: 147562</p>
        </div>
    </div>
</section>
<section class="profile__section">
    <h1 class="profile__section__header">02. Cartegory Colors</h1>
    <div class="container__profile__subsection">
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">02.01 People Green</h2>
            <p class="profile__subsection__color" style="background: #7CB93C;">Hex: 7CB93C</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">02.02 Comms Pink</h2>
            <p class="profile__subsection__color" style="background: #D53668;">Hex: D53668</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">02.03 Photos Purple</h2>
            <p class="profile__subsection__color" style="background: #993B9B;">Hex: 993B9B</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">02.04 Event orange</h2>
            <p class="profile__subsection__color" style="background: #EA5B1D;">Hex: EA5B1D</p>
        </div>
        <div class="profile__subsection">
            <h2 class="profile__subsection__header">02.05 Docs blue</h2>
            <p class="profile__subsection__color" style="background: #54BBB6;">Hex: 54BBB6</p>
        </div>
    </div>
</section>
Himmators
  • 14,278
  • 36
  • 132
  • 223
  • HTML is a static markup. it only describes elements. It cannot run any functions like ordering or sorting – Herr Derb Jul 12 '17 at 09:57
  • I know, and that is not my question either, not sure if this is possible, but forexample in css you can use the before-psuedo-element to amend content to your markup, but I'm not sure If i can add the item-number this way – Himmators Jul 12 '17 at 10:08
  • You can actually kind of order stuff using css aswell. – Himmators Jul 12 '17 at 10:09
  • Cant be done without JS/jquery. https://stackoverflow.com/questions/5672903/can-i-have-a-div-with-id-as-number – Plankton Jul 12 '17 at 10:11
  • Google, gives you right I guess: https://www.w3schools.com/cssref/css3_pr_order.asp – Herr Derb Jul 12 '17 at 10:11
  • Having a hammer doesn't mean to bang anywhere. Use the right tools for the right stuff. use jquery or js . the solutions using css r not scalable at all. – Plankton Jul 12 '17 at 10:20
  • @HerrDerb ordering was not my question though... – Himmators Jul 12 '17 at 19:31
  • @Plankton see my anser, works like a charm and probably has better perfomance than anything you could do with javascript, not that it matters.. – Himmators Jul 12 '17 at 19:31

2 Answers2

0

With CSS you actually really can order HTML elements. Not by element value thought. See the CSS order property on W3Schools - CSS order

Below the extracted snipped from W3Schools

#main {
    width: 400px;
    height: 150px;
    border: 1px solid #c3c3c3;
    display: -webkit-flex; /* Safari */
    display: flex;
}

#main div {
    width: 70px;
    height: 70px;
}

/* Safari 6.1+ */
div#myRedDIV   {-webkit-order: 2;}
div#myBlueDIV  {-webkit-order: 4;}
div#myGreenDIV {-webkit-order: 3;}
div#myPinkDIV  {-webkit-order: 1;}

/* Standard syntax */
div#myRedDIV   {order: 2;}
div#myBlueDIV  {order: 4;}
div#myGreenDIV {order: 3;}
div#myPinkDIV  {order: 1;}
<div id="main">
  <div style="background-color:coral;" id="myRedDIV"></div>
  <div style="background-color:lightblue;" id="myBlueDIV"></div>
  <div style="background-color:lightgreen;" id="myGreenDIV"></div>
  <div style="background-color:pink;" id="myPinkDIV"></div>
</div>

<p><b>Note:</b> Internet Explorer 10 and earlier versions do not support the order property.</p>

<p><b>Note:</b> Safari 6.1 (and newer) supports an alternative, the -webkit-order property.</p>
Herr Derb
  • 4,977
  • 5
  • 34
  • 62
0

Similair to an ordered list, the numbers I want to add is not a part of the content, and I need to move the content around and want the content to follow. Here is my solution:

body {
    counter-reset: section;
}

.profile__section__header::before{
    counter-increment: section;
    content: counter(section, decimal-leading-zero) ". ";
}

.profile__subsection__header::before{
    counter-increment: subsection;
    content: counter(section, decimal-leading-zero) "." counter(subsection, decimal-leading-zero) " ";
}
Himmators
  • 14,278
  • 36
  • 132
  • 223
  • bravo. tried it with a angular directive and works like a charm. Nice! Here's the link: http://plnkr.co/edit/sOwQqmFnBSNjvsOjFaqG?p=preview (Scroll all the way down to see the angular1 directive in action) – Plankton Jul 14 '17 at 07:18
  • thx, would you mind upvoting this question if you think it's legit. I don't think it's fair that it has a negative vote. Also, why did you add your e-mail adress to my solution? – Himmators Jul 15 '17 at 10:17