Bootstrap input-group-prepend/addon width adjustment - html

I'm having issues making prepend add-ons the same width. I'm using Font Awesome icons and the prepend is sized to each specific icon. I found another thread from about a year ago describing my exact problem, but there wasn't an answer.
Bootstrap4 make all input-group-addons same width
Here's a screenshot of my issue:
I tried using various CSS tweaks with no luck, including the one provided in that aforementioned thread.
Relevant HTML:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row body-main-bg">
<div class="col-sm-4 my-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-user"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Name">
</div>
</div>
</div>
<div class="row body-main-bg">
<div class="col-sm-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-envelope"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Email">
</div>
</div>
</div>
<div class="row body-main-bg">
<div class="col-sm-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-ellipsis-v"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Subject">
</div>
</div>
</div>
<div class="row body-main-bg">
<div class="col-sm-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-pencil"></span>
</span>
</div>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Message"></textarea>
</div>
</div>
</div>

I tried your same code snippet, with just some css tweaks it works for me.
I just added the following css,
Please use this css, this will solve your prepend/addon width issue.
.input-group-text {
width: 40px;
}
.input-group-text span {
margin: 0 auto;
}
Here is also the url to the snippet as well,
bootstrap-input-group-prepend-addon-width-issue

I think the easiest answer with this is css grid.
.wrapper
{
display:grid;
grid-template-rows: repeat(3,1fr) 2fr;
grid-template-columns: 15% 85%;
grid-row-gap:1rem
}
Then assign icons to the first column and inputs to the second one.
Hope this answered your problem.

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet" />
<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="modal-body" id="m_cr_body">
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend w-25">
<span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-camera fa-fw"></i> Photographer</span>
</div>
<input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend w-25">
<span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-paint-brush fa-fw"></i> Edit</span>
</div>
<input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend w-25">
<span class="input-group-text w-100" id="inputGroup-sizing-sm"><i class="fas fa-ruler-vertical fa-fw"></i> Rule</span>
</div>
<input type="text" class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
</div>
</div>
</div>

Related

How to use fa-plus-circle icon next to a text field using CSS and HTML?

I want to use fa-plus-circle item next to the text field as below. How can I achieve that using CSS and HTMl. I haven't use any CSS right now since it's affecting to all the other places that using fa-plus-circle.
.html
<div class="col-sm-6">
<label class="col-sm-3 col-form-label" >My Name <span class="fa fa-star required-field"></span> </label>
<input type="text" class="form-control"><span
class="fa fa-plus-circle text-success cursor-point"></span>
</div>
https://getbootstrap.com/docs/5.0/forms/input-group/
You can use input group for this
<div class="input-group mb-3">
<input type="text" class="form-control">
<span class="input-group-text">
<span class="fa fa-plus-circle text-success cursor-point"></span>
</span>
</div>
Try This way
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.0/css/font-awesome.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-sm-6">
<div class="d-flex align-items-center">
<div class="flex-fill">
<input type="text" class="form-control">
</div>
<span class="ml-3 fa fa-plus-circle text-success cursor-point"></span>
</div>
</div>

Vertical scroll is not working in my app in angular 10

I have this template from angular 10. The problem is the scrollbar doesn´t work even if I add the css style on the main container overflow: auto;
The HTML and scss codes are as following, as you can see I include the overflow property to the main container "cont", but is not working:
Anyone can help with this? Thank you!
.cont{
overflow: auto;
}
<div class="cont">
<div class="card-body">
<form name="formEmpresa">
<div class="container-background">
<div class="container-fluid">
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<div class="input-group flex-nowrap">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping"><i class="fa fa-building"></i></span>
</div>
<input type="text" class="form-control" placeholder="J123456789" name="Rif" required>
</div>
</div>
<div class="col-sm-6"></div>
<div class="col-sm-12">
<hr style="border: none">
<div class="input-group flex-nowrap">
<span class="input-group-text" id="addon-wrapping"><i class="fa fa-institution"></i></span>
<input type="text" class="form-control" placeholder="Razón Social" name="Razosoci" required ng-maxlength="150">
</div>
</div>
<div class="col-sm-12">
<hr style="border: none">
<label>Dirección fiscal</label>
<textarea class="form-control" rows="3" placeholder="Entre ..." name="Dir" ng-maxlength="200" required></textarea>
</div>
<div class="col-sm-12">
<hr style="border: none">
<div class="row justify-content-center">
<button class="btn btn-warning" style="width: 20%;">
<i class="fa fa-plus-circle" style="color: white;"></i> <h5 style="color: white;"><strong>Añadir sucursal</strong></h5>
</button>
</div>
</div>
<div class="col-sm-12">
<hr style="border: none">
<div class="card">
<div class="card-header" style="background-color: #ffc107; color: white;">
<strong>Nueva surcursal</strong>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-12">
<div class="input-group flex-nowrap">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping"><i class="fa fa-building"></i></span>
</div>
<input type="text" class="form-control" placeholder="Nombre Sucursal" name="sucursal" required>
</div>
</div>
<div class="col-sm-6">
<hr style="border: none">
<div class="input-group flex-nowrap">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping"><i class="fa fa-phone"></i></span>
</div>
<input type="text" class="form-control" placeholder="Teléfono" name="phone" required>
</div>
</div>
<div class="col-sm-6">
<hr style="border: none">
<div class="input-group flex-nowrap">
<div class="input-group-prepend">
<span class="input-group-text" id="addon-wrapping"><i class="fa fa-qrcode"></i></span>
</div>
<input type="text" class="form-control" placeholder="Código Postal" name="postal_code" required>
</div>
</div>
<div class="col-sm-12">
<hr style="border: none">
<textarea class="form-control" rows="3" placeholder="Dirección" name="Dir" ng-maxlength="200" required></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
You need to give some height to .cont class to add scroll to that div.

Issue with Input element shrinking too much as browser resizes

I have a contact form (a bunch of input/span elements) nested in a Boostrap col. As the browser shrinks, the input fields shrink to an undesirable size.
I have tried adding various col-breakpoints, which sort-of works, but it looks funky and still shrinks too much until it hits the breakpoint. I have also looked for a way to specify a min-width of sorts, but haven't had luck with that either.
<!-- Custom CSS -->
.input-group-text {
width: 40px;
}
.input-group-text span {
margin: 0 auto;
}
.body-main-bg {
background-color: #eeeeee;
}
<!-- Contact Form -->
<div class="container-fluid">
<div class="row body-main-bg justify-content-center">
<div class="col-4 my-3 text-center">
<h4>Contact Us</h4>
</div>
</div>
<form id="contact-form" method="" action="">
<div class="row body-main-bg justify-content-center">
<div class="col-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-user"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Name">
</div>
</div>
</div>
<div class="row body-main-bg justify-content-center">
<div class="col-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-envelope"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Email">
</div>
</div>
</div>
<div class="row body-main-bg justify-content-center">
<div class="col-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-ellipsis-v"></span>
</span>
</div>
<input type="text" class="form-control" placeholder="Subject">
</div>
</div>
</div>
<div class="row body-main-bg justify-content-center">
<div class="col-4 mb-3">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-pencil"></span>
</span>
</div>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Message"></textarea>
</div>
</div>
</div>
<div class="row body-main-bg justify-content-center">
<div class="col-4 mb-3">
<button class="btn btn-primary btn-block" type="submit">Submit</button>
</div>
</div>
</form>
</div>
If you change col-4 to col-lg-4 or col-md-4 you will have the desired layout.
The issue is that with col-4 you are essentially saying "stay this width on all devices". When col-lg-4 or col-md-4 are responsive and set divs to be 100% on large/medium devices and down.
See bootstraps grid options here: https://getbootstrap.com/docs/4.3/layout/grid/

How to make a Bootstrap input-group look like a form-group

I'm trying to make the last row look exactly like the others, but with the icon appended to the text box. I can't seem to get the width right!
(I apologize... I don't know how to make the code snippet render properly in this page. You have to view full screen.)
<link href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row justify-content-md-center">
<div class="col-sm-3">
<div class="form-group row">
<label>Name:</label>
<input type="text" class="form-control" />
</div>
<div class="form-group row">
<label>Date From:</label>
<input type="text" class="form-control" />
</div>
<div class="input-group row">
<label>Date To:</label>
<input type="text" class="form-control" />
<div class="input-group-append">
<div class="input-group-text" id="btnGroupAddon2">
<i class="fa fa-search" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>
Retain the form group of the div above "Date to:" label, then you can insert a div wrapping the input and image div's and add the input-group class which will produce the required result, please check my below example!
<link href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row justify-content-md-center">
<div class="col-sm-3">
<div class="form-group row">
<label>Name:</label>
<input type="text" class="form-control" />
</div>
<div class="form-group row">
<label>Date From:</label>
<input type="text" class="form-control" />
</div>
<div class="form-group row">
<label>Date To:</label>
<div class="input-group">
<input type="text" class="form-control" />
<div class="input-group-append">
<div class="input-group-text" id="btnGroupAddon2">
<i class="fa fa-search" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
If you want to keep it to the left, it takes a bit of out of class work like so:
<link href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row justify-content-md-center">
<div class="col-sm-3">
<div class="form-group row">
<label>Name:</label>
<input type="text" class="form-control" />
</div>
<div class="form-group row">
<label>Date From:</label>
<input type="text" class="form-control" />
</div>
<div class="input-group row">
<label class="pt-2">Date To:</label>
<input type="text" class="form-control ml-2"
style="border-top-left-radius: .25rem;border-bottom-left-radius: .25rem;"/>
<div class="input-group-append">
<div class="input-group-text" id="btnGroupAddon2">
<i class="fa fa-search" aria-hidden="true"></i>
</div>
</div>
</div>
</div>
</div>

Why aren't my col-lg- shown full width?

After getting some help with alignment of my controls, I'm now struggling to fully understand, exploit and adopt that solution.
The current state of affairs can be played with here and the code is below:
<div class="row">
<div class="col-lg-8">
<div class="form-inline col-lg-4">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="oldpswd" name="oldpswd" placeholder="Altes Passwort" type="password" class="form-control">
</div>
</div>
</div>
<span id="oldpswd_errmsg" class="bg-danger col-lg-4">xxxx</span>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="form-inline col-lg-4">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="oldpswd" name="newpswd" placeholder="Neues Passwort" type="password" class="form-control">
</div>
</div>
</div>
<span id="newpswd_errmsg" class="bg-danger col-lg-4">xxxx</span>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="form-inline col-lg-4">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="reppswd" name="reppswd" placeholder="Passwort wiederholen" type="password" class="form-control">
</div>
</div>
</div>
<span id="reppswd_errmsg" class="bg-danger col-lg-4">xxxx</span>
</div>
</div>
Question: within the row there is a col-lg-8 that contains two col-lg-4 divs. As I understood the doc, the input-controls are supposed to take up the entire width of their containers, yet the form-group inside the col-lg-4 is significantly smaller than its container.
How can this layout be fixed so that the divs with designated col-lg- classes use the available space?
Updated
Addedd css to expand the form controls to expand with divs.
Is this what you want? http://www.bootply.com/y2K2OY8H1H
You had a row, with a column of 8, with two columns of 4 inside that. So the col-8 fills 8 of the 12 main columns. Then the 2 col-4 inside of that only fill 8 of the 12 inside that col-8. So each time you nest the col's you create nested columns. It is a little confusing, but makes sense.
NEW CSS:
.form-group {
width:100%;
}
.input-group {
width:100%;
}
-
<div class="row">
<div class="col-md-2">
<div class="form-inline">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="oldpswd" name="oldpswd" placeholder="Altes Passwort" type="password" class="form-control">
</div>
</div>
</div>
</div>
<span id="oldpswd_errmsg" class="bg-danger col-lg-3">xxxx</span>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-inline">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="oldpswd" name="newpswd" placeholder="Neues Passwort" type="password" class="form-control">
</div></div>
</div>
</div>
<span id="newpswd_errmsg" class="bg-danger col-lg-3">xxxx</span>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-inline">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><span class="fa fa-key fa-fw"></span></div>
<input id="reppswd" name="reppswd" placeholder="Passwort wiederholen" type="password" class="form-control">
</div></div>
</div>
</div>
<span id="reppswd_errmsg" class="bg-danger col-lg-3">xxxx</span>
</div>