简体   繁体   中英

Boostrap div content align center?

i am making a web app with bootstrap and i want to put my div content to the center of the page and the table with it so i need help. Here is my code and preview of the page below. Thanks in advance!

{% 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 %} 

HERE IS A LINK TO A PICTURE OF THE PAGE! PREVIEW

I tried to fix that but i just can't. I must've done something wrong even though i checked the docs of the Bootstrap as well...

To make any content center aligned in bootstrap I always use very basic trick. No matter which you are using just write text-center in value of class attribute . If you are already using any other class simply enter text-center next to it.

For example. Refer following snippet.

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

Also you can use bootstrap grid systems ie row and col classes to align the contents as per your requirements.

Hope you will

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM