aligning text box label with the text box - html

I'm using bootstrap. I want the text labels for the inputs to be aligned left of the text boxes edge, not above in the center as they are now.
Is this something that is done with bootstrap?
EDIT: Sorry the code snippet did not show my problem properly so i redid it in jsFiddle.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="text-center col-xs-12 ">
<div class="row">
</div>
<div class="row ">
<div class="col-xs-6 ">
<label for="companyInput">LABEL</label>
<br />
<input id="companyInput" type="text">
</div>
<div class="col-xs-6 ">
LABEL
<br />
<input id="cardInput" type="text" />
</div>
</div>
</div>

EDIT:
I updated your fiddle, here - https://jsfiddle.net/Lfmxt3kv/1/
If you have to have text-center on the parent container, then you'll need a wrapper div around your label and input element. Here are the changes I made to the fiddle:
<div class="text-center col-xs-12">
<div class="row ">
<div class="col-xs-6 ">
<!-- .input-wrapper needs to be wrapped around both the label and input element -->
<div class="input-wrapper">
<label for="companyInput">LABEL</label>
<input id="companyInput" type="text">
</div>
</div>
<div class="col-xs-6 ">
<div class="input-wrapper">
<label for="cardInput">LABEL</label>
<input id="cardInput" type="text" />
</div>
</div>
</div>
</div>
.input-wrapper {
display: inline-block;
text-align: left;
}
.input-wrapper label {
display: block;
}
Just adding text-left looks like it works.
<div class="col-sm-6 text-left">
LABEL ONE
<br />
<input id="companyInput" type="text" placeholder="Företag... (1-100)">
</div>

you are looking for Bootstrap forms
Individual form controls automatically receive some global styling.
All textual <input>, <textarea>, and <select> elements with
.form-control are set to width: 100%; by default. Wrap labels and
controls in .form-group for optimum spacing.
For what you want, you need to display:inline-block the .form-group and add class text-left to align left because .container has text-center
Snippet
.form-group {
display: inline-block
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="text-center container">
<div class="row">
<div class="col-xs-12">
<form class="form">
<div class="form-group text-left">
<label for="companyInput">Company</label>
<input class="form-control" id="companyInput" type="text" placeholder="Företag... (1-100)">
</div>
<div class="form-group text-left">
<label for="cardInput">Card</label>
<input class="form-control" id="cardInput" type="text" placeholder="Kort... (1-100)" />
</div>
</form>
</div>
</div>
</div>

for a quick fix you could add a class to the div..
<div class="textalign col-span-6">
then in css just do
.textalign { text-align: left; }

Related

HTML add bootstrap check inside input readonly

I'm using bootstrap inside of my app on which I have a readonly input where I need to add checkmark inside of it. I tried to add simple <input readonly type="text" id="kyc_status" class="form-control" value="Success"> but this won't work. Below is my HTML structure:
<div class="card">
<div class="card-body">
<form>
<div class="row mb-3">
<div class="col">
<label for="kyc_status" class="form-label">
KYC Status
</label>
<input readonly type="text" id="kyc_status" class="form-control" value="Success">
<i class="bi bi-check"></i>
</div>
</div>
</form>
</div>
</div>
So now it produces me:
How to put this checkmark inside of the input on the left ?
You can use .input-group and adjust styling of .input-group-text for your needs.
Below, I have added .border-end-0, .bg-transparent, and .pe-0 to the .input-group-text and .border-start-0 to the input.form-control.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.9.1/font/bootstrap-icons.css">
<div class="card">
<div class="card-body">
<form>
<div class="row mb-3">
<div class="col">
<label for="kyc_status" class="form-label">
KYC Status
</label>
<div class="input-group">
<span class="input-group-text border-end-0 bg-transparent pe-0"><i class="bi bi-check"></i></span>
<input readonly type="text" id="kyc_status" class="form-control border-start-0" value="Success">
</div>
</div>
</div>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
I put both in a div tag and then gave the position.
Note: I have given color, width and height to the icon tag so that it can be seen. For testing.
You can use the following code. The style is also written.
<div class="card">
<div class="card-body">
<form>
<div class="row mb-3">
<div class="col">
<label for="kyc_status" class="form-label">
KYC Status
</label>
<div class="pos">
<input readonly type="text" id="kyc_status" class="form-control" value="Success">
<i class="bi bi-check"></i>
</div>
<style>
.pos {
position: relative;
}
.bi-check {
width: 5px;
height: 4px;
background: red;
position: absolute;
top: 50%;
left: 3px;
}
</style>
</div>
</div>
</form>
</div>
</div>
Exactly like this:
You can use position absolute property on checked icon and move it over the input field.
steps
wrap input element and icon tag in one division with style property positions relative.
then
for input use below property
padding-left 20px
then
for icon use below properties
position absolute
left 10px - adjust according your inputs field size
top 5px - adjust according your inputs field size

Offset & Center Container w/Bootstrap

Im trying to center the header and input field with bootstrap. I cant get the input field to center with the header. If anyone has a better way of doing this let me know.
<div class="container">
<div class="row">
<div class="col-md-6">
<h1 class="display-4 text-center">Weight Converter</h1>
<form>
<div class="form-group">
<input
id="lbsInput"
type="number"
class="form-control form-control-lg"
placeholder="Enter Weight..."
/>
</div>
</form>
<div id="output">
<div class="card">
<div class="card-block">
<h4>Grams:</h4>
<div id="gramsOutput"></div>
</div>
</div>
</div>
</div>
</div>
</div>
you have incomplete HTML and no CSS. But based on what you have, a simple margin: auto; in CSS should center the element for you.
If you want more control you should look into flexbox. post more code and you'll get more help.
EDIT: thanks for the code: this works to center the input. I just verified it. let me know if you need any more help. cheers
<div class="container">
<div class="row">
<div class="col-md-6">
<h1 class="display-4 text-center">Weight Converter</h1>
<form>
<div class="form-group" id="centerParent">
<input
id="lbsInput"
type="number"
class="form-control form-control-lg"
placeholder="Enter Weight..."
/>
</div>
</form>
<div id="output">
<div class="card">
<div class="card-block">
<h4>Grams:</h4>
<div id="gramsOutput"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
#centerParent {
display: flex;
flex-direction: row;
justify-content: center;
}
</style>

CSS Selector For Last Element With Class Within Element With Class

I'm using bootstrap and I have placed my inputs within their own .form-group. All my inputs are also contained within a div with a .well class.
I want to remove the default margin-bottom:15px that bootstrap has for .form-group but only if its the last instance of .form-group within its parent .well div.
<div class="well">
<div class="form-group">
<div class="col-md-6">
<div class="form-group">
<label class="m-b-none">Name</label>
<div class="input-group">
<input class="form-control" name="Name">
<div class="input-group-addon"><i class="fa fa-check-circle"></i></div>
</div>
</div>
<div class="form-group">
<label class="m-b-none">Surname</label>
<div class="input-group">
<input class="form-control" name="Surname">
<div class="input-group-addon"><i class="fa fa-check-circle"></i></div>
</div>
</div>
</div>
</div>
So I want to remove set the margin-bottom to 0px on the last form-group within each of the elements with the class well.
I tried the below code but it just applied the style to all .form-groups
.well .form-group:last-of-type {
margin-bottom: 0!important;
}
.well .form-group:last-of-type {
margin-bottom: 0 !important;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="well">
<div class="form-group">
<input/>
</div>
<div class="form-group">
<input/>
</div>
</div>
<div class="well">
<div class="form-group">
<input/>
</div>
<div class="form-group">
<input/>
</div>
</div>
A solution would be to use bootstrap for this. mb-0 is a bootstrap utility class to set the margin-bottom to 0.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="well">
<div class="form-group">
<input/>
</div>
<div class="mb-0 form-group">
<input/>
</div>
</div>
<div class="well">
<div class="form-group">
<input/>
</div>
<div class="mb-0 form-group">
<input/>
</div>
</div>
More on mb-0: What is class=“mb-0” in Bootstrap 4?
The CSS selector I was trying actually works. The HTML is produced using some C# extension methods and I hadn't realised all the inputs were being wrapped in a .form-group div. The CSS selector would have seen that as the last-of-type for the .well. Once I removed this div the selector worked.
.well .form-group:last-of-type {
margin-bottom: 0!important;
}
If you don't want to add a class, You can also do this directly with the :last-child selector.
.well .form-group:last-child {
margin-bottom: 0!important;
}
You can Use > to specify the next child of .well of type div
.well > div.form-group:last-child {
margin-bottom: 0 !important;
}

Bootstrap Button and input box , side by side

Can anybody please advise/correct me how to align or arrange the button and input box side by side without grouping in bootstrap.
I had searched few examples in the internet which are only in grouping of elements.
jsfiddle: https://jsfiddle.net/erama035/p9dagmL3/3/
<div class="container">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<button class="btn btn-default col-sm-2 col-md-2">add</button>
<input class="form-control col-md-3 col-sm-2"/>
</div>
<div class="col-xs-7 col-sm-7 col-md-7">
<button class="btn btn-default col-md-2">remove</button>
<input class="form-control col-md-5"/>
</div>
</div>
</div>
The quick way would be, to simply use Flexbox for the parent <div>. This converts the child elements to flex items, which are arranged side by side by default.
.container > .row > div {
display: flex;
}
The proper way would be to use Bootstraps predefined classes for grouping.
.container>.row>div {
display: flex;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-xs-5 col-sm-5 col-md-5">
<button class="btn btn-default">add</button>
<input class="form-control" />
</div>
<div class="col-xs-7 col-sm-7 col-md-7">
<button class="btn btn-default">remove</button>
<input class="form-control" />
</div>
</div>
</div>
for the cross-browser you can simple use inline-block
.btn,.form-control{display: inline-block; width: auto;}

Align Bootstrap columns from right to left to support RTL language

I am trying to design a form in arabic style. I have used a panel class. text field generally start from left side, but i want to design form from right to left.
.heading {
font-family: monospace;
font-size: 30px;
color: #0D91A5;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-12 ">
<center>
<h2 class="heading"> Registration</h2>
</center>
</div>
<div class="container" style="margin-top:30px">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-info" style="direction: rtl;">
<div class="panel-heading">
<h3 class="panel-title"><strong class="strong"> تفاصيل طالب | Executive Details</strong></h3>
</div>
<div class="panel-body">
<div class="row">
<div class=".col-sm-5 .col-md-6" style="direction: rtl;">
<div class="form-group col-md-12 ">
<div class="col-md-6 col-xs-12 col-xs-12 col-md-offset-6">
<input type="text" name="id_no" id="id_no" class="form-control" placeholder=" رقم| ID Number" tabindex="1">
</div>
<div class="col-md-6 col-xs-12 col-md-offset-0">
<input class="form-control" type="text" name="name" id="name" class="form-control" placeholder=" اسم| Name " tabindex="1">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
this is coding i am using class offset-6 for textfield start to right side but another textfiled with same grom starting from another line. i want box field in same line.
can anyone tell me which class i want to use? or can i change in bootsrap css file?
To design an RTL layout use Bootstrap RTL:
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-rtl.css" rel="stylesheet" />
Add bootstrap-rtl.css (after bootstrap.css file) and it will override all the CSS properties that are related to rtl support.