【问题标题】:button fixed in height with text in multiple rows do not show in same vertical position按钮高度固定,多行文本不显示在相同的垂直位置
【发布时间】:2019-12-28 04:57:22
【问题描述】:

固定高度的按钮 css 使垂直位置很难看,因为每个按钮文本都不止一行

我尝试评论 height:80px; 然后所有按钮在顶部垂直对齐,但是所有按钮的高度不同,使 BUTTONS GROUP 看起来很难看,特别是我需要生成超过 10 个按钮

button {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: normal;
  color: #444;
  width: 120px;
  height:80px !important;
  display:inline-block;
  padding:5px;
  margin: 5px 10px;
  background-color: #fdfdfd;
  border: 1px solid #cdcdcd;
  cursor: pointer;
  border-radius: 3px;
  word-wrap: break-word;
}
<button>Text in one row </button>
<button>Text in more than one row in this button </button>
<button>Text in more than two rows in this button which have same height </button>
<button>Text in more than three rows in this button which have same height, but more text </button>

CLICK to open an image

jsfiddle

如何使按钮的高度固定,并且所有按钮都位于垂直顶部。 注意:每个按钮有不同的字数,自动换行为 1 行、2 行、3 行...

【问题讨论】:

    标签: css button height word-wrap


    【解决方案1】:

    如果您将 vertical-align: top; 添加到您的 button 元素,这将解决您的问题

    CSS

    button {
       font-family: Arial, Helvetica, sans-serif;
       font-weight: normal;
       color: #444;
       width: 120px;
       height: 80px;
       display: inline-block;
       padding: 5px;
       margin: 5px 10px;
       background-color: #fdfdfd;
       border: 1px solid #cdcdcd;
       cursor: pointer;
       border-radius: 3px;
       word-wrap: break-word;
       vertical-align: top;
    }
    

    运行下面的代码sn-p查看结果

    button {
      font-family: Arial, Helvetica, sans-serif;
      font-weight: normal;
      color: #444;
      width: 120px;
      height: 80px;
      display: inline-block;
      padding:5px;
      margin: 5px 10px;
      background-color: #fdfdfd;
      border: 1px solid #cdcdcd;
      cursor: pointer;
      border-radius: 3px;
      word-wrap: break-word;
      vertical-align: top;
    }
    <button>Text in one row </button>
    <button>Text in more than one row in this button </button>
    <button>Text in more than two rows in this button which have same height </button>
    <button>Text in more than three rows in this button which have same height, but more text </button>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-31
      • 2020-01-28
      • 1970-01-01
      • 2016-05-13
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 2018-04-18
      相关资源
      最近更新 更多