Selecting the last line of a

element

后端 未结 4 1927
故里飘歌
故里飘歌 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:20

    Unfortunately there is no CSS selector that would apply.

    You can however select the first line using the pseudo element :first-line. Unfortunately at the moment there is no equivalent for the last line.

    0 讨论(0)
  • 2021-02-20 02:22

    You can use only one line and give css : nth-child(3)

    Here (3) denotes the number of a last line

    0 讨论(0)
  • 2021-02-20 02:27

    I don't think this can be done with CSS alone. jQuery or a PHP function might be able to get want you what

    0 讨论(0)
  • 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]);
    
    0 讨论(0)
提交回复
热议问题