html5 - How to count the lines of a <pre> poem using css? -


i want display beowulf on webpage, full poem. code far:

<head> <title>beowulf</title>     <style type="text/css">      body {padding: 10% 25%;}     pre {font-family: "times new roman";  font-size: 100%;}   </style> </head>   <body> <h3>beowulf</h3><br>  <pre>now beowulf bode in burg of scyldings, leader beloved, , long ruled in fame folk, since father had gone (...) of furious flame. nor far day when father , son-in-law stood in feud warfare , hatred woke again. (...)</pre> </body> 

now how every fifth line numbered? position numbers on extreme edge of right side.

i appretiate if tried explain issue me didatically possible. friend of simplicity , give preference codes shouldn't bigger beowulf poem (if message!), preferably css.

if javascrpit way there, kindly ask formulate answer in didactical way can. programming skills "lower-intermediate" , unfortunately didn't find concrete information on web, not @ w3schools. thank answers!

css styles elements or pseudo-elements, not text lines. need modify html or use js.

for example, can text, split lines, , wrap each 1 inside list item of ordered list.

the, can use css counter associate each line number, :nth-child select each 5n-th line, , pseudo-element insert counter. align numbers properly, can use css tables.

var old = document.getelementbyid('poem'),      poem = document.createelement('ol');  poem.id = 'poem';  old.textcontent.split('\n').foreach(function(line) {    var li = document.createelement('li');    li.textcontent = line;    poem.appendchild(li);  });  old.parentnode.replacechild(poem, old);
body {padding: 10% 25%;}  #poem {    font-family: "times new roman";    display: table;    padding: 0;    counter-reset: line;  }  #poem > li {    display: table-row;    white-space: pre;    counter-increment: line;  }  #poem > li:nth-child(5n+1):after {    content: counter(line);    display: table-cell;    text-align: right;    color: #aaa;    cursor: default;  }
<h3>beowulf</h3><br>  <pre id="poem">now beowulf bode in burg of scyldings,  leader beloved, , long ruled  in fame folk, since father had gone  away world, till awoke heir,  haughty healfdene, held through life,  sage , sturdy, scyldings glad.  then, 1 after one, there woke him,  chieftain of clansmen, children four:  heorogar, hrothgar, halga brave;  , heard -- -- 's queen,  heathoscylfing's helpmate dear.  hrothgar given such glory of war,  such honor of combat, kin  obeyed him gladly till great grew band  of youthful comrades. came in mind  bid henchmen hall uprear,  ia master mead-house, mightier far  ever seen sons of earth,  , within it, then, old , young  allot lord had sent him,  save land , lives of men.  wide, heard, work commanded,  many tribe mid-earth round,  fashion folkstead. fell, ordered,  in rapid achievement ready stood there,  of halls noblest: heorot named  message had might in many land.  not reckless of promise, rings dealt,  treasure @ banquet: there towered hall,  high, gabled wide, hot surge waiting  of furious flame. nor far day  when father , son-in-law stood in feud  warfare , hatred woke again. (...)</pre>


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -