I'm using Bootstrap 4.0 beta 2 and try to align label and form control horizontal in one line by using form-row and col-* classes.
Now I'm trying to align two of these form-row structs in one line, see fiddle (use HD resolution when running). But I don't know why the first input in first row is not vertically aligned with input field of second row. I've struggled for some hours now and using different classes form-inline, row, and so one and tried to play with margin and padding classes, but no luck.
The DOM cannot be changed, only the classes applied. Who can help me?
The problem is that your first column additionally has form-row on it, creating a row inside another row. There should never be a row inside a row; only use columns inside of rows. These rows add additional padding (15px for row, and 5px for form-row), which interferes with the percentage-based widths and offsets when you nest them.
Instead of nesting your second label + div inside of a new form-row, you need to take it out of its form-row, and place it inside of the form-row of the first label + div. After this, you'll need to adjust the col-md counts of both label+ div combinations to suit.
I've gone with 2 and 3 respectively, as that comes to a grand total of 10 ((2 + 3) + (2 + 3)), which equals the total of your second row (2 + 8).
I've created a fiddle showcasing this here, and you can also see this by maximising the snippet below:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<form>
<fieldset>
<div class="form-row">
<label class="col-form-label col-md-2 col-sm-12">LABEL</label>
<div class="col-md-3 col-sm-12">
<input type="text" class="form-control">
</div>
<label class="col-form-label col-md-2 col-sm-12">LABEL</label>
<div class="col-md-3 col-sm-12">
<input type="text" class="form-control">
</div>
</div>
<div class="form-row mt-2">
<label class="col-form-label col-md-2 col-sm-12">LABEL</label>
<div class="col-md-8 col-sm-12">
<input type="text" class="form-control">
</div>
</div>
</fieldset>
</form>
Hope this helps! :)
CSS Only Solution:
Assuming you can't modify the DOM, you can always fall back to CSS:
.form-row.mt-2 {
width: 100%;
}
#media screen and (min-width: 768px) {
.form-row.mt-2>div {
padding-left: 4px;
padding-right: 13px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<form>
<fieldset>
<div class="form-row">
<div class="form-row col-md-6 col-sm-12">
<label class="col-form-label col-md-4 col-sm-12">LABEL</label>
<div class="col-md-4 col-sm-12">
<input type="text" class="form-control">
</div>
</div>
<div class="form-row col-md-6 col-sm-12">
<label class="col-form-label col-md-4 col-sm-12">LABEL</label>
<div class="col-md-4 col-sm-12">
<input type="text" class="form-control">
</div>
</div>
</div>
<div class="form-row mt-2">
<label class="col-form-label col-md-2 col-sm-12">LABEL</label>
<div class="col-md-8 col-sm-12">
<input type="text" class="form-control">
</div>
</div>
</fieldset>
</form>
Though again, the DOM modification would be the more preferable solution :)
Check the snippet.
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" />
<form class="col-12">
<div class="form-row">
<div class="col-md-6 col-12">
<div class="form-row">
<label class="col-form-label col-md-4 col-12">LABEL</label>
<div class="col-md-8 col-12">
<input type="text" class="form-control">
</div>
</div>
</div>
<div class="col-md-6 col-12">
<div class="form-row">
<label class="col-form-label col-md-4 col-12">LABEL</label>
<div class="col-md-8 col-12">
<input type="text" class="form-control">
</div>
</div>
</div>
</div>
<div class="form-row align-items-center mt-2">
<label class="col-form-label col-md-2 col-12">LABEL</label>
<div class="col-md-10 col-12">
<input type="text" class="form-control">
</div>
</div>
</form>
Related
I have this layout
<div class="container-fluid header">
<div class="row">
<div class="col-md-4">
<label>Date From</label>
<input type="text" class="form-control" bsDatepicker [(bsValue)]="dateFrom" [minDate]="currentDate">
</div>
</div>
</div>
after that the label is on top of the input. I can't find a way so in this same col-md-4, the label to be
next to the input - inline. So they show together in the same line.
How can i make this and to preserve the responsivness of the col bootstrap class ?
Add form tag with inline class.
<div class="container-fluid">
<div class="row">
<form class="form-inline">
<div class="col-md-4 form-group ">
<label>Date From</label>
<input type="text" class="form-control" bsDatepicker [(bsValue)]="dateFrom" [minDate]="currentDate">
</div>
</form>
</div>
How can I combine all the form group items such as Select, Input items together just using bootstrap framework?
I have tried the below way but as expected I am getting the space between Select and Input Box
DEMO
The problem is your declaration of mx-sm-3. This applies for the -sm breakpoint and greater if there is no other declaration. The simplest way to correct this is add a reset at the larger breakpoint: mx-md-0:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="form-inline">
<div class="form-group">
<select class="custom-select mx-md-0">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
<div class="form-group mx-sm-3 mx-md-0">
<input class="form-control" type="text">
</div>
<div class="form-group mx-sm-3 mx-md-0">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
Expand the above code snippet to see how it will render when you exceed the -sm breakpoint. I also changed your <select> to make use of the custom-select class.
I'm not sure if this is what you're after, but if it's not, clarify what you're after a little more and I might be able to help.
If you're just wanting to group the items together, bootstrap has a card class that allows you to group elements into a container of sorts. The code below is wrapped in bootstraps grid system. I've put your code into a div tag with a card class. In a second example, I've removed a the inline form class, so you can see how the inputs are stacked vertically.
<div class="container mt-5">
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<div class="form-inline">
<div class="form-group mx-sm-3 mb-2">
<select class="form-control form-control-sm">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
<div class="form-group mx-sm-3 mb-2">
<input class="form-control" type="text">
</div>
<div class="form-group mx-sm-3 mb-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="card">
<div class="card-body">
<div class="form">
<div class="form-group mx-sm-3 mb-2">
<select class="form-control form-control-sm">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
<div class="form-group mx-sm-3 mb-2">
<input class="form-control" type="text">
</div>
<div class="form-group mx-sm-3 mb-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here's a codeply project so you can see how the layout.
I want to have a inline bootstrap 4 form occupying the full width (without spaces between the inputs and the button) with:
1 input type text and 1 button In extra small devices
2 input type text and 1 buttons In small devices
3 input type text and 1 buttons In medium and larger devices
But it is not working with the code below. I dont know if it is because the place where the form opens and close. Here is the example:
https://jsfiddle.net/o8jzq00f/1/
Html:
<div class="container-fluid bg-success">
<div class="row no-gutters justify-content-center" style="background-color: orange">
<div class="col-xs-12">
<h1 class="m-3">Title</h1>
</div>
</div>
<div class="row no-gutters justify-content-center">
<form>
<div class="col-xs-10 col-sm-4 col-md-3">
<label class="sr-only" for="inlineFormInput">Name</label>
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jane Doe">
</div>
<div class="col-sm-4 col-md-3 hidden-xs-up">
<label class="sr-only" for="inlineFormInput">Name</label>
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jon Doe">
</div>
<div class="col-sm-4 col-md-3 hidden-md-up">
<label class="sr-only" for="inlineFormInput">Name</label>
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jon Doe">
</div>
<div class="col-xs-2 col-sm-4 col-md-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
Use row class to bind your column then it will work
<div class="row">...under this you can use col classes and specify the width ...</div>
I have two input boxes that I am trying to get side by side on the row but I'd like there still to be a gap between the boxes but flush to the sides of the container.
Is there a way using just Bootstrap to do this? The container is a replication of a mobile device.
<div class="group col-sm-12">
<div class="row">
<div class="col-sm-6">
<div class="row">
<input type="text" name="first-name" ng-model="user.firstname" />
</div>
</div>
<div class="col-sm-6">
<div class="row">
<input type="text" name="last-name" ng-model="user.surname" />
</div>
</div>
</div>
</div>
plunkr example
Bootstrap has a few different grid classes. col-<size>-<num> where <size> can be xs, sm, md, or lg, and <num> can be an integer between (and including) 1-12.
For mobile devices, you'll want to use xs. If you don't specify any of the larger sizes, then they'll use the same widths as the smaller one. If you change col-sm-12 to col-xs-12 and col-sm-6 to col-xs-6 I think you'll get the result you're looking for.
It also helps your inputs look more consistent and more easily themed if you give them the form-control class.
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="group col-xs-12">
<div class="row">
<div class="col-xs-6">
<div class="row">
<input class="form-control" type="text" name="first-name" />
</div>
</div>
<div class="col-xs-6">
<div class="row">
<input class="form-control" type="text" name="last-name" />
</div>
</div>
</div>
</div>
I'm not familiar with Bootstrap, but one way to achieve it would be to add this to your CSS:
.col-sm-6, .col-sm-6 .row, .col-sm-6 .row input {
display: inline-block;
}
I am not sure if I understand your question correctly. You need a space between the text box side by side right? if so try this code. You could also use col-xs-offset-1 for space between grid. This will allow you to push 1 grid away. example http://www.bootply.com/U6vlrIktq2
<div class="col-md-4">
<input type="text" class="form-control">
</div>
<div class="col-md-4 ">
<input type="text" class="form-control"><br>
</div>
<!-- for more spacing between boxes-->
<div class="col-xs-5">
<input type="text" class="form-control">
</div>
<div class="col-xs-5 col-xs-offset-1">
<input type="text" class="form-control">
</div>
Assume we have two rows:
1 Row with col-md-12
1 Row with 2 divs, each of col-md-6
In the first row, I have Label/Textbox in a form-horizontal way. An example is shown below.
My question is, does the div with class form-group give me a row of width 12 columns? How to align content when I have rows including columns of different width? For instance, I need to align the sub button to be aligned with the Textbox, not the Label.
I am realizing that when I use a div.form-group, then I get the chance to have new 12 columns, even though the div.form-group is inside a div.col-md-6. Is this correct?
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row">
<div class="col-xs-11 col-md-6">
<div class="form-group">
<label for="txtFirstName" class="control-label col-md-3 col-xs-3">First Name</label>
<div class="col-md-7 col-xs-8">
<input type="text" class="form-control" id="txtFirstName">
</div>
</div>
</div>
<div class="col-xs-11 col-md-6">
<div class="form-group">
<label for="txtLastName" class="control-label col-md-3 col-xs-3">Last Name</label>
<div class="col-md-7 col-xs-8">
<input type="text" class="form-control" id="txtLastName">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-11 col-md-6">
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
you will have to use class 'row' to make it into col-6 div.
<div class="col-xs-11 col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3 col-xs-3">
<label for="txtFirstName" class="control-label">First Name</label>
</div>
<div class="col-md-7 col-xs-8">
<input type="text" class="form-control" id="txtFirstName">
</div>
</div>
</div>
</div>
Check http://getbootstrap.com/css/ , Nesting columns section