An unusual one this, and a toughie to explain eloquently!
I'm trying to force the first line of a paragraph to have the least number of characters where under normal circumstances it would be the last. that probably didn't make much sense, so I'll use an example.
Text usally formats like this:
开发者_JAVA百科Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Curabitur mollis lorem sit amet nisl
scelerisque mollis. Vestibulum tincidunt sodales
turpis quis convallis. Curabitur id diam dictum
arcu placerat lobortis.
I want the text to format like this:
Lorem ipsum dolor
sit amet, consectetur adipiscing elit. Curabitur
mollis lorem sit amet nisl scelerisque mollis.
Vestibulum tincidunt sodales turpis quis convallis.
Curabitur id diam dictum arcu placerat lobortis
As you can see the first line is the shortest one. I've tried searching for a solution, but to no avail; it's hard to know what to actually search for!
I'm assuming if anyone has ever done this the solution will be in scripting rather than CSS. I would normally script this myself in PHP, but the thought of it hurts my brain!
Anyone have any ideas?
If I understood your question correctly, this should give you your desired result:
<?php
$str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id magna ut dui cursus volutpat at at orci. Cras aliquam, est sit amet malesuada pulvinar, justo massa pellentesque mi, nec gravida nunc velit vitae risus. Nullam bibendum purus non lacus malesuada faucibus in auctor eros. In vulputate magna quis elit gravida a dignissim elit sagittis. Sed purus dolor, imperdiet a sodales vitae, semper sed dolor. Nunc iaculis leo non justo volutpat lobortis dapibus purus pharetra. Curabitur quis dolor tortor. Mauris egestas euismod justo, vel rutrum ligula dictum nec. Quisque a arcu nibh, ac dapibus diam. Ut eget sapien pretium nulla viverra malesuada. Donec at lectus quam.";
echo strrev(wordwrap(strrev($str), 50));
?>
Output:
Lorem
ipsum dolor sit amet, consectetur adipiscing elit.
Nunc id magna ut dui cursus volutpat at at orci.
Cras aliquam, est sit amet malesuada pulvinar,
justo massa pellentesque mi, nec gravida nunc
velit vitae risus. Nullam bibendum purus non lacus
malesuada faucibus in auctor eros. In vulputate
magna quis elit gravida a dignissim elit sagittis.
Sed purus dolor, imperdiet a sodales vitae, semper
sed dolor. Nunc iaculis leo non justo volutpat
lobortis dapibus purus pharetra. Curabitur
quis dolor tortor. Mauris egestas euismod
justo, vel rutrum ligula dictum nec. Quisque a
arcu nibh, ac dapibus diam. Ut eget sapien pretium
nulla viverra malesuada. Donec at lectus quam.
I just uploaded a new plugin(concept) of mine called Virgin Headlines. When searching for other ways to achieve the effect I found your question. If I´m not misstaken my plugin solves your problem. It's not finished but is usable if you use it as in the readme on github:
https://github.com/coocoomoo/VirginHeadlines
Here is a demo: http://coocoomoo.com/dev/virgin-headlines/
If you try it out please report back on browser issues! Thanks!
You need to reverse the string's words, format it normally, inspect how many words are on the last line, then format the original string with the same number of words on the first line as were on the last of the reversed string.
精彩评论