Selecting the last line of a

element

后端 未结 4 1988
故里飘歌
故里飘歌 2021-02-20 01:29

I am aware of the :first-line selector in CSS, but I cannot find anything that will allow me to select the last line.

The reason I am trying to select the l

4条回答
  •  耶瑟儿~
    2021-02-20 02:31

    IIRC, the only css control over the last line is text-align:

    text-align-last: right;
    

    I'm afraid javascript, or actually wrapping the last line in a span and styling that, is the only way. Below is the JS for reference.

    var thetext = document.getElementById('some_element').innerHTML.split(/\r?\n/);
    alert(thetext[thetext.length - 1]);
    

提交回复
热议问题