I have a standard responsive title (that breaks into multiline):
<h1>This is my beautiful
title!</h1>
I also have a (multiline) ellipsis defined on it (this is webkit specific I know but also ok because I need it only for iOS/Android) so something like:
h1 {
font-size: 18px;
line-height: 1.8em;
height: 3.6em;
position: relative;
display: block;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
What I would like to do is have the first line of my (multiline) title have different width - to achieve a more visually balanced title. But I cannot add new markup and the titles are of course dynamic/different all the time. Am looking for a CSS only solution (no JS).
Simple problem - how you you make line 1 in multiline text narrower but keep ellipsis at the same time.
So that the title would then look something like:
<h1>This is my
beautiful title!</h1>
SOLUTION 1 - I found a way to do this by using a right-floated pseudo element on the first line of the text - so something like:
h1:before {
content: "";
float: right;
width: 30%;
height: 1em;
}
PROBLEM 1 - floated elements do not work in a flexbox container and -webkit-box is still a flexbox container. And I need it to make ellipsis work. Any ideas on how to "float" a box to the right and wrap text around it without actually using a float?
SOLUTION 2 - I found a clever way to do this by changing the text layout direction and text-indent - so something like:
h1 {
direction: rtl;
text-indent: 30%;
text-align: left;
}
PROBLEM 2 - seems nice and clean - as long as you don't have trailing apostrophes, colons and stuff like that - because RTL will change their position to the beginning of the sentence (and I can't add additional markup or characters within H1 - only possibly outside).. so with this applied my title now looks like
<h1>!This is my
beautiful title</h1>
Any ideas on more hacks that could correct problem 1 or 2? It feels like I'm so close but at the same time so far away.
EDIT: problem examples here - https://codepen.io/anon/pen/bYqZQP