自举文本中的文本不会居中

时间:2018-11-14 11:34:12

标签: html css twitter-bootstrap center

我正在尝试创建虚拟轮盘。现在,我所关心的完全是美学问题。在右侧的文本框中,#chipsInv中的数字不会居中,除非我放置了html“ center”标签,然后由于某种原因,它在底部创建了大量的空白空间。

这是我的代码,因为我认为Java代码无关紧要,所以我省略了它:

<!DOCTYPE html>
<html>

<head>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <style>
    #ball {
        position: absolute;
        left: 208px;
        top: 40px;
        z-index: 1;
        width: 20px;
        height: 20px;
        transition: top 1s;
    }
    
    #wheel {}
    
    form {}
    
    .row {
        padding: 20px;
    }
    </style>
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-lg-5">
                <img id="ball" src="ball.png" onclick="spin()"></img>
                <img id="wheel" src="Rwheelbg.png" onclick="spin()"></img>
            </div>
            <div class="col-lg-1">
                <button id="reset" onclick="reset()">Reset</button>
            </div>
            <div class="col-lg-6">
                <div class="well well-lg">
                    <span><center>Chips</center></span>
                    <br>
                    <span style="font-size: 180px; text-align: center;" id="chipsInv">10</span>
                    <!-- Why won't this center!? -->
                    <br>
                    <span style="float:right;" id="purchase"><a style = "color:green !important;" href = "#">$ Purchase More Chips?</a></span>
                </div>
            </div>
            <!-- Row ends here -->
        </div>
        <p>Bet on:</p>
        <form action="">
            <input type="checkbox" name="21" value="310" id="310"> 21
            <br>
            <input type="checkbox" name="9" value="100" id="100"> 9
            <br>
            <input type="checkbox" name="14" value="120" id="120"> 14
            <br>
            <input type="checkbox" name="13" value="240" id="240"> 13
        </form>
        <p>Bet on up to four numbers. However, be warned, the more numbers you bet on, the lower your chip return will be.</p>
        <!-- container ends here -->
    </div>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

在Bootstrap中,尽可能地/尽可能地使用Bootstrap类来提供所需的样式,因为Bootstrap类被设计为彼此兼容。

  <div class="col-lg-6">
      <div class="well well-lg">
        <div class="text-center">Chips</div>
        <div class="text-center" style="font-size: 180px;" id="chipsInv">10</div>
        <div class="float-right" id ="purchase"><a style = "color:green !important;" href = "#">$ Purchase More Chips?</a></div>        
      </div>
  </div>

如果您想使示例中的所有内容以文本为中心,则只需在well-lg类旁边添加text-center类,如下所示:

  <div class="col-lg-6">
          <div class="well well-lg text-center">
            <div>Chips</div>
            <div style="font-size: 180px;" id="chipsInv">10</div>
            <div class="float-right" id ="purchase"><a style = "color:green !important;" href = "#">$ Purchase More Chips?</a></div>        
          </div>
  </div>

另外;

  • 通过Bootstrap,他们建议您在可能的情况下使用div,然后 您可以通过修改那些类别来指定不同的行为 div,例如“ d-inline”或“ d-block”。那就是我改变的原因 您的跨度到divs。
  • 确保您的col-lg-6 div包含在“ row”类的div中,并且根据文档,这些div一起指定col div时,这些div不得超过12。Bootstrap Grid Docs