我有一个封装了输入html标签的React组件。input标签的默认行为是,如果字符数超过输入可以显示的字符数,我们可以使用不可见的滚动向左和向右滚动(例如,我键入John Smitheens作为大小为11)。
我想把显示器改成约翰·史密斯...如果输入未聚焦(未单击)。
我不知道我想要预先限制的大小或字符数,因为React组件在很多地方使用,并且大小根据父组件(宽度: 100%)而不同。有没有办法获得输入大小或知道字符何时超过输入宽度?谢谢
<!DOCTYPE html>
<html>
<body>
<input placeholder="Search User" type="text" size="11">
</body>
</html>
发布于 2020-04-29 14:23:00
在样式表中尝试这样做:)
将其添加到您的input
css。
text-overflow: ellipsis;
这里有类似的情况:
how to add three dots to text when overflow in html?
有关该主题的更多信息:
https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
发布于 2020-04-29 14:21:22
只需将text-overflow: ellipsis;
添加到输入
input {
text-overflow: ellipsis;
}
<!DOCTYPE html>
<html>
<body>
<input placeholder="Search User" type="text" size="11">
</body>
</html>
https://stackoverflow.com/questions/61495338
复制相似问题