Text-Overflow: Ellipsis Not Working
This Is What I Tried (See Here): Body { Overflow: Hidden; } Span { Border: Solid 2Px Blue; White-Space: Nowrap; Text-Overflow: Ellipsis; } Essentially, I Want...
This is what I tried (see here):
body {
overflow: hidden;
}
span {
border: solid 2px blue;
white-space: nowrap;
text-overflow: ellipsis;
}
Essentially, I want the span to shrink with ellipsis when the window is made small. What did I do wrong?
12 Answers
You need to have CSS overflow, width (or max-width), display, and white-space.
span {
border: solid 2px blue;
white-space: nowrap;
text-overflow: ellipsis;
width: 100px;
display: block;
overflow: hidden
}
body {
overflow: hidden;
}
span {
border: solid 2px blue;
white-space: nowrap;
text-overflow: ellipsis;
width: 100px;
display: block;
overflow: hidden
}
<span>Test test test test test test</span>
Addendum If you want an overview of techniques to do line clamping (Multiline Overflow Ellipses), look at this CSS-Tricks page:
Addendum2 (May 2019)
As this link claims, Firefox 68 will support -webkit-line-clamp (!)
Make sure you have a block element, a maximum size and set overflow to hidden. (Tested in IE9 and FF 7)
div {
border: solid 2px blue;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 50px;
}
For multi-lines in Chrome use :
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2; // max nb lines to show
-webkit-box-orient: vertical;
Inspired from youtube ;-)
Must Read
For multiple lines
In chrome, you can apply this css if you need to apply ellipsis on multiple lines.
You can also add width in your css to specify element of certain width:
.multi-line-ellipsis {
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
<p class="multi-line-ellipsis">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
word-wrap: break-word;
this and only this did the job for me for a
<pre> </pre>
tag
everthing else failed to do the ellipsis....
I was having an issue with ellipsis under chrome. Turning on white-space: nowrap seemed to fix it.
max-width: 95px;
max-height: 20px;
overflow: hidden;
display: inline-block;
text-overflow: ellipsis;
border: solid 1px black;
font-size: 12pt;
text-align: right;
white-space: nowrap;
Just a headsup for anyone who may stumble across this... My h2 was inheriting
text-rendering: optimizelegibility;
//Changed to text-rendering: none; for fix
which was not allowing ellipsis. Apparently this is very finickey eh?
Add this below code for where you likes to
example
p{
display: block; /* Fallback for non-webkit */
display: -webkit-box;
max-width: 400px;
margin: 0 auto;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}