【问题标题】:How to centralize inline-forms in bootstrap 4?如何在引导程序 4 中集中内联表单?
【发布时间】:2018-02-05 19:15:59
【问题描述】:

这是我的 html:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <center class="container" style="margin:auto; background-color:black;">
            <img src=test + "0" id=image style="width:900px; height:900px;"><br/>
            <form class="form-inline" style="text-align:center;background-color:red;">
                <label id="out">wait...</label>
                <select class="form-control" style="width:111px;" id="sel1">
                    <option>flags 1</option>
                    <option>flags 2</option>
                    <option>people 1</option>
                    <option>people 2</option>
                    <option>people 3</option>
                </select>
                <div class="btn-group">
                    <button class="btn btn-outline-success" type="button" onclick='clearInterval(player);document.getElementById("image").src = "counter.gif";setTimeout(function(){ start(); },5000)'>play</button>
                    <button class="btn btn-outline-danger" type="button" onclick='clearInterval(player);document.getElementById("result").innerHTML = new Date().getTime() - timestamp'>stop</button>
                </div>
                <input class="form-control" type="number" id="delay" style="width:80px;">ms</input>
                <label id='result'></label>
            </form>
        </center>
    </body>
</html>

如您所见,我已经在表单标签上使用了text-align:center,但它仍然无法按我的意愿工作。如何让我的表单在页面中心对齐?

为什么我的代码没有按预期工作?

【问题讨论】:

  • 你需要先修正你的 HTML 并正确使用 bootstrap

标签: html css alignment bootstrap-4


【解决方案1】:

请立即查看

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    </head>
    <body>
        <center class="container" style="margin:auto; background-color:black;">
            <img src=test + "0" id=image style="width:900px; height:900px;"><br/>
            <form class="form-inline justify-content-center" style="text-align:center;background-color:red;">
                <label id="out">wait...</label>
                <select class="form-control" style="width:111px;" id="sel1">
                    <option>flags 1</option>
                    <option>flags 2</option>
                    <option>people 1</option>
                    <option>people 2</option>
                    <option>people 3</option>
                </select>
                <div class="btn-group">
                    <button class="btn btn-outline-success" type="button" onclick='clearInterval(player);document.getElementById("image").src = "counter.gif";setTimeout(function(){ start(); },5000)'>play</button>
                    <button class="btn btn-outline-danger" type="button" onclick='clearInterval(player);document.getElementById("result").innerHTML = new Date().getTime() - timestamp'>stop</button>
                </div>
                <input class="form-control" type="number" id="delay" style="width:80px;">ms</input>
                <label id='result'></label>
            </form>
        </center>
    </body>
</html>

【讨论】:

  • 您需要在表单类中添加“justify-content-center”。
【解决方案2】:

添加justify-content: center; 即可。

更多关于 flexbox 的信息:Flexbox

【讨论】:

    猜你喜欢
    • 2015-11-19
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2012-04-08
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多