Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

286
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda