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
Related
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<body class="grey darken-4">
<div class="container">
<div class="row">
<!-- I have tried adding center, center-align as a class to div tags but it in correctly formats. My form elements to the center which was not what I except -->
<div class="col s12 m6 l10">
<!-- adding center, center- align to the row still doesn't fix the issues still -->
<div class="card">
<div class="card-content">
<span class="card-title center ">Loan Calculator</span>
<form action="">
<div class="input-group">
<div class="input-field">
<span>$</span>
<input type="number" class="form-control" placeholder="Amount">
</div>
<div class="input-field">
<span>%</span>
<input type="number" class="ïnput-field" placeholder="Loan" class="form-control">
</div>
<div class="input-field">
<input type="number" class="form-control" placeholder="Years To Pay">
</div>
<div class="center">
<input type="submit" value="CALCULATE" class="btn black">
</div>
<h5 class="text-darken-3 center " id="result">Results</h5>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
I don't know if this is a current issue with Materialize CSS itself.
My goal is to properly format the card so that it has 6 columns for medium display. However, the card, when resized to small width, behaves in a erratic manner (the content is aligned to the left, and the space on the right is left empty).
The cause of the "issue" (I would say it is by-design) is the combination of float: left; and margin-left: auto; with no margin-right: auto; rules applied for columns with .col.m* classes. Because of this, columns are always snapped to the left of the containing row.
If you want to override this to center your column, you need to specify an offset. What Materialize CSS Grid (implemented with float) expects you to do is to express that the column taking ½ of the containing row width should be offset by 6 divided by 2 columns on both sides (aka "centered").
Offsets in Materialize CSS are provided with the offset-* set of classes. In your case, you only need the offset-m* and offset-l* subsets. Let's take a look:
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<body class="grey darken-4">
<div class="container">
<div class="row">
<!-- I have tried adding center, center-align as a class to div tags but it in correctly formats. My form elements to the center which was not what I except -->
<div class="col s12 m6 l10 offset-m3 offset-l2">
<!-- adding center, center- align to the row still doesn't fix the issues still -->
<div class="card">
<div class="card-content">
<span class="card-title center ">Loan Calculator</span>
<form action="">
<div class="input-group">
<div class="input-field">
<span>$</span>
<input type="number" class="form-control" placeholder="Amount">
</div>
<div class="input-field">
<span>%</span>
<input type="number" class="ïnput-field" placeholder="Loan" class="form-control">
</div>
<div class="input-field">
<input type="number" class="form-control" placeholder="Years To Pay">
</div>
<div class="center">
<input type="submit" value="CALCULATE" class="btn black">
</div>
<h5 class="text-darken-3 center " id="result">Results</h5>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
There are two blocks with content in them and one small span text between of them at the top. I need this span to have some static width like 20px (it's col-2 in the example) and this two blocks to split the rest of the free space.
Is this possible with bootstrap classes?
Here is some code: https://jsfiddle.net/Alexik/krexqp5m/1
some shorter in place:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row">
<div class="left-player d-inline-block col-5">
<div class="input-group mb-2">
<select class="form-control"></select>
</div>
<div class="input-group mb-2">
<select class="form-control w-25"></select>
<select class="form-control"></select>
<span class="input-group-text">
<input type="checkbox">
</span>
</div>
</div>
<span class="d-inline-block align-top col-2 text-center">VS</span>
<div class="right-player d-inline-block col-5">
<div class="input-group mb-2">
<select class="form-control"></select>
</div>
<div class="input-group mb-2">
<select class="form-control w-25"></select>
<select class="form-control"></select>
<span class="input-group-text">
<input type="checkbox">
</span>
</div>
</div>
</div>
you can display flex property here
steps
set the tag inside with all the 2 divs and span are to display: flex; in my case it was body
give flex-grow to both the divs
give width to your span
css:
body
{
display: flex;
}
div
{
flex-grow: 100;
background-color: rgb(128, 122, 118);
}
span
{
width: 20px;
}
html:
<div>
this is div one
</div>
<span>
vs
</span>
<div>
this is div two
</div>
output
I don't think bootstrap classes will work here since, their grid is divided into 12.
With bootstrap I don't think you can do that, because it wont allow you to define exact size of that span but yes with CSS flex you can easily do that.
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;
}
In my application, I am using bootstrap-tagsinput angular version (in smartadmin) which looks like this
code for bootstrap input tag:
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label>Type and enter to add an SMA</label>
<input smartTags class="form-control tagsinput" value="{{tagsValues}}" data-role="tagsinput">
</div>
</div>
</div>
I am using this in my dashboard inside widget as a widget toolbar in dropdown popover
dashboard.component.html
<div class="widget-toolbar">
<div class="btn-group dropdown dropdown-large" dropdown>
<a class="button-icon" title="SMA Filter" dropdownToggle aria-expanded="true">
<i class="fa fa-cog"></i>
</a>
<div class="dropdown-menu dropdown-menu-large filterDropwdownViewAlign" (click)="$event.stopPropagation()">
<div id="checkout-form" class="smart-form">
<header id="filterHeader">SMA</header>
<fieldset>
<form>
<div class="row form-group">
<section class="col col-xs-12">
<label class="form-control" style="border:0px;height:auto">
<input id="smartTagInput" smartTags class="form-control tagsinput" value="{{smaValues}}" data-role="tagsinput">
</label>
</section>
</div>
</form>
</fieldset>
</div>
</div>
</div>
</div>
I have applied css properties to the popover
.filterFormAlign {
margin-bottom: 0px !important;
margin-top: 0px !important;
padding-right: 0px !important;
}
.filterFormAlignToggle{
padding-left: 0px !important;
}
.filterDropwdownViewAlign {
margin: 35px 0 0;
top: 3px;
padding: 0px !important;
}
#media only screen and (min-width:768px) {
.filterDropwdownViewAlign {
min-width: 335px !important;
left: -296px !important;
}
}
#media only screen and (max-width: 479px) and (min-width: 320px) {
.filterDropwdownViewAlign {
min-width: 310px !important;
left: -255px !important;
}
}
That bootstrap input tags element is not looking in this popover as I showed in the image above.
Maybe it is coming because of that css properties that is inherited by this input field also. So is there any way that those css properties will not be inherited by the input tag or element inside the form
Seems like you have an overwrite of css definition which is making <input> element display block instead of floated / inline.
I don't know if this is the solution but looking at the differences between the 2 cases I would suggest to close the <label> tag before the <input> element and not after input element, something like:
<label class="form-control" style="border:0px;height:auto">
</label>
<input id="smartTagInput" smartTags class="form-control tagsinput" value="{{smaValues}}" data-role="tagsinput">
And the whole snippet:
<div class="widget-toolbar">
<div class="btn-group dropdown dropdown-large" dropdown>
<a class="button-icon" title="SMA Filter" dropdownToggle aria-expanded="true">
<i class="fa fa-cog"></i>
</a>
<div class="dropdown-menu dropdown-menu-large filterDropwdownViewAlign" (click)="$event.stopPropagation()">
<div id="checkout-form" class="smart-form">
<header id="filterHeader">SMA</header>
<fieldset>
<form>
<div class="row form-group">
<section class="col col-xs-12">
<label class="form-control" style="border:0px;height:auto">
</label>
<input id="smartTagInput" smartTags class="form-control tagsinput" value="{{smaValues}}" data-role="tagsinput">
</section>
</div>
</form>
</fieldset>
</div>
</div>
</div>
</div>
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; }