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>
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>
I am trying to use bootstrap 4, I have a simple div contains a text box. I want the text box to take the div width. I thought in Bootstrap the input, by default, take the full width?
What is really bugging me is that the code ran correctly here in the snippet??
Here is the sample code:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md" style="background-color: blue;">
<!-- this is the left side -->
<input type="text" class="form-control" placeholder="Email address">
</div>
<div class="col-md" style="background-color: red;">
<!-- this is the right side -->
</div>
</div>
</div>
The above code is exactly what I have. I am not sure this is the right way to do this?
I don't know if this can help, I am using this code inside a view (MVC project).
So the this is how it looks inside visual studio:
Layout:
<div class="container">
<div class="row">
<div class="col-md">
#RenderBody()
</div>
<div class="col-md d-none d-md-block">
<!------>
</div>
</div>
<footer>
<p>© #DateTime.Now.Year - My Project</p>
</footer>
</div>
And this is the view:
<input type="text" class="form-control" placeholder="Email address">
This is how it looks when I render the view (there are other CSS related to background color, etc.. that I didn't add here)
Columns have padding of 15px on both sides. To remove the padding you can...
Use p-0 for padding:0 on the column with input:
<div class="container">
<div class="row">
<div class="col-md p-0" style="background-color: blue;">
<!-- this is the left side -->
<input type="text" class="form-control" placeholder="Email address">
</div>
<div class="col-md" style="background-color: red;">
<!-- this is the right side -->
</div>
</div>
</div>
Or, you can use no-gutters to remove padding from all cols in the row. This will also remove the negative margins from the row which will effect alignment with the sides of the viewport on smaller screens...
<div class="container">
<div class="row no-gutters">
<div class="col-md" style="background-color: blue;">
<!-- this is the left side -->
<input type="text" class="form-control" placeholder="Email address">
</div>
<div class="col-md" style="background-color: red;">
<!-- this is the right side -->
</div>
</div>
</div>
Demo: https://www.codeply.com/go/d4AOm39YD3
I'm making a simple form with this code:
<div class="container">
<div class="jumbotron" style="width:100%">
<h1>
ConfigTool Web Interface
</h1>
<p>
Edit the config variables here and click save.
</p>
</div>
<div class="form-group row">
<label class="col-2">Name:</label>
<input class="form-control col-10" type="text" />
</div>
</div>
It looks like this:
You can see that the input does not align with the jumbotron, and that is because the input doesn't stop at the padding:
How do I fix this?
Here you go with the solution
<div class="container">
<div class="jumbotron" style="width:100%">
<h1>
ConfigTool Web Interface
</h1>
<p>
Edit the config variables here and click save.
</p>
</div>
<div class="form-group row">
<div class="col-2">
<label>Name:</label>
</div>
<div class="col-10">
<input class="form-control" type="text" />
</div>
</div>
</div>
You should use col-* inside a div tag
Column classes should be given to the elements surrounding the input controls (and labels). The Bootstrap grid system works best as follows:
div.container > div.row > div.col-* > content
<div class="container">
<div class="jumbotron" style="width:100%">
<h1>
ConfigTool Web Interface
</h1>
<p>
Edit the config variables here and click save.
</p>
</div>
<div class="form-group row">
<div class="col-2">
<label>Name:</label>
</div>
<div class="col-10">
<input class="form-control" type="text" />
</div>
</div>
</div>
You have added Bootstrap's predefined grid classes in input element. So, Grid classes padding apply in input element. You will need to create grid classes with separate div element. then put input element inside this div element.
<div class="container">
<div class="jumbotron" style="width:100%">
<h1>
ConfigTool Web Interface
</h1>
<p>
Edit the config variables here and click save.
</p>
</div>
<div class="form-group row">
<label class="col-2">Name:</label>
<div class="col-10">
<input class="form-control" type="text" />
</div>
</div>
</div>
also, Please check this official bootstrap Horizontal Form
You are missing the parent element for the form-group. Try this -
<div class="form-horizontal" >
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
</div>
</div>
You need to remove the "row" class from the form-group. the row class basically remove the padding from the div element.
<div class="form-group">
<label class="col-2">Name:</label>
<input class="form-control col-10" type="text" />
</div>
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>
Please note that I am a developer, not a designer.
I need to separate card div for two columns in desktop mode. I mean "This should be in Left Side" should be display on left side and "This should be on right side" should be display on right side.
I use following HTML.
<div class="card">
<div class="card-header">
Featured
</div>
<div class="card-block">
<div class="col-md-4">
This should be in Left Side
</div>
<div class="col-md-8">
This should be on right side
</div>
</div>
</div>
If you want to test online here is the jsfiddle (https://jsfiddle.net/uxfjwhpc/1/).
What is my mistake and how to correct it?
The classes col-* works when they are wrapped under row class. You can find the updated code below for card-block div. Hope this helps.
<div class="card-block">
<div class="row">
<div class="col-md-4">
This should be in Left Side
</div>
<div class="col-md-8">
This should be on right side
</div>
</div>
</div>
<div class="row card-block">
<div class="col-md-4">
This should be in Left Side
</div>
<div class="col-md-8">
This should be on right side
</div>
</div>
This will work for you.
I have the same issue with adding Form inside Card in Bootstrap. Here is my implementation.
From the original bootstrap standard form implementation:
<form action="/action_page.php">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
</form>
I need to adjust it to this to work:
<form action="/action_page.php">
<div class="row">
<label for="email" class="col-md-2">Email:</label>
<input type="email" class="form-control col-md-10" id="email" placeholder="Enter email" name="email">
</div>
</form>
I need to change form-group class to row class to make sure form-horizontal class should work fine inside the card of bootstrap.