Bootstrap 3 inline layout not working - html

I'm using the following markup with Bootstrap 3.
<div class="row" style="margin-bottom: 12px">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
According to all the examples I could find, this should put everything inline. However, for me, the labels appear over the textboxes rather than to the side of them.
I tried not enclosing the markup with <div class="row">. I also tried using <input type="text"> instead of <input type="date"> but none of that made any difference. I've triple checked the markup. Can anyone see what I'm doing wrong?
If I force the containers to be wider, then it appears closer to what I expect. But none of the examples I've seen do this. And I'd prefer to not specify a fixed width.

This is due to the version of Bootstrap 3 that you are using. The form-control class changed to width: auto within inline forms in v3.1.0. So versions v3.0.0, v3.0.1, v3.0.2 and v3.0.3 should all display the problem you are seeing. After the v3.1.0 release it should no longer be a problem.
From the release notes:
#11836: Along with the form validation update, we reset some key form and icon styles:
All .form-controls within inline forms are set to width: auto; to prevent stacking of .form-label within a .form-group.
Removes all select.form-control settings since those are now inherited by the above change
Removes the width: 1em; from the Glyphicons because it was virtually impossible to override.
Any version between 3.1.0 and the current 3.3.6 should work as you expect.
That being said, if you cannot upgrade you can still implement this on your own. See 3rd Snippet.
Example of the issue with v3.0.0
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
Example of expected behavior with v3.1.0
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
Example using v3.0.0 with fix:
#media (min-width: 768px) {
.form-inline .form-control {
width: auto;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>
<div class="form-group">
<label for="endDate">End Date:</label>
<input type="date" class="form-control" id="endDate" value="11/2/1972" placeholder="End Date">
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
All current form-inline css just in case:
#media (min-width: 768px) {
.form-inline .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle
}
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle
}
.form-inline .form-control-static {
display: inline-block
}
.form-inline .input-group {
display: inline-table;
vertical-align: middle
}
.form-inline .input-group .form-control,
.form-inline .input-group .input-group-addon,
.form-inline .input-group .input-group-btn {
width: auto
}
.form-inline .input-group>.form-control {
width: 100%
}
.form-inline .control-label {
margin-bottom: 0;
vertical-align: middle
}
.form-inline .checkbox,
.form-inline .radio {
display: inline-block;
margin-top: 0;
margin-bottom: 0;
vertical-align: middle
}
.form-inline .checkbox label,
.form-inline .radio label {
padding-left: 0
}
.form-inline .checkbox input[type=checkbox],
.form-inline .radio input[type=radio] {
position: relative;
margin-left: 0
}
.form-inline .has-feedback .form-control-feedback {
top: 0
}
}

your code is fine ,, but note that
Controls only appear inline in viewports that are at least 768px wide to account for narrow viewports on mobile devices.
here is my screenshot for your code

I've run into this issue in the past when I was using mvc to add my textboxes. I solved this issue by overriding the form-group class or by using an inline style on the div to set display: flex; This would force it into one line.
<div class="form-group" style="display:flex;">
<label for="startDate">Start Date:</label>
<input type="date" class="form-control" id="startDate" value="10/29/1961" placeholder="Start Date">
</div>

Related

Button is not aligning in center in bootstrap form

I have made bootstrap contact from in which I want to align all its element in center.
Below is my code:
.third-section > form > input{
width: 35%;
margin: auto;
margin-top: 25px;
}
.third-section > form > textarea{
width: 35%;
margin:auto;
margin-top: 20px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<section class="third-section">
<form>
<input type="text" class="form-control" placeholder="Name" required/>
<input type="email" class="form-control" placeholder="Email" required/>
<textarea id="message" rows="4" class="form-control" placeholder="Message" required></textarea>
<input type="submit" class="btn btn-primary" value="SUBMIT"/>
</form>
</section>
SCREENSHOT
As seen in screenshot button is not aligned in center.Someone please let me know how can I get desired layout. Any help would be appreciated.
THANKS
Add the following CSS
.third-section > form {
text-align: center;
}
if you could provide a working jsfiddle with all of your code in it, that would help. However, from what I can see, your issue can be solved by putting all of your form inside of a container with the text-center class.
<div class="container text-center">
...
</div>
Add bootstrap class 'text-center'. please refer the below code.
<section class="third-section text-center">
<form>
<input type="text" class="form-control" placeholder="Name" required/>
<input type="email" class="form-control" placeholder="Email" required/>
<textarea id="message" rows="4" class="form-control" placeholder="Message" required></textarea>
<input type="submit" class="btn btn-primary" value="SUBMIT"/>
</form></section>
Your button is not aligned because the your button is actually an input. All the elements are centered because they have margin: auto (so the remaining space is split evenly between the two margins). But the input elements (and the elements with class btn from bootstrap) are inline-block, and margin left and right properties are not working on inline and inline-block elements.
One option is the one that metaDesign sugested. Another option is to explicitly set the display property of the button to display: block.
so something like:
input.btn {
display:block;
}

CSS- Changing the width of a search box

I'd been trying to change the width of the search box in name="size" of my HTML template but can't do it even when I tried width:.
html:
<form class="form" method = "POST" >
<h1>Soccer Shoes Finder</h1>
<div class="line-separator"></div>
<div class="container-fluid form-inline">
<input class="form-control" name = "name" type="text" placeholder="Name"/>
<input class="form-control" name = "size" type="text" placeholder="Size"/>
<button class="form-control fa fa-search" aria-hidden="true"></button>
</div>
</form>
css of the element:
input[name="size"]{
width: 50%;
}
Here's a codepen for better context:
http://codepen.io/tadm123/pen/ZLVWpd
I recommend using this method.
<form class="form" method="POST">
<h1 class="text-center">Soccer Shoes Finder</h1>
<div class="line-separator"></div>
<div class="container ">
<div class="row">
<div class="col-md-4">
<input class="form-control" name="name" type="text" placeholder="Name" />
</div>
<div class="col-md-7">
<input class="form-control" name="size" type="text" placeholder="Size" /></div>
<div class="col-md-1">
<button class="form-control " aria-hidden="true"><i class="fa fa-search"></i></button></div>
</div>
</div>
</form>
Updated Codepen:
http://codepen.io/hunzaboy/pen/aJJpMK
It's getting overwritten by the bootstrap defaults. Specifically:
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle;
}
You need to adjust your selector to fix the cascade:
.form-inline input.form-control[name="size"]{
width: 50%;
}
did you try size attribute?
<input type="text" size="15"/>
The input elements use by default display: inline;, you cannot define a width in elements who using that display, if your change the display to display: inline-block; you will can change the width of your element.
input[name="size"]{
width: 50%;
display: inline-block; /* <--- Here the change */
}
Suppose you have a class-name (defined in HTML) of inputText (name).
Adding these lines will help (clean-way/simple).
.inputText{
//...
width:200px;
transition: width .4s ease-in;
}
.inputText:hover, .inputText:focus{
width:400px;
}

How to create a placeholder that starts from the top of the input box?

I am trying to create a message input box in a bootstrap form, however the box has to be of sufficient height so the user could read his message, the place holder of "message" would stay in the middle, also when I write the text it keeps going horizontally without considering margins, I am a newbie programmer so please don't be too harsh.
.theform {
margin-left: 200px;
margin-right: 200px;
margin-top: 50px;
border: 5px solid;
padding: 20px 20px 20px 20px;
}
.theform h1 {
font-size: 50px;
text-decoration: underline;
}
#formGroupExampleInput {
height: 50px;
}
.form-control {
font-size: 30px;
}
#messagebox {
height: 200px;
margin-right: 40px;
line-height: 0px;
}
#message {
height: 200px;
margin-right: 40px;
line-height: -20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="theform" id="link3">
<h1 class="text-center">Contact</h1>
<form>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="messagebox" placeholder="Message" size="50">
</div>
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
You have to use a textarea instead of an input. If you want to center the placeholder vertically, you also have to use some JS, just to adjust the textare.
Just look into this codepen for an example implementation of a vertical centered textarea:
https://codepen.io/desandro/pen/gICqd
NO JS REQUIRED
you can fix this issue by puting the text area :
<textarea name="" id="" cols="30" rows="10"></textarea>
by default in text area the placeholder is sent to the top left.
Don't make the mistake of puting input instead because when you will give it a huge height the placeholder will be sent to the middle left !!!

How to add a text after input text

I want to add "month" after the input in bootstrap, in the side of it.
I've tried span, pull-left nothing worked. Months is always below
<form role="form">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
</div>
</form>
JSFIDDLE
Just add form-inline to your form..
<form role="form" class="form-inline">
<div class="form-group">
<label for="exampleInputEmail1">Months</label>
<input type="email" class="form-control" style="width: 50%" id="exampleInputEmail1" placeholder="Months"> months
</div>
</form>
Demo: http://www.bootply.com/119625
Try wrapping the elements and specifying the column widths:
HTML
<form role="form">
<div class="form-group">
<div class="pull-left col-xs-9">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<span class="col-xs-3">months<span>
</div>
</form>
CSS
span{
margin-top: 25px;
}
JS Fiddle: http://jsfiddle.net/7rYp7/2/
putting style="display:inline" into the actual input element in question has worked for me.
Listen, I know we are supposed to avoid using style and only use classes defined in CSS but I tried all the example above and this is the only thing that worked.
You can set the following in your CSS (overwriting the bootstrap.css)
.form-group input {
display:inline;
width: 50%;
margin: 5px;
}
You can also use a different selector to be more specific (instead of overwriting it for all inputs) UPDATED:
#exampleInputEmail1{
display:inline;
width: 50%;
margin: 5px;
}
.form-group label {
display: block;
}

Why won't my two column form line up correctly?

I'm learning some css and want to make a two column form, without any table tags and such.
This is what i have got (code from CSS Cookbook 3ed edition).
JSfiddle HERE...
HTML code:
<div class="container">
<form id="regform" name="regform" method="post" action="/regform.php">
<div id="register">
<h4>Register</h4>
<label for="fmlogin">Login</label>
<input type="text" name="fmlogin" id="fmlogin" />
<label for="fmemail">Email Address</label>
<input type="text" name="fmemail" id="fmemail" />
<label for="fmemail2">Confirm Address</label>
<input type="text" name="fmemail2" id="fmemail2" />
<label for="fmpswd">Password</label>
<input type="password" name="fmpswd" id="fmpswd" />
<label for="fmpswd2">Confirm Password</label>
<input type="password" name="fmpswd2" id="fmpswd2" />
</div>
<div id="contactinfo">
<h4>Contact Information</h4>
<label for="fmfname">First Name</label>
<input type="text" name="fmfname" id="fmfname" />
<label for="fmlname">Last Name</label>
<input type="text" name="fmlname" id="fmlname" />
<label for="fmaddy1">Address 1</label>
<input type="text" name="fmaddy1" id="fmaddy1" />
<label for="fmaddy2">Address 2</label>
<input type="text" name="fmaddy2" id="fmaddy2" />
<label for="fmcity">City</label>
<input type="text" name="fmcity" id="fmcity" />
<label for="fmstate">State or Province</label>
<input type="text" name="fmstate" id="fmstate" />
<label for="fmzip">Zip</label>
<input type="text" name="fmzip" id="fmzip" size="5" />
<label for="fmcountry">Country</label>
<input type="text" name="fmcountry" id="fmcountry" />
<input type="submit" name="submit" value="send" class="submit" />
</div>
</form>
</div>
CSS code:
label {
margin-top: .33em;
display: block;
}
input {
display: block;
width: 250px;
}
#register {
float: left;
}
#contactinfo {
padding-left: 275px;
}
Because you float one div and not the other.
With a few simple CSS changes it'll work (as long as the h4 does not span multiple lines):
#register {
float: left;
width: 275px;
}
#contactinfo {
float: left;
}
See the updated fiddle.
Here's how I'd debug (except I'd use Firebug or another Inspect/devtools): http://jsfiddle.net/PhilippeVay/yuxTA/2/
As stated by #Arjan in his answer, this is due to floating and its effects.
Uncomment the last CSS declaration for a solution that won't modify layout. Also add margin-top to both columns or padding-top if you want a vertical margin back...
Another option is to remove the margins from the h4 (although, as said in other answers, floating [or similar] both columns makes more sense).
h4 {margin: 0;}
You have to float all the div in your containter
#register {
float: left;
}
#contactinfo {
float:left;
margin-left:30px; /*increase or decrease if you like*/
}