Search code examples
djangotwitter-bootstraptwitter-bootstrap-3django-bootstrap3

How to move form field to new line with bootstrap grid?


I am using django-bootstrap3 form that I would like to alter a little bit. This is code I am using:

<div class="row">
  {% for field in form %}
    {% bootstrap_field field form_group_class='col-md-6 form-group label-floating' %}
    {% if field.name == 'field3' %}
      <!-- what should I add here -->
    {% endif %}

  {% endfor %}
</div>

It creates two columns of form fields, since there is col-md-6. I would like to move field from second column to new line. How can I do this in my code?

field1     field2
field3     field4
field5     field6

and I want fields to be ordered like this:

field1     field2
field3     
field4     field5
field6

Solution

  • Nice and easy, just use col-md-6 as you already have for field 1 and field 2, but for field 3 use col-md-6 and col-md-offset-6.

    So it needs to be as follows:

    <div class="col-md-6"></div><div class="col-md-6"></div>
    <div class="col-md-6 col-md-offset-6"></div>
    <div class="col-md-6"></div><div class="col-md-6"></div>
    <div class="col-md-6 col-md-offset-6"></div>
    

    Use CSS to change the offset direction:

    .col-md-offset-6 {
          margin-right: 50% !important;
    }