Boostrap div内容对齐中心吗?

问题描述 投票:-1回答:1

我正在使用引导程序制作一个Web应用程序,我想将div内容放置在页面和表格的中心,因此我需要帮助。这是我的代码和以下页面的预览。预先感谢!

{% extends 'base.html' %}

{% block head %}<title>{{ title }}</title>{% endblock %}

{% block content %}
    <div class="content-section bg-white border border-primary mx-md-n5 shadow-lg px-5 mt-auto">
        <form method='POST' action=''>
            {{ form.hidden_tag() }}
            <fieldset class="form-group">
                <legend class="border-bottom mb-3">Calculate BMI</legend>
                <div class="form-group">
                    {{ form.weight.label(class="form-control-label mb-3") }}
                    {% if form.weight.errors %}
                        {{ form.weight(class="form-control form-control-lg is-invalid") }}
                        <div class="invalid-feedback">
                            {% for error in form.weight.errors %}
                                <span>{{ error }}</span>
                            {% endfor %}
                        </div>
                    {% else %}
                        {{ form.weight(class='form-control form-control-lg') }}
                    {% endif %}
                </div>
                <div class="form-group">
                    {{ form.height.label(class="form-control-label mb-3") }}
                    {% if form.height.errors %}
                        {{ form.height(class="form-control form-control-lg is-invalid") }}
                        <div class="invalid-feedback">
                            {% for error in form.height.errors %}
                                <span>{{ error }}</span>
                            {% endfor %}
                        </div>
                    {% else %}
                        {{ form.height(class='form-control form-control-lg') }}
                    {% endif %}
                </div>
                <div class="form-group">
                    {{ form.submit(class="btn btn-danger btn-block")}}
                </div>
                <small><i>Formula: [Weight(kg)/Height²(cm²)] * 10000</i></small>
            </fieldset>
        </form>
    </div>
    <hr class="border border-primary shadow-lg mx-md-n5">
    <table class="table table-responsive-md mx-md-n5 shadow-lg table-bordered table-hover">
        <thead class="thead-dark">
            <tr>
            <th scope="col">Table</th>
            <th scope="col">Low Body Weight</th>
            <th scope="col">Normal Weight</th>
            <th scope="col">Overweight</th>
            <th scope="col">Adipositas</th>
            <th scope="col">Too Overweight</th>
            </tr>
        </thead>
        <tbody>
            <tr>
            <th scope="row">BMI:</th>
            <td> < 19 </td>
            <td>19-24</td>
            <td>25-29</td>
            <td>30-40</td>
            <td> > 40 </td>
            </tr>
        </tbody>
    </table>


{% endblock %} 

这里是页面图片的链接!PREVIEW

我试图解决这个问题,但我做不到。即使我也检查了Bootstrap的文档,我也一定做错了...

python html flask web-applications
1个回答
0
投票

为了使任何资源中心都按照引导程序对齐,我总是使用非常基本的技巧。无论使用哪个,只需将class-center的值写入text-center。如果您已经在使用任何其他类,只需在其旁边输入text-center

例如。请参阅以下代码段。

<div class="content-section text-center">

此外,您也可以使用引导网格系统,即row和col类,根据您的要求对齐内容。

希望你会

© www.soinside.com 2019 - 2024. All rights reserved.