HTML, Create line numbers for large lines

I have the following code that creates automatic line numbers for each div with the class "lineNum". I want to create line numbers also for line breaks (in a code snippet, the line between lines 1 and 2). Thank!

.container {direction:rtl; counter-reset: line;}
.container .lineNum {display: flex;line-height: 1.5rem;}
.lineNum>center, .lineNum>right, .lineNum>left, .lineNum>span 
{width: 100%;}

.container .lineNum:before 
{
  width: 2%;font-weight: bold;
  counter-increment: line;content:counter(line);
  display: inline-block;
  background-color: lightgray;
  margin-left: 10px;
  padding-right: .5em;
}
<div class="container">
<div class="lineNum"><span>ื‘ืžื”ืœืš ืชืงื•ืคื” ื–ื•, ื’ื“ืœื ื• ืžืงื‘ื•ืฆื” ืงื˜ื ื” ืฉืœ ืขื•ืจื›ื™ื ืœืงื”ื™ืœื” ืžื’ื•ื•ื ืช ืฉืœ ืขื•ืจื›ื™ื, ืžืคืชื—ื™ื, ืงื•ืจืื™ื, ืชื•ืจืžื™ื ื•ืฉื•ืชืคื™ื. ืื™ืคื” ื ื”ื™ื” ื‘ืขื•ื“ 15 ืฉื ื”? ืื™ื–ื” ืชืคืงื™ื“ ื ืžืœื ื‘ืขื•ืœื? ืžื™ ืขื•ื“ ื™ืฆื˜ืจืฃ ืœืชื ื•ืขื”? ืžื” ืื•ืคื™ ื”ืขื‘ื•ื“ื” ื”ื ื™ืฆื‘ืช ืœืคื ื™ื ื•? ืฉืืœื•ืช ืืœื• ื™ื™ืขื ื• ืขืœ ื™ื“ื™ ืชื ื•ืขืช ื•ื™ืงื™ืžื“ื™ื” ื›ื•ืœื” ื‘ืžื”ืœืš ื”ืฉื‘ื•ืขื•ืช ื”ืงืจื•ื‘ื™ื, ื‘ืžืกื’ืจืช ื”ืชื”ืœื™ืš ื”ืืกื˜ืจื˜ื’ื™ ืœืฉื ืช 2017, ื”ืžืชื ื”ืœ ื‘ื™ืžื™ื ืืœื•.</span></div>
<div class="lineNum"><span>ืชืฆืœื•ื ืœื•ื•ื™ื™ืŸ ืฉืœ ืืจืฅ ื™ืฉืจืืœ, ืžืฉื ืช 2003, ื”ื›ื•ืœืœ ืืช ืžื“ื™ื ืช ื™ืฉืจืืœ, ืฉื˜ื—ื™ ื”ืจืฉื•ืช ื”ืคืœืกื˜ื™ื ื™ืช, ื•ื—ืœืงื™ื ืžื™ืจื“ืŸ, ืœื‘ื ื•ืŸ, ืกื•ืจื™ื” ื•ืžืฆืจื™ื</span></div></div>
Run code

edit: next result expected enter image description here

+4
source share
1 answer

If you need a gap between each class .lineNum, just add margin-top: 10px;. I added a snippet below to show you.

.container {direction:rtl; counter-reset: line;}
.container .lineNum {display: flex;line-height: 1.5rem;}
.lineNum>center, .lineNum>right, .lineNum>left, .lineNum>span 
{width: 100%;}

.lineNum {margin-top: 10px;} 
       
.container .lineNum:before 
{
  width: 2%;font-weight: bold;
  counter-increment: line;content:counter(line);
  display: inline-block;
  background-color: lightgray;
  margin-left: 10px;
  padding-right: .5em;
}
<div class="container">
<div class="lineNum"><span>ื‘ืžื”ืœืš ืชืงื•ืคื” ื–ื•, ื’ื“ืœื ื• ืžืงื‘ื•ืฆื” ืงื˜ื ื” ืฉืœ ืขื•ืจื›ื™ื ืœืงื”ื™ืœื” ืžื’ื•ื•ื ืช ืฉืœ ืขื•ืจื›ื™ื, ืžืคืชื—ื™ื, ืงื•ืจืื™ื, ืชื•ืจืžื™ื ื•ืฉื•ืชืคื™ื. ืื™ืคื” ื ื”ื™ื” ื‘ืขื•ื“ 15 ืฉื ื”? ืื™ื–ื” ืชืคืงื™ื“ ื ืžืœื ื‘ืขื•ืœื? ืžื™ ืขื•ื“ ื™ืฆื˜ืจืฃ ืœืชื ื•ืขื”? ืžื” ืื•ืคื™ ื”ืขื‘ื•ื“ื” ื”ื ื™ืฆื‘ืช ืœืคื ื™ื ื•? ืฉืืœื•ืช ืืœื• ื™ื™ืขื ื• ืขืœ ื™ื“ื™ ืชื ื•ืขืช ื•ื™ืงื™ืžื“ื™ื” ื›ื•ืœื” ื‘ืžื”ืœืš ื”ืฉื‘ื•ืขื•ืช ื”ืงืจื•ื‘ื™ื, ื‘ืžืกื’ืจืช ื”ืชื”ืœื™ืš ื”ืืกื˜ืจื˜ื’ื™ ืœืฉื ืช 2017, ื”ืžืชื ื”ืœ ื‘ื™ืžื™ื ืืœื•.</span></div>
<div class="lineNum"><span>ืชืฆืœื•ื ืœื•ื•ื™ื™ืŸ ืฉืœ ืืจืฅ ื™ืฉืจืืœ, ืžืฉื ืช 2003, ื”ื›ื•ืœืœ ืืช ืžื“ื™ื ืช ื™ืฉืจืืœ, ืฉื˜ื—ื™ ื”ืจืฉื•ืช ื”ืคืœืกื˜ื™ื ื™ืช, ื•ื—ืœืงื™ื ืžื™ืจื“ืŸ, ืœื‘ื ื•ืŸ, ืกื•ืจื™ื” ื•ืžืฆืจื™ื</span></div></div>
Run code
+5
source

Source: https://habr.com/ru/post/1673800/


All Articles