Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit characters displayed in span

Tags:

html

css

Is there some sort of way within HTML or CSS to limit the characters displayed with a span? I use a repeater that displays these info boxes and I want to limit the characters to the first 20 characters and if the input has more, then just concatenate? The box is like image shown:

enter image description here

My code for this is:

<span class="claimedRight" maxlength="20">{{ item.provider }}</span> 
like image 233
Mark Avatar asked Nov 15 '15 09:11

Mark


People also ask

How do I limit the number of characters?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.

How do I limit the number of characters in CSS?

While you can't use CSS alone to do this, you can limit the amount of characters show using CSS as Darren has suggested. You need to set your text container to white-space: no-wrap, text-overflow: ellipsis, and overflow:hidden. Then simply set the size for your container.


1 Answers

Here's an example of using text-overflow:

.text {    display: block;    width: 100px;    overflow: hidden;    white-space: nowrap;    text-overflow: ellipsis;  }
<span class="text">Hello world this is a long sentence</span>
like image 77
Samuel Cook Avatar answered Sep 19 '22 21:09

Samuel Cook