【问题标题】:Styling a Calculator in Html/CSS/Bootstrap 4.0在 Html/CSS/Bootstrap 4.0 中为计算器设计样式
【发布时间】:2020-09-08 12:49:43
【问题描述】:

我正在尝试用 CSS 创建我的第一个项目 - 一个计算器。但是我在将单元格放在一个完美的列中时遇到了问题。我希望所有单元格的大小相同。 (“=”除外)如果您能给我一些建议,那就太好了。提前致谢。 我已经走到这一步了:

计算器

<div class ="btn-group-vertical" role="group" aria-label="Vertical button group">
    <div class="btn-group btn-group-lg" role="group" aria-label="First Row">
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="7"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="8"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="9"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="+"></input>
    </div>
    <div class="btn-group btn-group-lg" role="group" aria-label="Second Row">
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="4"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="5"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="6"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="-"></input>
    </div>
    <div class="btn-group btn-group-lg" role="group" aria-label="Third Row">

        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="1"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="2"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="3"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="*"></input>
    </div>
    <div class="btn-group btn-group-lg" role="group" aria-label="Fourth Row">
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="0"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="."></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="+/-"></input>
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="/"></input>
    </div>
    <div class="btn-group btn-group-lg" role="group" aria-label="Basic example">
        <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="="></input>
    </div>
</div>

【问题讨论】:

    标签: html css bootstrap-4 calculator


    【解决方案1】:

    请看一下,希望对您有所帮助。如果仍有任何问题或疑问,请提出。

    .btn{
      width:50px;
      min-width:50px; /* this for smallest devices */
    }
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
    
    <div class ="btn-group-vertical" role="group" aria-label="Vertical button group">
        <div class="btn-group btn-group-lg" role="group" aria-label="First Row">
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="7"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="8"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="9"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="+"></input>
        </div>
        <div class="btn-group btn-group-lg" role="group" aria-label="Second Row">
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="4"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="5"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="6"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="-"></input>
        </div>
        <div class="btn-group btn-group-lg" role="group" aria-label="Third Row">
    
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="1"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="2"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="3"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="*"></input>
        </div>
        <div class="btn-group btn-group-lg" role="group" aria-label="Fourth Row">
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="0"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="."></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="+/-"></input>
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="/"></input>
        </div>
        <div class="btn-group btn-group-lg" role="group" aria-label="Basic example">
            <input type="button" class="btn btn-secondary btn-outline-dark" waves-effect value="="></input>
        </div>
    </div>

    【讨论】:

    • @NiklasFlink 欢迎您
    【解决方案2】:

    您可以使用 CSS 网格来创建计算器。这些数字将充当相同宽度的不同行和列元素。对于“=”,如果您希望它具有更大的宽度,则可以将其跨越多列;如果您希望高度更大,则可以将其跨越多行。

    【讨论】:

      【解决方案3】:

      对于完美的列,您可以使用网格系统:

      <div class="row">
          <div class ="col-2">
              <div class="row">
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="7"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="8"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="9"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="+"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="4"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="5"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="6"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="-"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="1"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="2"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="3"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="*"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="0"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="."></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="+/-"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-3" waves-effect value="/"></input>
                  <input type="button" class="btn btn-secondary btn-outline-dark col-12" waves-effect value="="></input>
              </div>
          </div>
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-26
        • 2014-07-12
        • 2020-02-23
        • 1970-01-01
        • 2019-04-05
        • 2020-08-24
        • 2016-05-23
        • 1970-01-01
        相关资源
        最近更新 更多