A simple explanation how to make overflow: ellipses work in Internet Explorer.
Months ago I had to stylize inputs with fixed width, but very long content. I wanted to show an ellipsis (“…”) to represent the clipped text.
<div class="long-value-input-container"> <input type="text" value="sdghkjsdghhjdfgjhdjghjdfhghjhgkdfgjnfkdgnjkndfgjknk" class="long-value-input" readonly /> </div>
To do so i used this CSS rule:
.long-value-input { width: 200px; height: 30px; padding: 0 10px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
It worked just fine in Chrome, but in IE the ellipsis were not shown.
After several days in struggle I found a simple solution. To display them the input had to have the readonly attribute. But what if I wanted to write in it? I decided to use javascript to toggle its attribute value everytime when click and blur events are fired.
// making the input editable $( '.long-value-input' ).on( 'click', function() { $( this ).prop( 'readonly', '' ); $( this ).focus(); }) // making the input readonly $( '.long-value-input' ).on( 'blur', function() { $( this ).prop( 'readonly', 'readonly' ); });
Working example:
https://github.com/marianadgeorgieva2/How-to-make-text-overflow-ellipsis-work-for-inputs-in-IE.git
Thanks! This helped a ton!
LikeLike
How can implement this on Select rather than input?
LikeLike
This solution is looks perfect for selecting an option from list, but in my case i need to enter a text so that i can search available options. Is there any other option to make the textbox editable?
LikeLike
Do u got solution?can you please reply?
LikeLike
I’ve scoured the internet. This is the only working “hack” I’ve found to get ellipsis working in IE input fields.
However, there’s a significant (in my opinion) drawback: when selecting/focusing the input field, you have to click twice to get it to be editable. This is a dealbreaker for me since I have a bunch of fields that will be need editing. Bummer 😦
LikeLike
Hi, Max!
I tested in Chrome and Edge and I cannot reproduce this issue. Can you give me a JSFiddle with your code and I’ll try to help you.
LikeLike
Hi Mariana,
This issue is reproducible in all IE version including IE 11 also. I just run your code from github. If we remove readonly element completely from the DOM on click, it seems to be working.
LikeLike
This was helpful to me — thanks for posting it!
LikeLike
I couldn’t believe that this problem was all because of a missing readonly attribute… I spent hours trying every possible solution before I came across this one. Thanks a lot for the informative post!
LikeLike
You’ re welcome, Chris!
LikeLike