Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use text-overflow ellipsis in an html input field?

Tags:

html

css

ellipsis

My web page has input fields to which I have applied the following css :

.ellip {     white-space: nowrap;     width: 200px;     overflow: hidden;     -o-text-overflow: ellipsis;     -ms-text-overflow: ellipsis;     text-overflow: ellipsis; } 

But this doesn't seem to have any effect. Am I missing something obvious here or is it not possible to have an ellipsis in an input field using CSS only?

like image 830
Jelly Ama Avatar asked Mar 19 '12 14:03

Jelly Ama


People also ask

How do you ellipsis text in HTML?

To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.

How do you input an ellipsis?

1. Make the "ellipsis" symbol under Windows: Alt + 0 1 3 3 = … The technique : You keep the Alt key pressed (key just to the left of the Space bar), then you successively type the digits 0 1 3 3 then you finally release the Alt key, which will display the symbol " ellipsis ": …

How do I force text-overflow ellipsis?

Inline overflow occurs when the text in a line overflows the available width without a breaking opportunity. To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.

What is text-overflow in HTML?

The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.


1 Answers

I know this is an old question, but I was having the same problem and came across this blog post from Front End Tricks And Magic that worked for me, so I figured I'd share in case people are still curious. The gist of the blog is that you CAN do an ellipsis in an input in IE as well, but only if the input has a readonly attribute.

Obviously in many scenarios we don't want our input to have a readonly attribute. In which case you can use JavaScript to toggle it. This code is take directly from the blog, so if you find this answer helpful you might consider checking out the blog and leaving a comment of appreciation to the author.

// 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');  });
.long-value-input {    width: 200px;    height: 30px;    padding: 0 10px;    text-overflow: ellipsis;    white-space: nowrap;    overflow: hidden;  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <div class="long-value-input-container">    <input type="text" class="long-value-input" value="sdghkjsdghhjdfgjhdjghjdfhghjhgkdfgjnfkdgnjkndfgjknk" readonly />  </div>
like image 52
jennEDVT Avatar answered Sep 20 '22 07:09

jennEDVT