Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
How can I make an icon inside of a bootstrap 5 form-floating label clickable?

I'd like to have a clickable icon as part of a form-floating label but the label seems to be rendered behind the input.

I tried playing with z-index without any luck and I'm not sure what else I can do to fix the problem. Could someone point me in the right direction?

https://blazorfiddle.com/s/y4143uso

Screenshot of the example cols from the fiddle

The "Test" button and icon on its own (col#3, col#4) work, but the first two col's with form-floating examples won't redirect when the icon is clicked.

@page "/"
@inject NavigationManager NavigationManager

<div class="container-fluid">
    <div class="row">
        <div class="col-1">
            <div class="form-floating">
                <input type="text" class="form-control" placeholder="bla">
                <label>LABEL<i class="fas fa-info-circle ps-1" @onclick="Test"></i></label>
            </div>
        </div>
        <div class="col-1">
            <div class="form-floating">
                <input type="text" class="form-control" value="blabla">
                <label>LABEL<i class="fas fa-info-circle ps-1" @onclick="Test"></i></label>
            </div>
        </div>
        <div class="col-1">
            <button type="button" class="btn btn-sm btn-primary" @onclick="Test">Test</button>
        </div>
        <div class="col-1">
            <i class="fas fa-info-circle ps-1" @onclick="Test"></i>
        </div>
    </div>
</div>
@code {
    void Test()
    {
        NavigationManager.NavigateTo("https://google.com");
    }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have to handle pointer-events belong to child labels. If a click event does not occur, firstly you should think about pointer-events.

.clickable-icon{
    pointer-events: auto !important; // required
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<div class="container my-2">
    <div class="form-floating">
  <input type="text" class="form-control" id="floatingInput" placeholder="Click Icons" value="Click Icons">
  <label for="floatingInput">Clickable Icon <label class="clickable-icon" onclick="alert('hello')">&#128512;</label> <label class="clickable-icon ms-1" onclick="alert('clicked')">&#x26A1;</label></label>
</div>
</div>

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!