Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What CSS controls the right and left margins between these form elements in Twitter Bootstrap?

enter image description here

I can't figure out what controls the margins between these inline form elements. For example the margin between the two text input fields.

EDIT: I know how to control to alter these margins, but why is there a margin between them AT THE MOMENT. I can't find any CSS in bootstrap that is responsible for these 3 or 4px margins between them at the moment.

like image 958
user1525612 Avatar asked Sep 01 '13 19:09

user1525612


People also ask

What is bootstrap form control?

Bootstrap form-control class is use to make an element fit it container <div> <input type='text' class='form-control'> </div> div{ width: 400px; background: gray; }

What does margin right do in CSS?

The margin-right CSS property sets the margin area on the right side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

What is form horizontal in bootstrap?

A horizontal form means that the labels are aligned next to the input field (horizontal) on large and medium screens. On small screens (767px and below), it will transform to a vertical form (labels are placed on top of each input). Additional rules for a horizontal form: Add class .


2 Answers

The space between the inputs on Bootstrap's documentation is due to white space in the HTML. Remember that .form-group is set to inline block, which is sensitive to white space.

For a demonstration, see http://jsfiddle.net/kvcrawford/Rs54Q/1/

You can fix it with some CSS like the following:

.form-inline-space-fix .form-group {
    margin-right: 4px;
}
.form-inline-space-fix .form-group:last-child {
    margin-right: 0;
}
like image 85
Kevin C. Avatar answered Sep 24 '22 12:09

Kevin C.


Here are the CSS selectors you will need..

Margin the inputs/fields:

.form-inline .form-group {
    margin: 0px 10px; /* Add something like this */
}

Margin for the checkbox/radio button:

.form-inline .radio, .form-inline .checkbox {
    margin: 0px 10px; /* Add something like this */
}

Margin for the submit button:

.bs-example > .btn, .bs-example > .btn-group {
    margin: 0px 10px; /* Add something like this */
}

Margin for the entire inline form

.bs-example {
    margin: 0px 30px; /* Add something like this */
}

And to answer your question, there are currently margins between elements, because that is the default. If you wish to remove them, I would suggest doing this manually by adding negative margins to the CSS controls I specified above. For instance, if you wish to remove the margins between the inputs, do this:

.form-inline .form-group {
    margin: 0px -3px; /* Add a negative margin to remove it*/
}
like image 44
Josh Crozier Avatar answered Sep 22 '22 12:09

Josh Crozier