简体   繁体   English

按钮溢出隐藏不起作用

[英]Button overflow hidden not working

I have the following: 我有以下内容:

在此输入图像描述

Fiddle link 小提琴链接

html: HTML:

<button>Here's a long chunk of text</button>

css: CSS:

button {
   width: 80px;
   overflow: hidden;
}

Basically, I want the button not to wrap the text.. 基本上,我希望按钮不包装文本..

I'm sure I'm just missing something obvious, but I can't figure it out... 我敢肯定我只是遗漏了一些明显的东西,但我无法弄明白......

Add the following style to prevent line breaks: 添加以下样式以防止换行:

{
    white-space: nowrap;
}

Updated Fiddle 更新小提琴

EDIT 编辑

Now, since you're trying to hide the overflow, I'd suggest to use text-overflow: ellipsis; 现在,既然你试图隐藏溢出,我建议使用text-overflow: ellipsis; to give better looks to the text cut, adding a (...) at the end: 为文本剪切提供更好的外观,最后添加一个(...):

Another Updated Fiddle 另一个更新的小提琴

 button { width: 80px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } 
 <button>Here's a long chunk of text</button> 

You can use white-space: nowrap; 你可以使用white-space: nowrap; :

 button { width: 80px; overflow: hidden; white-space: nowrap; } 
 <button>Here's a long chunk of text</button> 

Add white-space:nowrap; 添加white-space:nowrap;

button {
    width: 80px;
    overflow: hidden;
    white-space:nowrap;
}

jsFiddle example jsFiddle例子

add white-space: nowrap; 添加white-space: nowrap; and word-wrap: normal; word-wrap: normal;

word-wrap: The word-wrap property allows long words to be able to be broken and wrap onto the next line. word-wrap:自动换行属性允许长单词被打破并换行到下一行。

white-space: The white-space property specifies how white-space inside an element is handled. white-space: white-space属性指定如何处理元素内的空白。

 button { width: 80px; overflow: hidden; white-space: nowrap; word-wrap: normal; } 
 <button>Here's a long chunk of text</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM