Bootstrap Form-Group Inside Form-Inline - css

I m a newbie in Bootstrap and I have encounter a problem as I wan to display a select box in block style and another form group beside.
Here is my code
<div class="form-inline>
<div class="form-group">
<label for="EventType">Event Type</label>
<select class="form-control">
<option value="0">0</option>
<option value="1">1</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
</div>
</div>
Current Output is
My desire output is display both form group class div in inline method. But currently output show everything in inline while not div only. Is there any method to do so?

If possible write the HTML as follow-
<form class="form" role="form">
<div class="form-inline>
<div class="form-group">
<label for="EventType">Event Type</label>
<select class="form-control">
<option value="0">0</option>
<option value="1">1</option>
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
</div>
</form>
Again you can do this with the HTML you have provided. In this case, you have to write some custom CSS as follow-
.form-group{
display:block;
clear:both;
width:100%;
}

Related

Overlapping form select when window is small

I have the following selection boxes that are working with select2 js:
<!-- Selections for the table -->
<div class="form-group row">
<div class="col-xs-2">
<label for="month" class="control-label">Year</label>
<select class="form-control select2" id="year" name="year" data-placeholder="Select a year">
<option value="2015">
xxx
</option>
...
</select>
</div>
<div class="col-xs-2">
<label for="manager" class="control-label">Manager</label>
<select class="form-control select2" id="manager" name="manager" data-placeholder="Select a manager" multiple="multiple">
<option value="2">
xxx
</option>
...
</select>
</div>
<div class="col-xs-2">
<label for="user" class="control-label">User</label>
<select class="form-control select2" id="user" name="user" data-placeholder="Select a user" multiple="multiple">
<option value="87">
xxx
</option>
...
</select>
</div>
</div>
I am using bootstrap 3 and it is strange, when I get a smaller window, the boxes overlap :(. You can see this in the image below.
How can I have bootstrap to make the different select get below each other when there is not enough space and in a line if there is enough space horizontally?
Use below CSS:
.select2{width:100%}
if this not working then you can use:
.select2{width:100% !important}

Proper way to set two input fields side by side in Bootstrap 3 form?

I have form with many input fields. To save users from scrolling on the medium and large screens I would like to place some of the input fields side by side. Not all the fields have to be side by side and that's why I'm not using inline form. Here is example of what I have:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<form name="frmDemo" id="frmDemo">
<div class="form-group required">
<label class="control-label" for="last"><span class="label label-primary">Last Name:</span></label>
<input type="text" class="form-control" name="frmDemo_last" id="frmDemo_last" placeholder="Enter Last Name" maxlength="50" required>
</div>
<div class="form-group required">
<label class="control-label" for="first"><span class="label label-primary">First Name:</span></label>
<input type="text" class="form-control" name="frmDemo_first" id="frmDemo_first" placeholder="Enter First Name" maxlength="50" required>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<label class="control-label" for="plan"><span class="label label-primary">Plan:</span></label>
<select class="form-control" name="frmDemo_plan" id="frmDemo_plan">
<option value="">--Choose Plan--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<label class="control-label" for="plantext"><span class="label label-primary">Plan Text:</span></label>
<input type="text" class="form-control" name="frmDemo_plantext" id="frmDemo_plantext" placeholder="Enter Plan Text" maxlength="50">
</div>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 col-sm-6 col-md-6 col-lg-6">
<label class="control-label" for="gender"><span class="label label-primary">Gender:</span></label>
<select class="form-control" name="frmDemo_gender" id="frmDemo_gender" required>
<option value="">--Choose Gender--</option>
<option value="F">Female</option>
<option value="M">Male</option>
</select>
</div>
<div class="form-group col-xs-12 col-sm-6 col-md-6 col-lg-6">
<label class="control-label" for="gender"><span class="label label-primary">Grade:</span></label>
<select class="form-control" name="frmDemo_grade" id="frmDemo_grade" required>
<option value="">--Choose Grade--</option>
<option value="PK">PK</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12">
<button type="submit" name="frmDemo_submit" id="frmDemo_submit" class="btn btn-primary">Submit</button>
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div id="frmDemo_message" class="alert message-submit"></div>
</div>
</div>
</form>
As you can see I was able to achieve that and place the fields side by side. My question is what is the proper way to do that? My first set of fields for the Plan input use form-group div then row div and then col- div. The second set of input fields for Grade and Gender use row div and then form-group col-. Both ways work but which one is valid according to Bootstrap rules? If anyone can explain or give me suggestions I would appreciate that. Thank you.
That's alright. But if you want some other ways without using Bootstrap rows and columns you can target specific .form-group to style in your CSS. Personally I do these since it is much more cleaner than having many nested rows and columns. I would only use rows and columns for other purposes.
HTML:
<div class="form-group required">
<label class="control-label" for="last"><span class="label label-primary">Last Name:</span></label>
<input type="text" class="form-control" name="frmDemo_last" id="frmDemo_last" placeholder="Enter Last Name" maxlength="50" required>
</div>
<div class="form-group required">
<label class="control-label" for="first"><span class="label label-primary">First Name:</span></label>
<input type="text" class="form-control" name="frmDemo_first" id="frmDemo_first" placeholder="Enter First Name" maxlength="50" required>
</div>
<div class="form-group">
<label class="control-label" for="plan"><span class="label label-primary">Plan:</span></label>
<select class="form-control" name="frmDemo_plan" id="frmDemo_plan">
<option value="">--Choose Plan--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="form-group">
<label class="control-label" for="plantext"><span class="label label-primary">Plan Text:</span></label>
<input type="text" class="form-control" name="frmDemo_plantext" id="frmDemo_plantext" placeholder="Enter Plan Text" maxlength="50">
</div>
<div class="form-group">
<label class="control-label" for="gender"><span class="label label-primary">Gender:</span></label>
<select class="form-control" name="frmDemo_gender" id="frmDemo_gender" required>
<option value="">--Choose Gender--</option>
<option value="F">Female</option>
<option value="M">Male</option>
</select>
</div>
<div class="form-group">
<label class="control-label" for="gender"><span class="label label-primary">Grade:</span></label>
<select class="form-control" name="frmDemo_grade" id="frmDemo_grade" required>
<option value="">--Choose Grade--</option>
<option value="PK">PK</option>
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
</select>
</div>
<div class="form-group">
<button type="submit" name="frmDemo_submit" id="frmDemo_submit" class="btn btn-primary">Submit</button>
</div>
<div class="form-group">
<div id="frmDemo_message" class="alert message-submit"></div>
</div>
CSS:
/* I used nth-child(n+number) pseudoclass selector since you wanted to start from the 3rd div with .form-group class to be side by side with each other. */
.form-group:nth-child(n+3) {
width:50%;
float:left;
}
.form-group:nth-child(n+3) input, .form-group:nth-child(n+3) select {
width:95%;
}

Bootstrap - dropdownlist with button to the right, but form-control makes it 100% width

I'm having an issue with getting my 'Create' button to be right of my dropdownlist. Because the dropdown has a class form-control it makes the width 100% of the space available and so my button wraps underneath. If I remove the class the button sits next to the dropdown.
http://jsfiddle.net/2y39drrh/
Rather than writing a CSS class to override form-control's width, is there a better way? The forms.less file does say to use form-control with <select> elements...
<div class="form-group">
<label class="control-label col-md-1" for="Note_NoteTypeId">Type</label>
<div class="col-md-11">
<select class="form-control" data-val="true">
<option value="">Select...</option>
<option value="3">Option1</option>
<option value="2">Option2</option>
<option value="1">Option3</option>
</select>
<button class="btn btn-success" id="btnCreate" type="button">Create</button>
</div>
</div>
<div class="form-group">
<span class="field-validation-valid text-danger"></span>
</div>
I guess you want something like this?
Example 1
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="input-group">
<select class="form-control" data-val="true">
<option value="">Select...</option>
<option value="3">Option1</option>
<option value="2">Option2</option>
<option value="1">Option3</option>
</select>
<span class="input-group-btn">
<button class="btn btn-success" id="btnCreate" type="button">Create</button>
</span>
</div>
<div class="form-group">
<span class="field-validation-valid text-danger"></span>
</div>
Example 2
<div class="form-inline">
<select class="form-control" data-val="true">
<option value="">Select...</option>
<option value="3">Option1</option>
<option value="2">Option2</option>
<option value="1">Option3</option>
</select>
<input type="button" class="btn btn-success" value="Create">
</div>
I'm not sure why, the code I'm inserting to this post works weird on JSFiddle and SO editor. But it works fine on codepen.io
body {
max-width: 800px;
margin: 0 auto;
padding: 2em;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-6">
<select id="vehicle" name="vehicle" class="form-control" data-dropupauto="false">
<option value=""> 1 </option>
<option value=""> 2 </option> <option value=""> 3 </option>
</select>
</div>
<div class="col-md-6">
<button class="btn btn-success" id="btnCreate" type="button">Create</button>
</div>
</div>
See the example in full page. I believe that's the reason why SO editor and JSFiddle shows different results.

CSS Twitter Bootstrap Form

I am having trouble implementing a form in Twitter Bootstrap2.
I've set up a JS Fiddle http://jsfiddle.net/manishap/WNSCW/15/
Here is the code:
<div class="container">
<div id="ratingSubectives" class="row-fluid">
<form class="well" >
<fieldset>
<div class="control-group span3">
<label class="control-label" for="select01">Aaaaaaaaaaaa</label>
<div class="controls"><select id="select01">
<option value=""></option>
<option value="A">A</option>
<option selected="selected" value="B">B</option>
<option value="C">C</option>
</select></div>
</div>
<div class="control-group span3">
<label class="control-label" for="select02">Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb</label>
<div class="controls"><select id="select02">
<option></option>
<option selected="selected" value="A">B</option>
<option value="B">B</option>
<option value="C">C</option>
</select></div>
</div>
<div class="control-group span3">
<label class="control-label" for="select03">Ccccccccccc</label>
<div class="controls"><select id="select03" disabled>
<option value="A">A</option>
<option value="B">B</option>
<option selected="selected" value="C">C</option>
</select></div>
</div>
<div class="control-group span3">
<label class="control-label" for="select03"> </label>
<div class="controls"><button type="submit" class="btn">Submit</button></div>
</div>
</fieldset>
</form>
</div>
I'm trying to place 3 select controls with labels horizontally across a div. It looks right in English with short labels. However, eventually this is a site that is delivered in multiple languages, and if the labels get long (as in the middle selector), the label text overlaps the text next to it. How do I get the text to wrap?
I tried adding a max-width: 100%, as per another answer and that didn't work. Maybe I put the labels in divs instead of label tags...
Thanks for any suggestions.
Use the word-wrap attribute to break the word:
.control-label {
word-wrap: break-word;
}

Can I select the size attribute for twitter bootstrap multiple select?

The size attribute doesn't seem to be working with Twitter bootstraps css file. Am I missing something?
<div class="control-group">
<div class="controls" >
<select class="span2" multiple="multiple" id="multiSelect" size="2">
<option>Assigned1</option>
<option>Assigned2</option>
<option>Assigned3</option>
<option>Assigned4</option>
<option>Assigned5</option>
</select>
</div>
It should be working. I think you forgot a class from the container div.
<div class="control-group select optional">
<label class="select optional control-label"> *Category</label>
<div class="controls">
<select name="name" id="id" class="select optional" size="2">
<option value="">1</option>
<option value="">1</option>
</select>
</div>
</div>
Try this example and check how it works out. that's the way i'm using.

Resources