Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set border of another element when an input control has focus?

I have a form with various input controls set up like this:

<div class="form-group mb-3">
    <div class="input-group">
        <input asp-for="Email" class="form-control" />
        <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-envelope"></span>
            </div>
        </div>
    </div>
    <small>
        <span asp-validation-for="Email" class="text-danger"></span>
    </small>
</div>

And I have a SCSS file that changes the border width on active and focus:

.form-control:focus,
.form-control:focus:active  {
    border-width: $input-focus-width !important;
}

Currently I’m getting this result:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Inputcontrol

How can I set the border with of the input-group-text element when the input control is active?

>Solution :

You can handle the element immediately placed after .form-control with the following selector:

.form-control:focus + .input-group-append .input-group-text

In your case:

.form-control:focus,
.form-control:focus:active,
.form-control:focus + .input-group-append .input-group-text {
    border-width: 2px !important;
}
<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="form-group mb-3">
    <div class="input-group">
        <input asp-for="Email" class="form-control" />
        <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-envelope">icon</span>
            </div>
        </div>
    </div>
    <small>
        <span asp-validation-for="Email" class="text-danger"></span>
    </small>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading