Truncate text at absolute div position
Here is a JSFiddle example I'm trying to do: JSFiddle example
It is responsive and in large width this is exactly what I want, for example:
But in small sizes it overlaps other text and / or breaks lines like this:
and this:
And this is my css for the texts:
.giro-nome {
position: absolute;
top: 25%;
}
.giro-percentual {
position: absolute;
right: 0;
top: 25%;
font-weight: 700;
}
I wanted to just stop the text on one line, something like this (expected, not real):
Is it possible? Probably not with absolute as I do, but I have no idea how to do it.
Thank you frontline.
source to share
text-overflow: ellipsis
; this is what you are looking for.
8.2. Overflow ellipsis: the "text overflow" property
This property specifies to render when inline content overflows its block container element ("block") in its inline progression that has "non-overflow" visible. Text may overflow for example when it is prevented from wrapping (for example, due to "White-space: nowrap or one word is too long to match). The values are as follows:
ellipsis Display ellipsis (U + 2026) to represent clipped inline content. Implementations can replace more language / script - matching ellipsis symbol or three dots "..." if ellipse symbol is not available.
However, you must first specify the width of the absolutely positioned element. Either using properties left
/ right
or other approaches like width: 90%
or width: calc(100% - 80px)
:
.giro-nome {
position: absolute;
top: 25%;
left: 0; right: 80px; /* Equal to > width: calc(100% - 80px) */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
source to share