How to set the height of textarea to fill the whole column? - html

I am writing simple contact form using bootstrap-4. I have 1 row with 2 columns. Left column contains input text objects and selection object. Right column contains textarea. I try to make textarea the same hight as left col.
I aplied h-100 class into the textarea and parent div but it's higher than the left col.
link to the screenshot: https://i.imgur.com/Lrfwhtn.png
<div id="content" class="margin-from-nav">
<div class="container">
<form>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6">
<div class="form-group">
<label for="inputName1">Imię</label>
<input type="text" class="form-control" id="inputName1" placeholder="Imie">
</div>
<div class="form-group">
<label for="inputName2">Nazwisko</label>
<input type="text" class="form-control" id="inputName2" placeholder="Nazwisko">
</div>
<div class="form-group">
<label for="inputEmail4">Adres e-mail</label>
<input type="email" class="form-control" id="inputEmail4" placeholder="Email">
</div>
<div class="form-group">
<label class="mr-sm-2" for="inlineFormCustomSelect">Temat zapytania</label>
<select class="custom-select mr-sm-2" id="inlineFormCustomSelect">
<option selected>Wybierz temat...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6">
<div class="form-group h-100">
<label for="exampleFormControlTextarea1">Treść wiadomości</label>
<textarea class="h-100 form-control" id="exampleFormControlTextarea1" rows="10"></textarea>
</div>
</div>
</div>
</form>
</div>
</div>

You can use the flexbox utility classes (d-flex flex-column) to make the textarea fill the remaining height (flex-grow-1):
<div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6 d-flex flex-column">
<div class="form-group flex-grow-1 d-flex flex-column">
<label for="exampleFormControlTextarea1">Treść wiadomości</label>
<textarea class="form-control flex-grow-1" id="exampleFormControlTextarea1"></textarea>
</div>
</div>
Demo: https://www.codeply.com/go/2z4ckbR2FU

Related

How to size specific form elements using Bootstrap 4?

I got the following form and fields, but I can't size them so as each is suited to its input type:
This is what it looks like now VS expected result
<div id="addTaskFieldsDiv">
<h6>New task</h6>
<form>
<div class="row flex-nowrap d-flex align-items-center">
<div style="width: 30%" class="form-group col-sm"><select class="form-control" id="taskList" placeholder="Pick a task">
<option>Option1</option>
</select></div>
<div style="width: 15%" class="form-group col-sm"><input type="date" class="form-control" placeholder="MM/dd/yyyy"></div>
<div style="width: 10%" class="form-group col-sm"><input type="link" class="form-control" placeholder="Paste a link"></div>
<div style="width: 32%" class="form-group col-sm"><input type="text" class="form-control" placeholder="Notes"></div>
<div style="width: 7%" class="form-group col-sm"><input type="checkbox" title="Request Approval" class="form-control"></div>
<div style="width: 7%" class="form-group col-sm"><button id="addTask" type="submit" onclick="addTaskToTable()">+</button></div>
</div>
</form><br>
</div>
Yoc can give a try like this ...and change the column grid options to your convinience
<form>
<div class="row flex-nowrap d-flex align-items-center">
<div class="form-group col-sm col-md-3"><select class="form-control" id="taskList" placeholder="Pick a task">
<option>Option1</option>
</select></div>
<div class="form-group col-sm col-md-3"><input type="date" class="form-control" placeholder="MM/dd/yyyy"></div>
<div class="form-group col-sm col-md-2"><input type="link" class="form-control" placeholder="Paste a link"></div>
<div class="form-group col-sm col-md-2"><input type="text" class="form-control" placeholder="Notes"></div>
<div class="form-group col-sm col-md-1"><input type="checkbox" title="Request Approval" class="form-control"></div>
<div class="form-group col-sm col-md-1"><button id="addTask" type="submit" onclick="addTaskToTable()">+</button></div>
</div>
</form><br>

Add Styling to the Search/filters component (Bootstrap) ASP.NET core

I am trying to style and put multiple search filters on the page in a line so the User Experience is much better but I am kind of stuck with how to style this search component
<section class="search-sec">
<div class="container">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-3 col-md-2 col-sm-12 p-0">
<input class="" type="text" name="name" placeholder="Name" value="#ViewData["name"]" />
</div>
<div class="col-lg-2 col-md-2 col-sm-12 p-0">
<label for="age" class="">Age</label>
<select class="" name="age">
........
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<label for="minAge">Age range between</label>
<select name="minAge">
......
</select>
and
<select name="maxAge">
......
</select>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<label for="sex">Sex</label>
<select name="sex">
.....
</select>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<label for="stockNumber">Find by Stock Number</label>
<input type="text" name="stockNumber" value="#ViewData["stockNumber"]"
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<input type="submit" value="Search" class="btn btn-default" /> |
<a class="btn btn-link" asp-action="Index">Clear</a>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
The issue even after changing the sizes and all it looks like below
I tried looking for bootstrapping example and nothing helped. Can anyone please suggest how can I make this search functionality look better. Any help is greatly appreciated
The grid system contains 12 columns. If you want to put them in one line, the * in col-lg-* should sum within 12. Then you also need to adjust the letter to avoid the letter length over the div width.
Here is a whole working demo:
<section class="search-sec">
<div class="container-fluid">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-1 col-md-2 col-sm-12 p-0">
<input class="" type="text" name="name" placeholder="Name" value="#ViewData["name"]" />
</div>
<div class="col-lg-2 col-md-2 col-sm-12">
<label for="age" class="">Age</label>
<select class="" name="age">
<option>- Any -</option>
<option>aaa</option>
<option>bbb</option>
<option>ccc</option>
</select>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 p-0">
<label for="minAge">Age range from</label>
<select name="minAge">
<option>- Start -</option>
<option>1</option>
<option>2</option>
</select>
to
<select name="maxAge">
<option>- End -</option>
<option>14</option>
<option>15</option>
</select>
</div>
<div class="col-lg-2 col-md-3 col-sm-12">
<label for="sex">Sex</label>
<select name="sex">
<option>- Either -</option>
<option>male</option>
<option>female</option>
</select>
</div>
<div class="col-lg-1 col-md-3 col-sm-12 p-0">
<label for="stockNumber">Stock No.</label>
</div>
<div class="col-lg-1 col-md-3 col-sm-12 p-0">
<input type="text" name="stockNumber" value="aaa" />
</div>
<div class="col-lg-2 col-md-3 col-sm-12 p-0">
<input type="submit" value="Search" class="btn btn-default" /> |
<a class="btn btn-link" asp-action="Index">Clear</a>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
#section Scripts
{
<style>
input[type="text"] {
width: 100%; //fit the div width
}
select {
width: 65px;
}
</style>
}
Result:

How to align two inputs side by side inside a Bootsrap row?

The two inputs get misaligned due to the difference in length of the label text. Below is the part of my code:
<div class="row">
<div class="col-auto col-md-6 form-group">
<label for="category">Which of the following best describes you?</label>
<select class="form-control" id="category" name="category">
<option>Furniture Designer</option>
<option>Architect</option>
</select>
</div>
<div class="col-auto col-md-6 form-group">
<label for="training">Education level/type </label>
<input type="text" name="training" class="form-control" id="training" placeholder="Training">
</div>
</div>
How can I easily fix the misalignment and keeping the form resposive?
You could make the form-group's d-flex flex-column and then use mt-auto on the form input to force bottom alignment...
<div class="row">
<div class="col-auto col-md-6 form-group d-flex flex-column">
<label for="category">Which of the following best describes you?</label>
<select class="form-control mt-auto" id="category" name="category">
<option>Furniture Designer</option>
<option>Architect</option>
</select>
</div>
<div class="col-auto col-md-6 form-group d-flex flex-column">
<label for="training">Education level/type </label>
<input type="text" name="training" class="form-control mt-auto" id="training" placeholder="Training">
</div>
</div>
https://codeply.com/p/S9wKwrKLch
OR, use the text-truncate class on the labels to prevent text wrapping:
<label for="category" class="text-truncate">
Which of the following best describes you?
</label>
https://codeply.com/p/S9wKwrKLch
try with this way
<div class="col-auto d-md-flex flex-md-column col-md-6 form-group">
<label class="flex-md-fill" for="training">Education level/type </label>
<input type="text" name="training" class="form-control" id="training" placeholder="Training">
</div>
https://jsfiddle.net/lalji1051/t41Lnuxh/5/
The default behavior in bootstrap 4 is that the label will appear above the input. (Certainly with the code you have above).
If you want the label to be next to the input then try this straight from teh bs4 documentation:
<form>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword">
</div>
</div>
</form>
Bootstrap 4 docs
If you would like to handle it with a little piece of code, I hope this one wirks for you :
You can use equal margin-bottoms for both your inputs and if you like to use bootstrap, for example you can add mb-2 class to your inputs.
Or even you can use mt-auto to your inputs.

How to get achieve form style in bootstrap?

I am Trying to achieve below style using bootstrap framework. I was able to achieve some what similar to this, but the problem is the save button is not getting aligned to right(not taking available width). There is a gap between save button and red border wrapper. Is there any way to to get the button take available width? or is it possible using inline-form or something? please help.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div style="border:1px solid red;" class="container mb-4">
<div class="row mt-4">
<div class="col-5">
<div class="form-group row">
<label for="sel-city" class="col-form-label col-md-2">Label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-city" name="city"></select>
</div>
</div>
</div>
<div class="col">
<div class="form-group row">
<label for="sel-zone" class="col-form-label col-md-2">Label</label>
<div class="col-md-7">
<select class="form-control custom-select" id="sel-zone" name="workzone"></select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-5">
<div class="form-group row">
<label for="sel-stage" class="col-form-label col-md-2">label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-stage" name="stage">
</select>
</div>
</div>
</div>
<div class="col">
<div class="form-group row">
<label for="sel-status" class="col-form-label col-md-2">Label</label>
<div class="col-md-7">
<select class="form-control custom-select" id="sel-status" name="status"></select>
</div>
<button id="btn-status-save" class="btn btn-primary float-right" onclick="saveStatus()">Save</button>
</div>
</div>
</div>
</div>
So I restructured your html a bit so it flows automatically (see example)
Key things to note directly related to your question:
For the button (classes)
btn-block: This will make the button expand the entire available width of the container div.
For the column (classes):
align-self-end : will put item at the very bottom right of div; would need to add mb-3 to add bottom margin so it aligns with your other element.
noPadding: custom css class. By default, cols will have padding on the left and right side. You will want to override this with a css class if you want to kill that off.
.noPadding {
padding-right: 0px !important;
padding-left: 0px !important;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div style="border:1px solid red;" class="container mb-4">
<div class="row mt-4">
<div class="col-5">
<div class="form-group">
<label for="sel-city" class="col-form-label col-md-2">Label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-city" name="city"></select>
</div>
</div>
<div class="form-group">
<label for="sel-zone" class="col-form-label col-md-2">Label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-zone" name="workzone"></select>
</div>
</div>
</div>
<div class="col-5">
<div class="form-group">
<label for="sel-stage" class="col-form-label col-md-2">label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-stage" name="stage">
</select>
</div>
</div>
<div class="form-group">
<label for="sel-status" class="col-form-label col-md-2">Label</label>
<div class="col-md-10">
<select class="form-control custom-select" id="sel-status" name="status"></select>
</div>
</div>
</div>
<div class="col align-self-end mb-3 noPadding">
<button id="btn-status-save" class="btn btn-primary btn-block" onclick="saveStatus()">Save</button>
</div>
</div>
</div>

Align Labels and Textboxes in Form-Inline

I am using bootstrap's grid system and want to create an inline form.
Here is what I have:
<div class="container body-content">
<form class="well form-inline" style="width: 100%;">
<div class="row">
<div class="form-group col-md-4">
<label>Location:</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Assignment:</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Incident Number:</label>
<input type="text" class="form-control">
</div>
</div>
<br>
<br>
<div class="row">
<div class="form-group col-md-4">
<label>Date:</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Training:</label>
<input type="text" class="form-control">
</div>
<div class="form-group col-md-4">
<label>Example:</label>
<input type="text" class="form-control">
</div>
</div>
</form>
</div>
When this is ran, there is no structure or alignment for the textboxes or the labels. How can I achieve this?
Here is a bootply
For each label and input you should make this structure:
<div class="form-group col-md-4">
<label class="col-lg-4 control-label">Location:</label>
<div class="col-lg-8">
<input type="text" class="form-control">
</div>
</div>
this will make it work with the grid system
See bootply