'How to set maximum line of text using flex css react
But it look actually not so good if the title or author is so long, so i wonder how can i set maximum of text line to fixed number, example 3, example:
This very long
long long
This very long
long long
This very long
long long
Will be
This very long
long long
This very long....
I already add this to css:
max-width: 128px;
max-lines: 3;
font-size: 16px;
color: grey;
text-align: center;
text-overflow: ellipsis;
But not work
Solution 1:[1]
css max-lines
"is a proposal not yet supported anywhere" according to https://caniuse.com/sr_css-max-lines.
The correct css uses webkit clamp line that is well supported except for IE. see https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-line-clamp
In your case you would use something like:
{
width: 300px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
where the line-clamp value is a code specifying elipses after 3 lines. That block is taken from an example in the MDN link given above, where more information can be found.
Solution 2:[2]
The method you're trying will only work with one line of text due to the limited capabilities of css (That is if you expect it to work dynamically and not manually)
The following styles are the ones responsible for achieving that effect:
.overflow-wrap {
white-space: nowrap;
overflow: hidden;
overflow-wrap: break-word;
text-overflow: ellipsis;
width: 250px;
}
<h1>Overflow wrap</h1>
<p class="overflow-wrap">This text will be wrapped after a certain amount of words</p>
<p>This text will not be wrapped after a certain amount of words</p>
To achieve the effect you want, there is an answer provided here:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dave Pritlove |
Solution 2 |