I want to show some text in a, say, < h6 > element. The content is mostly fixed but few lines with some variable content I know may be too long.
- I prefer to use n to organize the source text in lines as I want, because this way is very convenient in the source file;
- I want the pieces of split text to be shown centered or right aligned, I will have to decide;
- I want to indicate myself the optional splitting points, with < wbr > or something as I know the problematic lines and how I want to split them when they exceed length;
- The first part of the split line I want to remain left aligned.
For example, in case of right aligned split:
Information foo: This is a normal line of text
Information bla:
This is a line which had to be split
In case of center aligned split:
Information foo: This is a normal line of text
Information bla:
This is a line which is very long and
definitely would not fit
I found no solution to meet all these criteria. One annoying result was as such:
Information foo: This is a short line of text
Information bla:
Information This is a line which is very long
bar: The line uses the space not occupied above
This happens, for example, with "float:right". I think is not possible to apply some style only to the element containing text but I prefer not to have each line in an element. As I said, using n to organize the content is very content. If possible, I would limit the usage of additional elements only to too long parts, like this:
<pre>
Information foo: This is a normal line of textn
Information bla:
<span>This is a content which had to be split<span>n
</pre>
Another attempt would be like
<elem style="white-space: pre-wrap">
Information foo: This is a normal line of textn
Information bla:
</elem><elem>This is a content which had to be split</elem><elem>n
Details: some other line
</elem>
but not sure how to continue from here.
2
Answers
You can do this, but I’m not sure if this is what you are looking for.
Then, use JS to separate and process the text.
If you don’t want it to be on the absolute right, you can replace the
align-self: flex-end;
withpadding-left
.Keep in mind:
<br>
elements will be removed from the text!Anyway, what you are trying to do is a bit unusual so that you will have unusual answers 🙂
In the example below shows simple use of CSS class selectors and HTML inline-block elements. Details are in the text of the HTML.