I'm trying to figure out how I can get labels in my form to be maintained all on one line. That is if a label for a specific input happens to be longer than the rest, I would like the other labels to have additional white space underneath such that my input fields are in alignment. See picture for alignment issue.
<div class="row">
<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
<label>Window Utilization Total:<span class="input-required" ng-show="logbook.util.$error.required">*</span></label>
<input name="util" ng-model="sortie.total_window_time" empty-to-null required type="text" title="Time: e.g. 01:00, 12:30, 23:59, etc" maxlength="5"
placeholder="00:00" pattern="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$"/>
<p class="input-error" ng-show="logbook.util.$invalid && logbook.util.$touched">
Invalid time (e.g. 12:00, 23:59, 1:30, etc).
</p>
</div>
<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
<label>Flight Plan:</label>
<input ng-model="sortie.flight_plans" empty-to-null type="text" placeholder="e.g. NMZSAN_FP509"/>
</div>
<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
<label>Partial Flight Plans (Lines Completed):</label>
<input ng-model="sortie.partial_flight_plan" empty-to-null type="text" placeholder="e.g. NMZSAN_FP509, Lines 1-5"/>
</div>
<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
<label>Date of Last Control:</label>
<input ng-model="sortie.last_control_date" empty-to-null type="text" placeholder="YYYY-MM-DD"/>
</div>
</div>
If you want an all-css approach, it's going to be tricky. Someday, grid layout will make this sort of thing easy, but it has terrible support right now.
However, you could use flex-box to help you.
I think it will work if you have two rows, one for labels and one for the inputs.
<style>
div { display: flex }
label, input { flex: 1 }
</style>
<div>
<label for="1">Short</label>
<label for="2">Also Short</label>
<label for="3">So long ohmygoodness so much to say</label>
</div>
<div>
<input id="1"/>
<input id="2"/>
<input id="3"/>
</div>
Here's a jsfiddle to demonstrate it.
Note that flexbox support is not yet perfect, and you should add some browser-specific prefixes and be aware of its limitations. Read more at caniuse.com. If you need support for older versions of IE, it looks like you'll have to use a javascript fallback as indicated in the other answer here.
Just add this js code in your file, what this will do, it will equalize all the label height based on the height of biggest label as per its content/text.
Add class label_big to all the label elements
This works for me very well, hope it will resolve your issue.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
var highestBox = 0;
$('.form_group .label_big').each(function(){
if($(this).height() > highestBox){
highestBox = $(this).height();
}
});
$('.form_group .label_big').height(highestBox);
});
</script>
Related
I have this code that generates a red asterisk in my required fields
.required:before {
content:"* ";
color:red;
}
in some it shows well but in others it doesn't
How can I make it show on the same line of my label?
<div class="form-group container-fluid">
<label class="col-md-2 control-label required">Nombre:</label>
<div class="col-md-10">
<input type="text" class="form-control" ng-model="activity.name">
</div>
</div>
Looks like it's the width of your labels which pushes the text to lines below.
If you increase the width of .control-label you should be able to keep everything on the same line.
It looks like you are using bootstrap so try change the col widths (col-md-*)
you can try col-md-3 and col-md-9 or col-md-4 and col-md-8 respectively.
e.g. (3 and 9)
<div class="form-group container-fluid">
<label class="col-md-3 control-label required">Nombre:</label>
<div class="col-md-9">
<input type="text" class="form-control" ng-model="activity.name">
</div>
</div>
I solved my mistake with this:
.required:before {
content:"*\00a0";
color:red;
}
I started looking into Bootstrap to make my forms responsive. I want to generate them from a data source and place each control on the page, using all the space. I got something that resemble what I want, with a responsive design, but I am using class="row", which gives me some white spaces when the divs have different heights on the same row. Is it possible to use something else that would remove those, while, if possible, staying with aligned controls that removes most of the white space?
This is the full code I am using for my tests:
<html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<br/>
<div class="row">
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="">
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"></textarea>
</div>
</div>
<div class="form-group col-sm-6 col-lg-4 col-xl-3">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
</div>
</div>
</div>
</div>
</body>
</html>
You can see some whitespace here on the 1st row (left of Message label), as the Message Div has a different height.
You can also see this strange whitespace on the 3rd row, where a complete column is empty. It seems to happen when the label on top of it has a second line (2+3=? where the ? appear on a second line). If I drag the window large enough so the label is on one line, the problem is gone. Still, that will happen and I don't want it to create problems.
This one is not related to the whitespace (an extra problem). I need to be able to resize my text area, and the resize operation should move the other divs out of the way, instead of letting them on top of the current text area... This already works when I drag the area to the bottom (down), but not to the right.
Would you have an idea on how I could resolve the problems listed above (bullet points) ?
UPDATE
For the screen above, the way I would like it to be shown (the order of the items could differ) is indicated in the following screen. As you can see, I would like things to stay aligned in rows while reducing the white space. The smaller items are combined in the same column of the same row to fit the empty space, just like a row could have nested rows for a specific column. Still, if two smaller items cannot fit inside the space, it should not be placed there, as I want to keep lines of content. As an example, if "name" and "email" cannot fit in the height of "message", then I should have the same layout as before ("name, email, message" only, in the 1st row). The number and types of items are variables (depending on the form). Also, it is important that the form stays responsive to screen size changes and vertical resizes (it is right now), so if I lower the size or enlarge a text area, the number of columns still need to change and the same kind of layout should be seen with less columns.
I would also add that my items (whatever the type) need to be shown like this:
["centered label" "input field"]
They can then be stacked, still keeping the same absolute order (most of it at least). The important part is that I need groups for those items, that include a responsive label and input.
UPDATE2
This is another picture that represent the same problem. I used the same code as before but with some other controllers. I marked the spots where the whitespace should not be present with red arrows. This time the form items's html was generated from a data source (which represent my goal).
For your first problem you could use <div class="clearfix"> in between each three form-groups. clearfix will clear the spacing and reset on the next row. This solution will also help your second problem. If you also want this to work on sm and xl make use of different .clearfix divs which will hide on the specific browser like so: <div class="clearfix hidden-sm"></div>.
http://www.bootply.com/KxONBlaNXJ
You can see some whitespace here on the 1st row (left of Message label), as the Message Div has a different height.
The main cause of the spacing issues have to do with the differing heights of your div.form-groups.
Example: In your screenshot, the height of the "first row" is pretty much defined by the height of the message div.
Masonry.js is one way about this - refer to this previous question for a nice visual made by the original poster on what Masonry can do (as well as link to Masonry).
You can also see this strange whitespace on the 3rd row, where a complete column is empty. It seems to happen when the label on top of it has a second line (2+3=? where the ? appear on a second line). If I drag the window large enough so the label is on one line, the problem is gone. Still, that will happen and I don't want it to create problems.
That nitpicky 2+3=? is indeed "claiming" that space as you have it now, thus pushing the next div over an entire column. So another height issue and as mentioned above, Masonry is another way about this.
This one is not related to the whitespace (an extra problem). I need to be able to resize my text area, and the resize operation should move the other divs out of the way, instead of letting them on top of the current text area... This already works when I drag the area to the bottom (down), but not to the right.
I can point you to this bootply example which shows how you can disable resize.
To your points, when you drag "down", the height adjusts and the following divs react accordingly (similar theme as above). You can drag right because you've applied col-sm-6 col-lg-4 col-xl-3... i.e. the widths are controlled via Bootstrap and you can't change that by simply dragging a textarea.
Edit - I just noticed #CBroe's comment and I like that CSS only solution. The only word of caution is I probably wouldn't directly modify the bootstrap -col- classes. I would simply apply a new class name and play from there :)
You have col-*-* in both the outline <div> and the label - is the nesting intentional? If so, then the child nest needs it's own .row... see http://getbootstrap.com/css/#grid-nesting
Use col-*-* in the <input> & <textarea> to assign widths... see http://getbootstrap.com/css/#form-control-column-sizing, scroll down to Column sizing
i'm trying to build a 2 column form layout in bootstrap with an fixed height textarea on the right. I got it working well on desktop screen with an .pull-right-md (own class) on the textarea box. But in "responsive" mode (on smaller screens) I have the problem with the order of the boxes. I want the textarea to be on the last position when displayed on small screens.. I already tried to solve this problem by ordering the col's with .col-*-pull and .col-*-push classes but it was not working.
Here you can see what I have done so far: http://www.bootply.com/BBFB4Tt97j
Do you have any ideas how I could solve this problem?
Plz don't ever do duplication of html elements for sake of styling, it's not worth it! You breaking semantics, and produce illogical code that is tricky to maintain.
You can easily achieve desired effect without duplicating anything:
http://output.jsbin.com/debenudiqi/2/
You can grab code here
http://jsbin.com/debenudiqi/2/edit
This is what I suggest, tried to work my way around with pull and push but i haven't found a solution with that. You can use the hidden-xs, visible-xs to create two different text-area, one visible only on small screen and the other on large screens only. But you make sure when you handle the form, you handle the two different text areas.
<form class="">
<div class="col-md-6 col-sm-12 form-group pull-right-md hidden-sm hidden-xs">
<textarea class="form-control textarea-fixed-height" id="textarea" name="textarea">default text</textarea>
</div>
<div class="col-md-6 col-sm-12 form-group">
<input class="form-control" id="inputEmail3" placeholder="Name" type="text">
</div>
<div class="col-md-6 col-sm-12 form-group">
<input class="form-control" id="inputPassword3" placeholder="Email" type="email">
</div>
<div class="col-md-6 col-sm-12 form-group">
<input class="form-control" id="inputPassword3" placeholder="Telefon" type="text">
</div>
<div class="col-md-6 col-sm-12 form-group">
<input class="form-control" id="inputPassword3" placeholder="Betreff" type="text">
</div>
<div class="col-md-6 col-sm-12 form-group pull-right-md hidden-lg hidden-md">
<textarea class="form-control textarea-fixed-height" id="textarea1" name="textarea1">default text</textarea>
</div>
</form>
Bootply link
So for everyone with the same kind of problem thats the solution of my problem: http://www.bootply.com/BBFB4Tt97j#
I have put two textareas in the form-tag. One as first box and the second on the last position but before the submit button. With .hidden-xs and .hidden-sm on the first textarea it's not visible for smaller devices and with .hidden-md and .hidden-lg I prevent the textarea-tag for showing up on big screens.
this is working fine now.. thx
I need my 2 inputs which placed inline to have width of parent div which defines col-md-6 and col-md-3. Right now inputs are aligned correctly but have width which in one case less than col-md-6 and in second case more than col-md-3. How to make this inputs have width col-md-6 and col-md-3 correspondingly?
<div class="col-md-9">
<form action="" role="form" class="form-inline">
<div class="col-md-6">
<div class="form-group">
<label for="iR" class="sr-only">i R</label>
<input type="text" class="form-control" id="iR" placeholder="some mid long explanation" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="iS" class="sr-only">i S</label>
<input type="text" class="form-control" id="iS" placeholder="some mid long explanation 2" />
</div>
</div>
</div>
As others have mentioned, you need to specify custom widths with inline forms. From the docs:
Inputs and selects have width: 100%; applied by default in Bootstrap. Within inline forms, we reset that to width: auto; so multiple controls can reside on the same line. Depending on your layout, additional custom widths may be required.
In your case, you need to specify width: 100% for both the input and the form-group:
<div class="form-group" style="width: 100%">
and
<input type="text" class="form-control" id="iR" placeholder="some mid long explanation" style="width: 100%" />
Working example in JSFiddle
Just put style="width: 100%;" on the input; Btw, you are missing a form closing tag.
Also if you look at bootstraps for any elements you set up most of the time they leave a bit of margins. So if you don't want any margins just change the margins to 0.
I've succeeded to pin down an error in my code. Really weird I must say. Of course, before anyone says google it, I have hehehe. I simply want to know if this is a bug, and or if there is some solution to this.
I have a form in which I want to edit some content and send it to the server. The thing is, when I try to focus a field (click on it), I can't. It is disabled for some reason. Not only inputs, but select boxes and checkboxes as well. However, if I change the class of the div with the textarea as its child from col-sm-12 to col-sm-11 everithing works as it should. Now I don't want to use a column of size 11 when everything else can be 12. Looks just weird.
Here is my code:
<form>
<div class="form-group col-xs-12 col-sm-6 col-md-6 col-lg-6">
<label for="title" >Title</label>
<input type="input" name="title" class="form-control" value="<?php echo $article['title'] ?>">
</div>
...
...
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label for="content" >content</label>
<textarea name="content" class="form-control" rows="3"><?php echo $article['content'] ?></textarea>
</div>
<div class="form-group col-xs-12 col-sm-6 col-md-6 col-lg-2">
<input type="submit" name="submit" class="btn btn-success form-control" value="Save!"/>
</div>
...
</form>
Does anyone know anything about this?
I experienced this issue today. The text inputs would not focus on click, and the clearfix div did not work.
The solution was to wrap each col-xx-x in a div with a .row class. Ex:
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label for="content" >content</label>
<textarea name="content" class="form-control" rows="3"></textarea>
</div>
</div>
I experienced the same problem. Neither .clearfix or wrapping each col-xx-x in a div with a row class worked. Wrapping the form tags within a div containing a row class did however solve the issue.
<div class="row">
<form>
.
.
.
</form>
</div>
i have same problem, still not work after add div row. i add this code to style css to solve the problem :
.col-md-12{
width: 100% !important;
}
add to all col-xx-12
The problem is that there is a div or some other element that is overlapping the input controls. You should be able to tab through to the input element, even through you can't click on it. Try visiting this stackoverflow post: Bootstrap 3 form not working on mobile devices.