CSS - Align big Element right of multiple smaller Rows - html

I have a form with multiple inputs.
All of those inputs are Dropdowns, Checkboxes, short Texts, etc. Except one which can be come quite large (textarea). I want all the smaller Inputs on the left side of the Page and the textarea on the right side of the Page.
The Textarea is supposed to have the same height as all the elements on the right side and take roughly half of the Pages width.
My problem is now that I am unable to properly add the Textarea to the right Side. When I use "float:right" then it either has an huge gap between the smaller Elements and itself, or it is small and when I make it bigger then the small Elements become smaller. Or it has the correct size, but then it only has one Element on the left side and every other Element comes after the Textarea has ended.
<form method="post">
<input asp-for="ID" type="hidden" />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="row " >
<div class="form-group col-md-6">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group col-md-5">
<label asp-for="Comment" class="control-label"></label>
<textarea asp-for="Comment" rows="14" class="form-control" oninput='this.style.height = "";this.style.height = this.scrollHeight + 3 + "px"' height:"100vh">
</textarea>
<span asp-validation-for="Comment" class="text-danger"></span>
</div>
</div>
<div class="row">
<div class="form-group col-md-3">
.....
</div>
<div class="form-group col-md-3">
....
</div>
</div>
<div class="row">
#if (Model.Valid is not null)
{
<div class="form-group col-md-3">
....
</div>
}
<div class="form-group col-md-3">
....
</div>
</div>
<div class="row">
......
<hr />
.....
So, all the smaller Elements are inside the "form-group", which are mostly inside "row". And on the right side I now want the Comment TextArea.
I would prefer a plain Bootstrap Solution (especially since everything else is already working in Bootstrap), but I am open to everything.

Related

Bootstrap form controls alignment when resizing window

Using bootstrap 3.3 and angular here.
I am trying to create a search filter above my grid but having some alignment issues. In full page I can see them aligned correctly, but when I try to resize the page all my form controls get jumbled up and down. I believe these is some css class which is missing but cant seem to figure out what is that. Could anyone point me in right direction.
I also created a stackblitz demo here at:
https://angular-datrange-enhq8w.stackblitz.io/
If you resize the window you would see what I am talking about.
Here is the stackblitz editor for this:
https://stackblitz.com/edit/angular-datrange-enhq8w
Below is some relevant code:
<div id="filters">
<form [formGroup]="filtersForm" >
<div class="row padding-top-10">
<div class="col-xs-12 col-sm-12 col-md-1 col-lg-1 form-group" style="margin-right:65px">
<label for="name">Name</label>
<input formControlName="name" name="name" type="text" style="height:33px" autocomplete="off" class="hidden-xs hidden-sm" />
</div>
</div>
</form>
</div>
Also on side note if you see the demo somehow I feel my dropdown does has the right style, is there some extra bootstrap 3 style I can add for this.
Thanks for looking into.
Anyone for inputs?
The grid system for bootstrap states that every row must be wrapped by a container class.
<div id="filters">
<form [formGroup]="filtersForm">
<div class="container-fluid">
<div class="row padding-top-10">
<div class="col-xs-12 col-sm-12 col-md-1 col-lg-1 form-group" style="margin-right:65px">
<label for="name">Name</label>
<input formControlName="name" name="name" type="text" style="height:33px" autocomplete="off"
class="hidden-xs hidden-sm" />
</div>
</div>
</div>
</form>
</div>
This does not solve the issue of changing the size. The bootstrap grid system is setup like this: For every row, there are 12 columns. What you are saying is that for the div with the class col-xs-12, make the element in that class have a width of 100% when the screen size is extra small. You are also saying that when it hits the col-md-1 (medium screen size breakpoint), it should have a width of 8.3333%. You have 6 divs in that page you provided. Since you have 6 divs, 12 columns / 6 divs = 2 columns per div. Therefore your code should be refactored to something like this:
<div id="filters">
<form [formGroup]="filtersForm">
<div class="container-fluid">
<div class="row padding-top-10">
<div class="col-xs-12 col-md-2 form-group" style="margin-right:65px">
<label for="name">Name</label>
<input formControlName="name" name="name" type="text" style="height:33px" autocomplete="off"
class="hidden-xs hidden-sm" />
</div>
</div>
</div>
</form>
</div>
Notice how I removed col-sm-12.. this is because col-xs-12 will set the width for every screen size up to the next given class. In this case you have col-xs-12, therefore when the screen size is xs and sm, it'll have a width of 100%. When it hits the md breakpoint, it'll change the width to 2/12 and have the same width for lg and xl screen sizes.
Check out bootstrap grid system.
The base syntax is:
container | container-fluid
row
columns (the total of col must be 12)
Also, there is no need of aditional margins on your col divs.
<div id="filters">
<form class="container-fluid">
<div class="row padding-top-10">
<div class="col-xs-12 col-md-2">
<div class="form-group">
<label for="name">Name</label>
<input formControlName="name" name="name" type="text" autocomplete="off" class="form-control" />
</div>
</div>
<div class="col-xs-12 col-md-2">
<div class="form-group">
<label for="age">Age Range</label>
<select class="form-control" formControlName="age">
<option [selected] value="">All</option>
<option *ngFor="let age of ages" value='{{age}}'>
{{age}}
</option>
</select>
</div>
</div>
</div>
</form>
</div>
If you want to persist all columns in a single row even on small screens, remove col-xs-12 and change col-md-2 to col-xs-2.

CSS class for rendering divs dynamically on half of page

I am stuck in rendering div via ng-repeat. I want to render the coming divs in ng-repeat one by one covering half the page.
Here is my code:
<div class="col-md-12">
<div class="form-group col-md-6" ng-repeat="field in selectedfields" ng-if="!selectedfields[$index].allowedValues || selectedfields[$index].allowedValues.length === 0 ">
<label class="control-label" for="domain">{{field.name}} </label>
<input placeholder="{{field.name}}" class="form-control" type="text" id="domain">
</div>
<div class="form-group col-md-6" ng-repeat="field in selectedfields" ng-if="selectedfields[$index].allowedValues.length >= 1">
<label class="control-label" for="{{field.name}}">{{field.name}} </label>
<select class="form-control">
<option value="{{allowedValue.name}}" ng-repeat="allowedValue in field.allowedValues" ng-model="field.allowedValues">{{allowedValue.name}}</option>
</select>
</div>
</div>
The divs(textboxes/dropdown) under the parent div should appear one by one covering half the page, but they are coming on full page. Each div is rendering on next line. Can someone please suggest what am I doing wrong in giving the css class?
Your final layout should be
<div class="col-md-12">
<div class="row">
<!-- ng-repeat stuff goes here !-->
</div>
</div>

Removing whitespace in bootstrap forms

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

Bootstrap CSS vertical spacing disappears when columns get stacked

I'd like some form fields to be side by side when there's width available on the client, and stacked neatly when there isn't. It's almost working, but not quite "stacked neatly". Here's the markup ...
<div class="form-group">
<div class="col-md-3">
<input type="text" placeholder="State" class="form-control" ng-model="family.state">
</div>
<div class="col-md-4">
<input type="text" placeholder="Zip" class="form-control" ng-model="family.zip">
</div>
<div class="col-md-4">
<div class="checkbox">
<input type="checkbox" ng-model="family.listAddress">List address</input>
</div>
</div>
</div>
Here's the wide result, which is as desired:
But here's the narrow result which is not quite right (because of the missing vertical space):
What does your CSS look like? You can add a class to all of these divs and apply a simple margin: 5px; and that could solve your problem.

Bootstrap 3.0 Text is coming after 2 input elements when it is coded before.

With Bootstrap 3.0, I am have a couple of questions/issues:
1) For learning, how is possible to have the div with class col-sm-5 small than the child div elements that are specified longer with class="col-sm-4" + class="col-sm-4" which equals 8?
2) I want "Pick A Date" text to come before the 2 input elements. However, it's coming after them which makes no sense to me.
<form name="dateFrom">
<div class="form-group well col-sm-5">
<div class="form-group">
Pick A Date
<div class="col-sm-4">
<input type="text" class="form-control datepicker" placeholder="From date" name="search" class="form-control">
</div>
<div class="col-sm-4">
<input type="text" class="form-control datepicker" placeholder="To date" name="search1" class="form-control">
</div>
</div><!-- /input-group -->
</div><!-- /.col-lg- -->
</form>
1) the widths of the columns are defined in percent, col-sm-5 has is 5/12 of the width of its parent and the col-sm-4 is 4/12 of the width of its parent which is in your case the form-group.
2) the elements with the class col-sm- have float: left, as your text Pick A Date does not have any floating attribute, the two div with col-sm- float to the left thats why your text appears on the right. If you want it in the correct order surround it with a div and add e.g. col-sm-4 to it.