【问题标题】:Making all buttons in a column and row the same size?使列和行中的所有按钮大小相同?
【发布时间】:2014-03-07 19:32:14
【问题描述】:

我正在制作一个计算器,我希望表格行和列中的所有按钮在水平和垂直方向上相互对齐。它们现在水平对齐,因为我有行,但我希望在垂直方向上具有相同的大小,尽管我在按钮中放了什么。 谢谢。

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    在你的 CSS 中添加一个特定的宽度

    input {
       text-align:center;
       width:100px;
    }
    

    【讨论】:

      【解决方案2】:

      像这样写你的CSS:

      <style>
      td{
        text-align:center;
        }
        button{
          width:100%;
        }
      

      你的html是这样的:

          <tr>
            <td>
              <button>BACK</button>
            </td>
            <td>
              <button>C</button>
            </td>
            <td>
              <button>CE</button>
            </td>
          </tr>
          <tr>
            <td>
              <button>7</button>
            </td>
            <td>
              <button>8</button>
            </td>
            <td>
              <button>9</button>
            </td>
          </tr> etc ...
      

      然后,如果你想使用 jquery,你可以使用这个方便的脚本来使所有 tds 的大小为最宽:

        $(function(){
          var widest=Math.max($('td').width());
          $('td').width(widest);
        })
      

      如果您不想使用 jquery,请使用 @Abhidevs 方法设置固定宽度。

      使用我的版本here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-29
        • 2015-11-15
        • 2014-12-20
        • 2018-05-31
        • 1970-01-01
        • 1970-01-01
        • 2016-09-16
        • 1970-01-01
        相关资源
        最近更新 更多