如何将其大小限制的可满足段落插入?
我需要一个编辑一行段落,以便插入其中的文本一定不能溢出其大小。
目前,我正在使用CSS试图隐藏溢出并避免多行(不显示该段落的孩子)。
但是,理想情况下,我需要插入到段落中的文本在溢出后立即被“剪切”。
这是我到目前为止的代码(也 jsfiddle ):
div
{
width: 50vw;
height: 50vh;
margin: 10px auto;
background-color: gray;
}
p
{
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 25%;
background-color: brown;
text-align: center;
white-space: nowrap;
overflow-x: hidden;
}
/* Avoiding multiple lines */
p *
{
display: none;
}
<div>
<p contentEditable="true">
Edit me! Unfortunally I can be overflowed... :(
</p>
</div>
I need an editable one line paragraph such that the text inserted into it must not overflow its size.
I'm currently using CSS to try to hide the overflow and also to avoid multiple lines (by not displaying the paragraph's children).
However, ideally I need the text inserted into the paragraph to be "cut" as soon as it would overflow.
This is my code so far (also in JSFiddle):
div
{
width: 50vw;
height: 50vh;
margin: 10px auto;
background-color: gray;
}
p
{
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 25%;
background-color: brown;
text-align: center;
white-space: nowrap;
overflow-x: hidden;
}
/* Avoiding multiple lines */
p *
{
display: none;
}
<div>
<p contentEditable="true">
Edit me! Unfortunally I can be overflowed... :(
</p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
word-break:在这种情况下属于
属性You can use
word-break: keep-all;
property in this case