Lining.js
In CSS we already have the selector ::first-line
to apply style on the first line of element. But there is no selector like ::nth-line()
, ::nth-last-line()
or even ::last-line
. Then I read an article A Call for ::nth-everything from CSS tricks. ::nth-line()
is actually really useful in some situation.
There comes Lining.js. It offers you complete down-to-the-line control like this:
<div class="poem" data-lining>Some text...</div>
<style>
.poem .line[first] { /* `.poem::first-line`*/ }
.poem .line[last] { /* `.poem::last-line` */ }
.poem .line[index="5"] { /* `.poem::nth-line(5)` */ }
.poem .line:nth-of-type(-n+2) { /* `.poem::nth-line(-n+2)` */ }
.poem .line:nth-last-of-type(2n) { /* `.poem:::nth-last-line(2n)` */ }
</style>
<script src="YOUR_PATH/lining.min.js"></script>
Supported browsers