I have few search filters on my page and a data card ASP.Net Core application. I am trying to align them on the page so it looks better. Currently it looks like below
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="card border-info mb-3" style="max-width: 12rem;">
<div class="card-header text-center"><b>Current Shipping Address</b></div>
<div class="card-body text-info" style="font-size: 14px;">
<b><h7 class="card-title">Location</h7></b>
<p class="card-text">
#Html.DisplayFor(model => model.CustomerData.Location)
<br />#Html.DisplayFor(model => model.CustomerData.Address1)
</p>
</div>
</div>
</div>
<div class="col-md-9">
<section class="search-sec">
<div class="container-fluid">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-lg-9">
<div class="row">
<div class="col-lg-5 col-md-2 col-sm-12 p-0">
<label for="name" class="">Strain Name</label>
<input class="" type="text" name="name" value="#ViewData["name"]" />
</div>
<div class="col-lg-4 col-md-2 col-sm-12 p-0">
<label for="genotype" class="">Genotype</label>
<input class="" type="text" name="genotype" value="#ViewData["genotype"]" />
</div>
</div>
<div class="form-row">
<div class="col-lg-3 col-md-2 col-sm-12 p-0">
<label for="age" class="">Age</label>
<select class="" name="age">
......
</select>
</div>
<div class="col-lg-6 col-md-2 col-sm-12 p-0">
<label for="minAge">Age range between</label>
<select name="minAge">
.......
</select>
and
<select name="maxAge">
........
</select>
</div>
</div>
<div class="form-row">
<div class="col-lg-3 col-md-2 col-sm-12 p-0">
<label for="sex">Sex</label>
<select name="sex">
......
</select>
</div>
<div class="col-lg-3 col-md-2 col-sm-12 p-0">
<div class="form-group form-actions col-md-10 no-color">
<label for="stockNumber">Find by Stock Number</label>
<input type="text" name="stockNumber" value="#ViewData["stockNumber"]" />
</div>
</div>
</div>
<div class="col-lg-3 col-md-2 col-sm-12 p-0">
<input type="submit" value="Search" class="btn btn-default" /> |
<a class="btn btn-link" asp-action="Index">Return to Original List</a>
</div>
</div>
</div>
</form>
</div>
</section>
</div>
</div>
</div>
I am trying put the data card in the left and align the search filters in the right 2 in a row and show them in 3 rows.
I tried changing the sizes of the col-lg-* in each row on the filters but still cannot align them like what I am trying any help is greatly appreciated
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="card border-info mb-3" style="max-width: 12rem;">
<div class="card-header text-center"><b>Current Shipping Address</b></div>
<div class="card-body text-info" style="font-size: 14px;">
<b><h7 class="card-title">Location</h7></b>
<p class="card-text">
#Html.DisplayFor(model => model.CustomerData.Location)
<br />#Html.DisplayFor(model => model.CustomerData.Address1)
</p>
</div>
</div>
</div>
<div class="col-md-9">
<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 mb-3">
<div class="col-lg-6 col-md-2 form-check-inline mr-0">
<label for="name" class="col-auto">Strain Name</label>
<input class="form-control" type="text" name="name" value="#ViewData["name"]" />
</div>
<div class="col-lg-6 col-md-2 form-check-inline mr-0">
<label for="genotype" class="col-auto">Genotype</label>
<input class="form-control" type="text" name="genotype" value="#ViewData["genotype"]" />
</div>
</div>
<div class="row mb-3">
<div class="col-lg-3 col-md-2 col-sm-12 form-check-inline m-0">
<label for="age" class="col-auto" >Age</label>
<select class="form-control px-1" name="age">
<option>-Any-</option>
</select>
</div>
<div class="col-lg-9 col-md-2 col-sm-12 form-check-inline m-0 justify-content-between">
<label class="col-auto" for="minAge">Age range between</label>
<select class="form-control" name="minAge">
<option>-Start-</option>
</select>
<label class="col-auto" for="minAge">and</label>
<select class="form-control" name="maxAge">
<option>-End-</option>
</select>
</div>
</div>
<div class="row">
<div class="col-lg-2 col-md-2 col-sm-12 form-check-inline m-0">
<label class="col-auto" for="sex">Sex</label>
<select class="form-control px-1" name="sex">
<option>-Either-</option>
</select>
</div>
<div class="col-lg-5 col-md-2 col-sm-12 form-check-inline m-0">
<label class="col-auto" for="stockNumber">Find by Stock Number</label>
<input type="text" class="form-control" name="stockNumber" value="#ViewData["stockNumber"]" />
</div>
<div class="col-lg-5 col-md-2 col-sm-12 form-check-inline m-0">
<input type="submit" value="Search" class="btn btn-default" /> |
<a class="btn btn-link" asp-action="Index">Return to Original List</a>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
</div>
</div>
</div>
Related
Let's say I have this kind of grid columns bootstrap 4 (image on the left) and then I collapse the card 1 using boostrap collapse, and I expected the grid 3 to overlapping the height of row (and the result will be on the right image)
I have tried it using align-item-start and align-self-start, turns out it just like the row class bootstrap..
my investigation is that grid 1 and 2 covered by row class that has certain height (if height 1 < 2 then height 2 will be the row height and vice versa..
is this even possible using bootstrap 4?
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<div class="row no-gutter">
<div class="col-7">
<div class="card shadow mb-4">
<!-- Card Header - Dropdown -->
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary">Data Rekam Medis</h6>
<button class="btn btn-xs btn-primary mb-0" type="button" data-toggle="collapse" data-target="#collapseRekamMedis" aria-expanded="true" aria-controls="collapseRekamMedis">
Toggle
</button>
</div>
<div class="collapse show" id="collapseRekamMedis">
<!-- Card Body -->
<div class="card-body py-2">
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">
<nobr>Pasien<i class="text text-danger">*</i></nobr>
</label>
<div class="col-sm-8">
<input type="text" class="form-control number text-right" name="anamnesa" />
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">Berat Badan<i class="text text-danger">*</i></label>
<div class="col-sm-3">
<div class="input-group">
<input type="text" class="form-control number text-right" name="anamnesa" />
<div class="input-group-append">
<span class="input-group-text">kg</span>
</div>
</div>
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">
<nobr>Tekanan Darah<i class="text text-danger">*</i></nobr>
</label>
<div class="col-sm-5">
<div class="input-group">
<input type="text" class="form-control number text-center" name="sistole" />
<div class="input-group-append input-group-prepend">
<span class="input-group-text">/</span>
</div>
<input type="text" class="form-control number text-center" name="diastole" />
</div>
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Perabaan<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="perabaan" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Pengamatan<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="pengamatan" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Penciuman<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="penciuman" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Diagnosa<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="diagnosa" />
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">Sindrom<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="sindrom" />
</div>
</div>
<div class="row">
<label class="col-sm-3 col-form-label text-right">Anamnesa<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<textarea class="form-control" name="sindrom" rows="4"></textarea>
</div>
</div>
</div>
<div class="card-footer text-right">
<button type="button" class="btn btn-warning" id="btn_save"><i class="fa fa-save"></i> Simpan</button>
</div>
</div>
</div>
</div>
<div class="col-5 float-right">
<div class="card shadow mb-4">
<!-- Card Header - Dropdown -->
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary">Informasi Pasien</h6>
<button class="btn btn-xs btn-primary mb-0" type="button" data-toggle="collapse" data-target="#collapsePatientData" aria-expanded="true" aria-controls="collapsePatientData">
Toggle
</button>
</div>
<div class="collapse show" id="collapsePatientData">
<!-- Card Body -->
<div class="card-body py-2">
<div class="mb-0 row">
<label class="col-4 col-form-label text-right">
<nobr>Pasien <i class="text text-danger">*</i></nobr>
</label>
<div class="col-8">
<input type="text" readonly class="form-control-plaintext" id="patient_name" value="Maman Abdurrahman">
</div>
</div>
<div class="mb-0 row">
<label class="col-4 col-form-label text-right">Usia</label>
<div class="col-8">
<input type="text" readonly class="form-control-plaintext" id="patient_name" value="25 thn">
</div>
</div>
<div class="mb-0 row">
<label class="col-4 col-form-label text-right">Diagnosa</label>
<div class="col-8">
<input type="text" readonly class="form-control-plaintext" id="patient_name" value="Radang tenggorokan">
</div>
</div>
<div class="mb-0 row">
<label class="col-4 col-form-label text-right">Anamnesa</label>
<div class="col-12">
<textarea class="form-control-plaintext" id="patient_name" rows="6">publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available</textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-7">
<div class="card shadow mb-4">
<!-- Card Header - Dropdown -->
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-primary">Data Rekam Medis</h6>
<button class="btn btn-xs btn-primary mb-0" type="button" data-toggle="collapse" data-target="#collapsesRekamMedis" aria-expanded="true" aria-controls="collapsesRekamMedis">
Toggle
</button>
</div>
<div class="collapse show" id="collapsesRekamMedis">
<!-- Card Body -->
<div class="card-body py-2">
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">
<nobr>Pasien<i class="text text-danger">*</i></nobr>
</label>
<div class="col-sm-8">
<input type="text" class="form-control number text-right" name="anamnesa" />
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">Berat Badan<i class="text text-danger">*</i></label>
<div class="col-sm-3">
<div class="input-group">
<input type="text" class="form-control number text-right" name="anamnesa" />
<div class="input-group-append">
<span class="input-group-text">kg</span>
</div>
</div>
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">
<nobr>Tekanan Darah<i class="text text-danger">*</i></nobr>
</label>
<div class="col-sm-5">
<div class="input-group">
<input type="text" class="form-control number text-center" name="sistole" />
<div class="input-group-append input-group-prepend">
<span class="input-group-text">/</span>
</div>
<input type="text" class="form-control number text-center" name="diastole" />
</div>
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Perabaan<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="perabaan" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Pengamatan<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="pengamatan" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Penciuman<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="penciuman" />
</div>
</div>
<div class="mb-2 row">
<label class="col-sm-3 col-form-label text-right">Diagnosa<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="diagnosa" />
</div>
</div>
<div class="row mb-2">
<label class="col-sm-3 col-form-label text-right">Sindrom<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="sindrom" />
</div>
</div>
<div class="row">
<label class="col-sm-3 col-form-label text-right">Anamnesa<i class="text text-danger">*</i></label>
<div class="col-sm-8">
<textarea class="form-control" name="sindrom" rows="4"></textarea>
</div>
</div>
</div>
<div class="card-footer text-right">
<button type="button" class="btn btn-warning" id="btn_save"><i class="fa fa-save"></i> Simpan</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
Silly me, turns out you don't need to user .row class..
simply using .float-left and .float-right on each div
FINAL CODE
<div class="col-7 float-left"></div>
<div class="col-4 float-right"></div>
<div class="col-7 float-left"></div>
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:
I've created a Bootstrap 4 form with this layout
And the Razor page code to generate it is:
#page
#model HighStreetLeads3.Pages.Leads.EditModel
#{
ViewData["Title"] = "Edit";
Layout = "~/Pages/Shared/_Layout.cshtml";
}
<h1>Edit</h1>
<h4>Lead</h4>
<hr />
<form class="form-inline col-lg-12" method="post">
<div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Lead.Id" />
</div>
<div class="row col-12">
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.Name" class="control-label float-left">Name</label>
</div>
<div class="col-9">
<input asp-for="Lead.Name" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.Name" class="text-danger"></span>
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.PhoneNumber" class="control-label float-left">Number</label>
</div>
<div class="col-9">
<input asp-for="Lead.PhoneNumber" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.PhoneNumber" class="text-danger"></span>
</div>
</div>
</div>
</div>
<div class="row col-12">
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.Status" class="control-label float-left"></label>
</div>
<div class="col-9">
<input asp-for="Lead.Status" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.Status" class="text-danger"></span>
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.NextAction" class="control-label float-left">Next Action</label>
</div>
<div class="col-9">
<input asp-for="Lead.NextAction" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.NextAction" class="text-danger"></span>
</div>
</div>
</div>
</div>
<div class="row col-12">
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.WebAddress" class="control-label float-left">URL</label>
</div>
<div class="col-9">
<input asp-for="Lead.WebAddress" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.WebAddress" class="text-danger"></span>
</div>
</div>
</div>
<div class="col-6">
<div class="form-group">
<div class="col-3">
<label asp-for="Lead.ContactName" class="control-label float-left">Contact</label>
</div>
<div class="col-9">
<input asp-for="Lead.ContactName" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.ContactName" class="text-danger"></span>
</div>
</div>
</div>
</div>
<div class="row col-12">
<div class="col-6">
<div class="form-group text-left">
<div class="col-3">
<label asp-for="Lead.Where" class="control-label float-left">Address</label>
</div>
<div class="col-9">
<input asp-for="Lead.Where" class="form-control mb-2" style="width:100%" />
<span asp-validation-for="Lead.Where" class="text-danger"></span>
</div>
</div>
</div>
</div>
<div class="row col-12">
<div class="col-12">
<div class="form-group">
<div class="col-1 mr-0 pr-0">
<label asp-for="Lead.Notes" class="control-label col-3 float-left"></label>
</div>
<div class="col-8">
<input asp-for="Lead.Notes" class="form-control mb-2 ml-5" style="width:100%" />
<span asp-validation-for="Lead.Notes" class="text-danger"></span>
</div>
<div class="col-2 ml-5 float-right">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</div>
</div>
#*<div class="form-group col-1 offset-11">
<input type="submit" value="Save" class="btn btn-primary" />
</div>*#
I can add the page model in if anyone needs it, but I don't think it's relevant, and the css is the standard bootstrap.
So..... as you can see, the majority of the form is in two columns, but the last field (Notes) takes up more of the screen width. Because of this, I can't get the label or the entry field for Notes to line up with the previous fields. I've tried fiddling about with margins and padding, but I can't get an exact line up. It feels like I need to be able to ask Bootstrap for a width of a fractional column.
Is there a way of getting this last field laid out so it aligns with the previous ones?
Any input gratefully received.
Nick
You use col-3 in <div class="col-6">,so you need to set col-1.5 in <div class="col-12">,but there is no col-1.5,so you can only try to set the css and make it close to col-1.5:
<div class="row col-12">
<div class="col-12">
<div class="form-group">
<div class="col-md-1" style="flex: 0 0 12.15%;max-width: 12.15%;">
<label asp-for="Lead.Notes" class="control-label float-left"></label>
</div>
<div class="col-8">
<input asp-for="Lead.Notes" class="form-control mb-2 ml-5" style="width:100%" />
<span asp-validation-for="Lead.Notes" class="text-danger"></span>
</div>
<div class="col-2 ml-5 float-right">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</div>
</div>
result:
Can anybody tell how to arrange horizontal text box in same row eve though label will be in different line
<div class="row">
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label class="control-label">Roll number <br> Student Code:</label>
<input type="text" class="form-control">
</div>
<div class="text-required> This is required </div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label">School code:</label>
<input type="text" class="form-control ">
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label>Year Of Passing:</label>
<input type="text" class="form-control">
</div>
</div>
</div>
You can add w-50 d-inline-block class to input and w-25 to label as below
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row">
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label class="control-label w-25">Roll number <br> Student Code:</label>
<input type="text" class="form-control w-50 d-inline-block">
</div>
<div class="text-required> This is required </div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label class="w-25">School code:</label>
<input type="text" class="form-control w-50 d-inline-block">
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="form-group">
<label class="w-25">Year Of Passing:</label>
<input type="text" class="form-control w-50 d-inline-block">
</div>
</div>
</div>
You can wrap input in a div with col-x attribute and add row class to form-group.
An example:
<div class="form-group row">
<label class="control-label col-4">Roll number <br> Student Code:</label>
<div class="col-6">
<input type="text" class="form-control">
</div>
</div>
The full example here:
https://stackblitz.com/edit/js-bootstrap-css?file=index.html
<div class="row">
<div class="col-12">
<div class="form-group row">
<label class="control-label col-4">Roll number <br> Student Code:</label>
<div class="col-6">
<input type="text" class="form-control ">
</div>
</div>
<div class="text-required> This is required </div>
</div>
<div class="col-sm-3 col-lg-4">
<div class="form-group row">
<label class="control-label col-4">School code:</label>
<div class="col-6">
<input type="text" class="form-control ">
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-lg-4">
<div class="form-group row">
<label class="control-label col-4">Year Of Passing:</label>
<div class="col-6">
<input type="text" class="form-control">
</div>
</div>
</div>
</div>
Here below is my code:
<div class="modal-body-scrolled border-primary border-bottom p-0 mt-2">
<div class="form-row">
<div class="col-12">
<div class="row ml-0 mr-0">
<div class="row form-inline col-12 mt-2 mb-2 pt-2 pb-2 m-0">
<div class="row col-12 mb-2">
<div class="col-2 spacer"></div>
<div class="col-10 pl-0 d-inline">
<input type="text" class="form-control form-control-sm d-inline" style="width: 40px;"> <label class="col-form-label col-form-label-sm d-inline"> days </label>
</div>
</div>
</div>
</div>
</div>
<div class="col-12">
<div class="row ml-0 mr-0 mb-3">
<label for="date" class="col-2 pl-0 justify-content-start align-items-start">Event:</label>
<select type="field" class="form-control form-control-sm ml-2" style="width:500px" v-model="keyEvent">
<option value="" disabled selected>(select)</option>
</select>
</div>
<div class="row ml-0 mr-0 mb-3">
<label for="date" class="col-2 pl-0 justify-content-start align-items-start">Date:</label>
<div class="col-2 pl-0 d-inline">
<input class="form-control">
</div>
</div>
</div>
</div>
</div>
I'm using the standard Bootstrap 12-column layout, with the first column set as col-2 and the second column set as col-10.
I thought that would mean my elements exactly left align but they don't.
How do I get the elements to left align / sit flush with each other?
<div>
<div class="row mb-1">
<div class="col-2"></div>
<div class="col-10"> <input type="text" class="form-control form-control-sm d-inline" style="width: 40px;"> <label class="col-form-label col-form-label-sm d-inline"> days </label>
</div>
</div>
<div class="row mb-1">
<div class="col-2">
<label for="date" class="">Event:</label>
</div>
<div class="col-10">
<select type="field" class="form-control form-control-sm" style="width:500px" v-model="keyEvent">
<option value="" disabled selected>(select)</option>
</select>
</div>
</div>
<div class="row mb-1">
<div class="col-2">
<label for="date" class="">Date:</label>
</div>
<div class="col-10">
<input class="form-control" style="width: 140px">
</div>
</div>
</div>
Try this structure, this is simple and short, will help you too
we can write it like this with much more simpler way,
just use normal grid classes, you are making your markup too complicate
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" style="padding: 20px;">
<div class="row mb-3">
<div class="col-2">
<label class="label">Label</label>
</div>
<div class="col-10">
<input class="form-control" style="width:100px;display:inline-block;" />
<label class="label" style="display:inline-block;">days</label>
</div>
</div>
<div class="row mb-3">
<div class="col-2">
<label class="label">Label</label>
</div>
<div class="col-10">
<select type="field" class="form-control">
<option value="" disabled selected>(select)</option>
<option value="" >option 1</option>
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-2">
<label class="label">Label</label>
</div>
<div class="col-10">
<input class="form-control" style="width:100px;display:inline-block;" />
</div>
</div>
</div>
Changed the structure:
col-2 as you mentioned will have the label
col-8 will have the inputs
Make sure to wrap col in their respective row
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modal-body-scrolled">
<div class="container">
<div class="row">
<div class="col-2">
Label
</div>
<div class="col-8">
<input type="text" class="form-control form-control-sm d-inline" style="width: 40px;"> <label class="col-form-label col-form-label-sm d-inline"> days </label>
</div>
</div>
<div class="row">
<div class="col-2">
Event:
</div>
<div class="col-8">
<select type="field" class="form-control form-control-sm" style="width:500px" v-model="keyEvent">
<option value="" disabled selected>(select)</option>
</select>
</div>
</div>
<div class="row">
<div class="col-2">
Date:
</div>
<div class="col-8">
<div class="col-2 pl-0 d-inline">
<input class="form-control">
</div>
</div>
</div>
</div>
</div>