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 last line is because I want to be able to define the text-overflow
and white-space
attributes of the last line.
I am trying to avoid using JavaScript to form a solution.
The text-align-last property in CSS is used to set the last line of the paragraph just before the line break. The line break may be due to the natural ending of a paragraph, or it may be due to the use of <br> tag.
The text-align-last property specifies how to align the last line of a text. Notice that the text-align-last property sets the alignment for all last lines within the selected element. So, if you have a <div> with three paragraphs in it, text-align-last will apply to the last line of EACH of the paragraphs.
At the end of your document you should close with the </html> tag.
The text-align-last CSS property sets how the last line of a block or a line, right before a forced line break, is aligned.
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.
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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With