Is there a way to add a clickable icon to a form-floating label in Bootstrap 5?

I'm having trouble getting a clickable icon to work properly in a form-floating label. It seems that the label is being rendered behind the input field.

I've tried adjusting the z-index with no success, and I'm not sure what else to try to solve the issue. Can anyone offer some guidance on how to fix this problem?

The "Test" button and icon in its own column (col#3, col#4) are functioning correctly, but the first two columns with form-floating examples are not redirecting 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");
    }
}

Answer №1

When dealing with child labels, it is important to consider the pointer-events. If a click event is not registering, the first thing to check is the pointer-events property.

.clickable-icon{
    pointer-events: auto !important; // necessary
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="10727f7f64636462716050253e213e23">[email protected]</a>/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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to send props to a CSS module in React?

Currently utilizing NextJS, I have a route named about that is displayed through page.js. Within /about/page.js, I am incorporating a component called <Hero /> and aiming to pass a prop to <Hero heroHeight={'height: 400px'} /> to my C ...

Shift heading 1 as well as heading 2 to the image's right side

Is it possible to position <h1> and <h2> to the right of an image while ensuring that <h2> is displayed below <h1>? Any suggestions on how I can achieve this layout? This is my current code <html> <link rel="stylesheet" h ...

Nested accordions with Bootstrap 4.3 featuring plus and minus icons

I am trying to implement a nested accordion structure that displays plus and minus buttons when opening and collapsing each section. <div style="padding: 10px"> <div class="accordion" id="base-data"> &l ...

The map fails to load on the HTML page

I am struggling to load a map into my HTML page from a file located in the app folder. Despite using the correct code for inserting the map, it still does not load properly. <!-- Contact section start --> <div id="contact" class="contact"> ...

If I desire to utilize a particular font that I am aware is not readily accessible on the majority of users' computers

Is it possible to embed a specific font into my website if I know it's not commonly available on users' computers? I've seen some websites using unique fonts as text and not images, so I'm curious about how that is achieved. Thank you, ...

Tips for maintaining the webcam video in the center of the screen even when the height is set to 100% and the window is being resized

When using React, I encountered an issue with centering a webcam video while maintaining its height at 100% of the screen. Although the video fills the screen vertically correctly, adjusting the width of the window causes the video to lose its centered pos ...

Article with content surpassing the boundary of its parent container

I'm struggling to contain text within the parent's div as it keeps overflowing. I attempted using element.style { text-overflow: ellipsis; overflow: hidden; } but unfortunately, it didn't work. Take a look here at my JSFiddle link. It ...

Looking for a unique Full Screen Crosshair Cursor with either HTML5 or JQuery?

We've all seen that iconic military crosshair cursor in movies and animations. One example can be found at the beginning of a YouTube video titled "Dishonorable Disclosures" - https://www.youtube.com/watch?v=X-Xfti7qtT0 Another instance is with the ...

downloading responsive design

Using media queries to define backgrounds with separate images based on browser size: @media (min-width:1440px){div.container{background:URL('bg1440.png');}} @media (min-width:960px){div.container{background:URL('bg960.png');}} @media ...

The Silent Disregard for CSS Files in React Rendered Pages

I'm currently working on a React application that I created using create-react-app. In my index.html file, I have linked it to my CSS file like this: <link rel="stylesheet" href="../src/site.css"></link> The content of the site.css file ...

Incorporating SQLSRV results into clickable <td> elements: A dynamic approach

As a newcomer to the world of JS/PHP/web development, I'm seeking help with a seemingly simple task. My goal is to make each <td> element in a table clickable, and retrieve the text contained within the clicked <td>. Currently, I have a S ...

Eliminating white space - A CSS and HTML page with no room for gaps

After finally getting my website up and running using style.css, I am faced with the following CSS code: html { height:100%; } { position: relative; z-index: 0; width: 100%; left: 0; top: 0; cursor:default; overflow:visible; } body { ...

Using Jquery to Highlight the Background Image in a Circle

I currently have 3 images named back_about_1.jpg, back_about_2.jpg, and back_about_3.jpg. There is a div with the ID "about" - <div id="about"></div> The default background image of the div is set to back_about_1.jpg using CSS - background: u ...

Optimize Your Website for Various Screen Sizes

Can anyone assist with centering my webpage on small screen sizes? Everything looks good at the normal width of 989px, but once it shrinks, it shifts to the left and leaves excess white space on the right. I've tried various methods to correct this is ...

What steps can I take to ensure that a user only clicks on my voting link once for a specific post?

I am managing a MySQL database with two tables. One table is named 'users' with the column 'uname' as the primary key, which stores usernames as strings. The second table is named 'posts' with the column 'id' as the ...

Adjustable height within embedded object tag

I've been struggling to adjust the height of the content on my site automatically. I have attempted using iframes as well, but nothing seems to work despite trying numerous code examples from various sources including CSS and JS scripts. Any help wou ...

Sections overlap, extending the content beyond their designated boundaries

I am facing an issue where the header in the first section remains fixed as an attachment, but when I resize the browser window, the background only covers a small portion of the section. The rest of the content either goes under another section or complet ...

Expanding the Width of a Web Page with CSS on a Squarespace Website

Looking to adjust the width of my Squarespace website on the SKYE template to have minimal padding around images and content. Check out the website here using the password123. I've attempted to make changes with no success using the following code: ...

Using AngularJS to add external scripts to partials with ng-include

Why won't my main javascript files (located in index.html) work in the partials (such as page1.html)? For example, jQuery and syntax highlighting scripts are not functioning properly when I click on my menu items. HTML CODE: <div data-ng-controll ...

Creating designs on a digital canvas using ink

As someone who is new to coding, I am looking for guidance on how to create a drawable triangle on an inkcanvas. My goal is to have a button that, when clicked, allows me to click in the inkcanvas and drag to form the triangle, similar to drawing shapes in ...