【问题标题】:Button overflow hidden not working按钮溢出隐藏不起作用
【发布时间】:2014-11-27 11:51:48
【问题描述】:

我有以下几点:

Fiddle link

html:

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

css:

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

基本上,我希望按钮不换行。

我确定我只是遗漏了一些明显的东西,但我无法弄清楚......

【问题讨论】:

  • 如果由于某种原因 white-space:nowrap 解决方案不适合您的需求,您也可以指定 height

标签: html css


【解决方案1】:

添加以下样式以防止换行:

{
    white-space: nowrap;
}

Updated Fiddle

编辑

现在,由于您试图隐藏溢出,我建议使用text-overflow: ellipsis; 来更好地查看文本剪切,在末尾添加一个 (...):

Another Updated Fiddle

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

【讨论】:

    【解决方案2】:

    你可以使用white-space: nowrap;:

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

    【讨论】:

      【解决方案3】:

      添加white-space:nowrap;

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

      jsFiddle example

      【讨论】:

        【解决方案4】:

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

        word-wrap: word-wrap 属性允许将长单词打断并换行到下一行。

        white-space: white-space 属性指定如何处理元素内的空白。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-01-06
          • 2016-04-22
          • 2014-04-16
          • 2012-04-26
          • 2013-07-12
          • 2012-10-26
          • 2016-04-19
          相关资源
          最近更新 更多