I am trying to use the adaptive placeholder CSS files on my page - it works perfectly for text and select inputs but when I try and use it with bootstraps input-group, it just doesn't work.
I've created a bootply to show what I mean bootply (the middle one is what I want it to look like)
This is the input-group that doesn't take the adaptive placeholder
<div class="row">
<div class="col-sm-6">
<div id="divSupplierInput2" class="input-group">
<input class="form-control" type="text" id="Text2" name="txtSupplier" value="" runat="server"
required="">
<label for="txtSupplier" placeholder="Supplier">
</label>
<span class="input-group-btn">
<button class="btn btn-secondary btn-sm" type="button">
...</button>
</span>
</div>
</div>
</div>
and this is an input where it does work
<div class="row">
<div class="col-sm-6">
<input id="Text1" type="text" class="form-control input-sm" runat="server" required="">
<label for="txtInvoiceNumber" placeholder="Invoice Number">
</label>
</div>
any help would be greatly appreciated, cheers
Use two divs, col-sm-5 adjust-span-left and col-sm-1 adjust-span-right.
You can also use col-sm-6 to col-sm-11 depending how long you want it to be.
Note I added adjust-span-left and adjust-span-right to the divs respectively, now use CSS to adjust it accordingly:
.adjust-span-right{
margin-left: -40px;
}
/* To make it responsive to smaller screens add this */
#media screen and (max-width: 780px) {
.adjust-span-left{
float:left;
width:90%;
overflow:hidden;
}
.adjust-span-right{
float:left;
width:10%;
overflow:hidden;
}
}
Then use this input
<div class="row">
<div class="col-sm-5 adjust-span-left">
<input id="txtInvoiceNumber" type="text" class="form-control input-sm" runat="server" required="">
<label for="txtInvoiceNumber" placeholder="Invoice Number">
</label>
</div>
<div class="col-sm-1 adjust-span-right">
<span class="input-group-btn">
<button class="btn btn-secondary btn-sm" type="button">
...
</button>
</span>
</div>
</div>
EDIT
I noticed the placeholder doesn't show on the smaller screen on focus, so you should also adjust the css for that in the responsive css style.
Something like:
#media screen and (max-width: 780px) {
input[type="text"][required]:focus + label[placeholder]:before,
input[type="text"][required]:valid + label[placeholder]:before {
/* Adjust the css accordingly */
-webkit-transform: translate(6px, -10px);
-ms-transform: translate(6px, -10px);
transform: translate(8px, -10px);
}
}
Related
I am trying to align a checkbox with a text input. I would like the text box to be a form control, so that it right aligns with the other inputs on the page. However, if I do this, it becomes a block element and there is a line break after the checkbox. If I don't use the form-control class, the input box isn't wide enough and it doesn't look right compared to the rest of the form. If I use the grid layout, there is too much space in between the checkbox and the text box.
The image below represents the following code:
<div>
<input type="checkbox" />
<input type="text" placeholder="Enter your own vendor name here ..." class="form-control" />
</div>
Simple class like form-inline and form-group would help you on this.
<div class="form-inline">
<div class="form-group">
<input type="checkbox"/>
<input type="text" placeholder="Enter your own vendor name here ..." class="form-control" />
</div>
</div>
Fiddle: http://jsfiddle.net/2yao3x5r/
However, from bootstrap documentation
This only applies to forms within viewports that are at least 768px
wide
Besides, I have a suggestion if your checkbox belongs to your input to use input-group
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox" aria-label="...">
</span>
<input type="text" class="form-control" aria-label="...">
</div>
If you have a smaller than 768px viewport, I suggest to use .row and .col modifier. e.g.
<div class="row">
<div class="col-xs-2 col-sm-2">
<input type="checkbox"/>
</div>
<div class="col-xs-10 col-sm-10">
<input type="text" placeholder="Enter your own vendor name here ..." class="form-control" />
</div>
</div>
You could use the Input-Group Add-on component for checkboxes/radios. And you can always style the input-group box if it doesn't work for your specific form setup.
See example Snippet.
body {
padding-top: 50px;
}
.input-group-addon.my-addon {
background: white;
padding-top: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="well">Default</div>
<div class="container">
<div class="input-group"> <span class="input-group-addon">
<input type="checkbox" aria-label="...">
</span>
<input type="text" class="form-control" aria-label="...">
</div>
</div>
<hr>
<div class="well">Added Styling</div>
<div class="container">
<div class="input-group"> <span class="input-group-addon my-addon">
<input type="checkbox" aria-label="...">
</span>
<input type="text" class="form-control" aria-label="...">
</div>
</div>
You can use form-inline or form-horizontal
Inline-form
http://getbootstrap.com/css/#forms-inline
Horizontal-form
http://getbootstrap.com/css/#forms-horizontal
or
You have to add "display:inline-block" to your input controls
You could use input-group-addon and style the checkbox as a label for the input.
For more precise control, but less clean, you can add some CSS to the controls themselves:
#inputText {
margin-left: 20px;
}
#inputCheckbox {
position: absolute;
top: 0px;
margin-top: 0px;
}
HTML (with grid system):
<div class="col-md-2">XX</div>
<div class="col-md-8">
<input type="text" placeholder="Enter your own vendor name here ..."
class="form-control" id="inputText" />
<input type="checkbox" class="pull-left" id="inputCheckbox" />
</div>
<div class="col-md-2">XX</div>
http://codepen.io/anon/pen/WQQpyg
On a larger screen this isn't a problem, but when I reduce the browser window, the submit button moves underneath the text field.
This is causing a problem when I try to add a background color to the form with css. Does anyone know how to prevent this?
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div>
<form class="form-inline" role="form">
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</body>
Is this what you are looking for? https://jsfiddle.net/DIRTY_SMITH/2zkwxm97/
Added col-xs-4 to <div class="form-group col-xs-4">
You could use a horizontal form with column sizing.
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
.less-padding {
padding: 0 2px;
}
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4">
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-xs-6 less-padding">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<div class="col-xs-6 less-padding">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
Another solution was mentioned.
Here is how it goes:
#import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
#media (max-width: 768px) {
.form-group {
display: inline-block;
vertical-align: top;
}
}
<form class="form-inline" role="form">
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
class .form-inline only applies to forms within viewports that are at least 768px wide.
Check Bootstrap Doc here
To achieve what you want, you shouldn't use it. You could do something like this:
<div>
<form>
<div class="col-xs-6">
<input type="email" class="form-control" id="email" placeholder="Enter Email Address">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
Check this demo
Looks like it uses a media query like this:
#media (min-width: 768px)
And anything narrower than that, the form-group will change to display:block instead of inline-block. So maybe override that back to inline-block, but not sure that is best way to solve your issue. Maybe let it stack like that and find another way to fix the background color issue.
I am attempting to create an inline form within a small container (.col-sm-4). Using a default inline form at this size automatically wraps into multiple lines, which I would like to avoid. The look I am aiming for is here:
At this point I have gotten the inputs to throw out their min-width and instead adhere to their bounding columns, but I cannot get the button in the spot I want it (and autosizing with the overarching container).
JSFiddle Here
HTML:
<div class="col-xs-4 well">
<div class="col-xs-7 form-col" id="input-dynamic">
<input type="text"></input>
</div>
<div class="col-xs-4 form-col" id="input-dynamic">
<div class="input-group-addon">$</div>
<input type="number"></input>
</div>
<div class="col-xs-1 form-col" id="input-dynamic">
<button class="btn btn-danger">-</button>
</div>
</div>
CSS:
#input-dynamic input[type=text] {
width: 100%;
box-sizing: border-box;
height: 28px;
}
#input-dynamic input[type=number] {
width: 100%;
box-sizing: border-box;
height: 28px;
}
#input-dynamic button {
width: 100%;
box-sizing: border-box;
height: 28px;
}
.form-col {
padding-right: 2px;
padding-left: 2px;
}
Kfriede, Hi there. You said you want to avoid the form items from stacking.
Here is a Fiddle that will do that for the form.
But just because of the still having it to be used properly on a very small screen.
I added a media breakpoint at 320px to drop the button down below and expand the two inputs to take up 50% width each.
Hope this can help you get started here with this form.
<form class="row-fluid">
<input type="text" class="input-style col-xxs-6 col-xs-4 " id="exampleInputName2" placeholder="Name">
<label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
<div class="col-xxs-6 col-xs-5 input-block">
<div class="input-addon input-height col-xs-2">$</div>
<input type="text" class="input-style col-xs-8" id="exampleInputAmount" placeholder="Amount">
</div>
<div class=" col-xxs-12 col-xs-3">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>
I forked your JSFiddle.
I Implemented the inline-form techniques discussed here.
And built some of the elements using this Bootstrap form builder. If you google Bootstrap form builder you will see many similar ones.
I also noticed you didn't add all the external resources to the JSFiddle so I did that as well.
If you have a really really small screen it gets scrunched but you could use a media query as discussed HERE to change the layout for a small width.
<div class="container-fluid">
<div class="row">
<div class="col-xs-4">
<form class="form-inline">
<div class="form-group">
<div class="row">
<div class="col-xs-6">
<input id="textinput" name="textinput" type="text" class="form-control input-md"></div>
<div class="col-xs-6"><div class="input-group"> <span class="input-group-addon">$</span>
<input id="prependedtext" name="prependedtext" class="form-control" placeholder="Amount" type="text"> <span class="input-group-btn">
<button class="btn btn-danger" type="button">-</button>
</span>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
I have a very simple form with Bootstrap 3 which I can easily (automatically) align when I don't use input-group-addons.
After I use them in my form it is impossible to align it (the line with addons is wider because of added addons)
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="product_name" class="col-sm-2 control-label">Product name</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="product_name" placeholder="Product name">
</div>
</div>
<div class="form-group">
<label for="product_price" class="col-sm-2 control-label">Price</label>
<div class="col-sm-4 input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">
<span class="input-group-addon">.00</span>
</div>
</div>
<div class="form-group">
<label for="product_description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-6">
<textarea class="form-control" id="product_description" placeholder="Description" rows="5"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
JsFiddle: http://jsfiddle.net/Yzxy3/
Bootstrap documentation for input groups says :
Don't mix input-group with other components. (see:http://getbootstrap.com/components/#input-groups)
Do not mix form groups or grid column classes directly with input groups. Instead, nest the input group inside of the form group or grid-related element."
So you can't mix "col-sm-4" with "input-group" in the same class. You have to create 2 div class, the first with "col-sm-4" and the other with "input-group"
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">
<span class="input-group-addon">.00</span>
</div>
</div>
Updated Fiddle
It's because .input-group has default
padding-right: 0;
padding-left: 0;
so your div will stretch to the full width, where as .col-sm-4 has default styles as:
padding-right: 15px;
padding-left: 15px;
So to make it work as expected, you can add this style:
.input-group[class*="col-"] {
padding-right: 15px;
padding-left: 15px;
}
Updated Fiddle
I find that I needed to include: float: left as well. So, the css is:
.input-group[class*="col-"] {
float: left;
padding-right: 15px;
padding-left: 15px;
}
If not, my multi-column rows broke when I upgraded from v3.0.2 to v3.0.3.
--cp
.input-group[class*="col-"] is not useful if you use
<fieldset>
Here is solution!
.makeHorizontal{
float:left;
padding-left:20px;
}
I'm working in Bootstrap 3.0 trying to make a Google-style search box that has a "Search Help" link after the Submit button.
My problem: when I go responsive I lose my offset margins and the button wraps to the next line.
<div class="row search">
<div class="col-md-8 col-md-offset-2">
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<button type="submit" id="s" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
Search Help
</form>
</div>
</div>
C.f.: http://jsfiddle.net/redo1134/su3eq/2/
Everything's fine at >991px. But at 991 and below I lose the offset.
This is certainly related to the #media (min-width: 992px) media query in bootstrap.css, but I don't know how to keep the offset.
And to make matters worse: when the viewport is <768px the button and the link wrap to the next line.
Again, I'm drawn to bootstrap.css and the min-width: 768px media query, but I don't know how to keep the input, button, and text all together.
Thanks!
<div class="row search">
<div class="col-sm-8 col-sm-offset-2">
<form role="form">
<div class="input-group">
<input type="text" class="form-control input-sm">
<span class="input-group-btn">
<button class="btn btn-default btn-sm" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
Search Help
</div>
</form>
</div>
</div>
So, using Bootstrap will automatically make the spans break to show full widths at a certain breakpoint... it does that for responsiveness! I usually have to create my own styles when i would like something to act as I want it. Which is totally ok!
So, using inline styles just for a quick example, (you can turn them into proper styles for your stylesheet) you can do something like this with your search area... also updated the jsfiddle here
<!-- Global Search -->
<div class="row search">
<div class="col-md-8 col-md-offset-2">
<form class="form-inline" role="form">
<div class="form-group">
<div style="width:75%; float: left;">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<div style="width: 25%; float: left; padding-left: 10px; box-sizing: border-box;">
<button type="submit" id="s" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
Search Help
</div>
<div class="clearfix"></div>
</div>
</form>
</div>
</div>
DEMO:http://jsbin.com/IKaKosoX/1/
EDIT: http://jsbin.com/IKaKosoX/1/edit?html,css,output
Remove the row col wrapping the form-inline and replace with this html:
<!-- Global Search -->
<form class="form-inline global-search" role="form">
<div class="form-group">
<label class="sr-only" for="">Enter search terms</label>
<input type="search" class="form-control" id="k" name="k" placeholder="Enter search terms">
<input id="cn" name="cn" type="hidden" value="false" />
</div>
<button type="submit" id="s" class="btn btn-default"><span class="glyphicon glyphicon-search"></span>
</button> Search Help
</form>
Remove previous custom css regarding the form and replace with:
/* center search */
.global-search {
text-align:center;
padding:10px;
}
.global-search * {
display:inline-block;
margin-bottom:0;
}
.global-search .form-control {
width:120px;
}
.global-search a {
display:block;
padding-top:10px;
}
#media (min-width:400px){
.global-search {
padding: 20px 0;
text-align:center;
}
.global-search .form-control {
width:300px;
}
}