【问题标题】:Boostrap div content align center?Bootstrap div内容对齐中心?
【发布时间】:2020-05-05 15:54:07
【问题描述】:

我正在使用引导程序制作一个 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 的文档,我一定做错了什么......

【问题讨论】:

  • 您是否尝试在主div 上添加.justify-content-center?如果我是你,我会将所有内容都包装在.container.container-fluid中,然后是.row(指定.col的数量)并在.row上添加.justify-content-center,看看是否工作。

标签: python html flask web-applications


【解决方案1】:

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

例如。参考以下sn-p。

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

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

希望你会

【讨论】:

  • 我相信他们正在寻找整个 div 以页面为中心,而不是内容要以 div 为中心
  • 是的,我一直在寻找要居中的整个 div,我已经弄清楚了,谢谢你们俩的支持!
猜你喜欢
  • 2021-03-31
  • 2019-10-14
  • 1970-01-01
  • 2016-05-17
  • 1970-01-01
  • 2013-09-11
  • 2014-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多