-2

How can i limit text of button? Just to trim some long text inside button. All I'm allowed to do is only change the CSS

<html>

<body>
  <input style="?" type="button" value="Trim long long long long long long long text that goes beyond a specified length" />
</body>

</html>

1 Answers1

1

To make the input match a specific length in pixels (e.g. 100px) you need to set the width. This will make your input take 100px width.

To get a proper text overflow you add overflow:hidden and text-overflow:ellipsis.

Lastly add your text into the title attribute too, so you get the full text as tooltip when hovering the button - This is optional but i'd strongly recommend it for accessibility reasons.

.trimmedbutton {
  width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}
<html>

<body>
  <input class="trimmedbutton" type="button" value="Trim long long long long long long long text that goes beyond a specified length" title="Trim long long long long long long long text that goes beyond a specified length" />
</body>

</html>
Fabian S.
  • 2,441
  • 2
  • 24
  • 34