I am trying to add a line number for each line in a div. But my div body is just a floating combination of other HTML elements that are generated using js and injected to that div. I know that if I want to add line numbers to a div that contains a text or fixed with elements I can do this. but How to do that for floating elements.
var field = document.getElementById('field');
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
for (var i = 0; i < 100; i++) {
var element = document.createElement('div');
if(randomIntFromInterval(1, 3) == 1)
element.classList.add("child_1_div");
else if(randomIntFromInterval(1, 3) == 2)
element.classList.add("child_2_div");
else if(randomIntFromInterval(1, 3) == 3)
element.classList.add("child_3_div");
field.appendChild(element);
}
.parent_div {
width: 500px;
height: 500px;
font-size: 0;
border: 1px solid #FF0000;
}
.child_1_div {
font-size: 1rem;
display: inline-block;
width: 30%;
height:20px;
box-sizing: border-box;
border: 1px solid #000;
}
.child_2_div {
font-size: 1rem;
display: inline-block;
width: 10%;
height: 10px;
box-sizing: border-box;
border: 1px solid #000;
}
.child_3_div {
font-size: 1rem;
display: inline-block;
width: 5%;
height: 5px;
box-sizing: border-box;
border: 1px solid #000;
}
<div id ="field" class="parent_div"></div>