Using a glyphicon will change the dimensions of the text box

I am currently working on a Bootstrap web page that features a list box filled with names and a search box for filtering through those names. The search box includes a glyphicon-remove button that becomes visible when text is typed in. Clicking the button clears the search box. However, I am facing an issue where the size of the search box shrinks when the icon appears, and I cannot determine the cause of this behavior.

Here is a visual representation:

https://i.sstatic.net/YOtus.png

This is how it should appear:

https://i.sstatic.net/YOtus.png

To resolve this issue, I could set a fixed width using CSS, but I prefer for it to adjust with the window like the rest of the form.

HTML:

<div class="col-lg-4">
<form>
    <div class="form-group has-feedback">
        <label for="txtFilter">Select A User</label>
        <div class="input-group">
            <input class="form-control" type="text" id="txtFilter" placeholder="Filter by name">
            <span class="form-control-feedback glyphicon glyphicon-remove filter-icon"></span>
        </div>
    </div>
    <div class="form-group">
        <select class="form-control" id="lstUsers" size="8"></select>
    </div>
</form>

CSS:

.filter-icon{
cursor: pointer;
pointer-events: all;
z-index: 3;}

Answer №1

It appears that when the icon disappears, the box does not change shape. Have you checked for any conflicting CSS styles that may be causing this issue? Without any other potential explanation, it seems like the code provided should not result in an error.

.filter-icon{
cursor: pointer;
pointer-events: all;
z-index: 3;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-4">
<form>
    <div class="form-group has-feedback">
        <label for="txtFilter">Select A User</label>
        <div class="input-group">
            <input class="form-control" type="text" id="txtFilter" placeholder="Filter by name">
            <span class="form-control-feedback glyphicon glyphicon-remove filter-icon"></span>
        </div>
    </div>
    <div class="form-group">
        <select class="form-control" id="lstUsers" size="8"></select>
    </div>
</form>
</div>
</div>
</div>

Answer №2

Feel free to give this code a shot!

Here's the HTML:

<html>
<head>
<title>SSSSSS</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="col-lg-12">
<form>
 <div class="col-lg-12 form-group has-feedback">
        <label for="txtFilter">Select A User</label>
 </div>
 <div class="col-lg-12 form-group">      
  <input id="txtFilter" type="search" class="form-control" placeholder="Filter by name">
  <span id="searchclear" class="glyphicon glyphicon-remove"></span>
</div>


    <div class="col-lg-12 form-group">
        <select class="form-control" id="lstUsers" size="8"></select>
    </div>
</form>
</div>
</body>
</html>

CSS is as follows:

#searchclear {
    position: absolute;
    right: 18px;
    top: 0;
    bottom: 0;
    height: 14px;
    margin: auto;
    font-size: 14px;
    cursor: pointer;
    color: #ccc;
}

And here's the Jquery implementation:

$("#searchclear").click(function(){
    $("#txtFilter").val('');
});
$(document).ready(function(){
 $('#searchclear').css("display","none");
$('#txtFilter').keyup(function () { 
 $('#searchclear').css("display","block");
});
})

Answer №3

After facing a similar issue, I managed to resolve it by adapting Kasunjuth Bimal's code and making some tweaks. The key alteration was changing the class from 'input-group' to 'form-group', which enabled me to realign the icon with additional CSS adjustments. Below is my modified code snippet:

<form>
<div class="form-group has-feedback">
    <label for="txtFilter">Choose A User</label>
    <div class="form-group relative">
        <input class="form-control" type="text" id="txtFilter" placeholder="Filter by name">
        <span class="form-control-feedback glyphicon glyphicon-remove filter-icon"></span>
    </div>
</div>
<div class="form-group">
    <select class="form-control" id="lstUsers" size="8"></select>
</div>

.filter-icon{
position: absolute;
right: 1px;
cursor: pointer;
pointer-events: all;
z-index: 3;
}

.relative{
position: relative;
max-width: 280px;
}

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

Adjust the background color of the choices in the select box

I'm looking to customize the appearance of a drop-down menu in a form on a website by making the background of the options transparent, similar to the initial selection. I've tried using background:rgba(255, 255, 255, 0.2) for this purpose, but ...

Switching from ejs format to html

I've been working on a tutorial that uses ejs, but I'm not too familiar with it. I'd like to know how to convert the server.js from using ejs to html. Here's the code snippet: app.set('view-engine', 'ejs') app.use( ...

Ways to implement div on hover in my table's td cells

Here is the HTML table code I have: <table border='1px'> <tr> <td id='td'>first</td> <td>last</td> <tr> <td id='td'>newFirst</td> <td>newSecond</td> </t ...

Utilizing Jquery and Ajax to Load Tabs using WebApi's Get Method

Recently, I've been delving into the world of jquery/ajax and doing some experimentation. My goal is to provide html content from an asp.net WebApi application and load it into JqueryUI tabs upon a user selecting the desired tab. Unfortunately, I am ...

The logo appears cropped in the responsive layout

Responsive Logo Issue I am facing an issue with the logo in the header when viewed using Chrome developer tools in the Galaxy S5 responsive view. It seems that the logo container is too big and needs to be moved after the navbar, but I am unsure how to do ...

How can I prompt an error upon submission if the user enters incorrect input in a popup dialog?

Currently, I am facing an issue with a popup on my webpage that contains a typeahead input. Users are able to enter irrelevant information and submit the form. I want to implement a validation mechanism that checks if the input matches the typeahead option ...

Ensure the background image is optimized for viewing on screens of any size

I am facing an issue with an image on my website that serves as the background for some elements. The image is wider than it is tall, causing problems for users viewing the site on phones. Is there a way to cut off the sides of the image and ensure it fits ...

Uses identification numbers in place of names

I'm a beginner in Django and I'm facing an issue where the ID is displaying instead of the category name. How can I solve this problem? I have attached a part of the code below, which is incomplete. I suspect the issue lies in views.py model.py ...

Guide to Retrieving the Value of the Radio Button in Django

Welcome to my quiz app development journey! Here is a snippet from my HTML file: {% for question in questions %} <p>Q){{question.name}}</p> <input type="radio" value="1" name="{{question.id}}">{{question.o ...

Cancel an AJAX request without interfering with the subsequent request

When working with a number input and the "onChange" event, I have come across an issue with my ajax request. Upon aborting the request, it seems to have a negative impact on subsequent requests. If I send just one request without aborting, everything runs ...

Screenshots showcasing examples of HTML5 Canvas presentations

I recently discovered html2canvas through a question I had asked previously. I'm now trying to figure out how to use it to achieve the following: Generate a live thumbnail of a website. Clicking on the live thumbnail should load a larger image of th ...

Tips for designing a unique mosaic using flex technology

I am attempting to design a unique mosaic layout using flexbox that resembles the image provided: https://i.sstatic.net/jrHvb.jpg Each box should have a width equivalent to one-third of the parent container, except for box 4 which needs to be double the ...

Choose just one column within an HTML table

Is there a way to easily select the text of a single column from an HTML table using just the mouse pointer? Imagine you have a table that looks something like this: https://i.sstatic.net/n3lZR.png When trying to select only the text in the Lastname col ...

Guide on extracting the string "152" from a textnode using Selenium

I'm having trouble getting the xpath for the number 152. The xpath I tried only extracts "Test" which comes after 152, but it excludes the actual number itself. How can I get this to work and extract the count of 152? My current xpath is: //div\ ...

Is there a way to conceal the second td element?

This is the code I'm using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> </head> <body style="width:100%;" > ...

Create a transparent selection form using Contact Form 7

I'm having trouble making the Options in a Select Drop Down transparent, but it just doesn't seem to work. Even when I try to make it black, it stays black. .wpcf7-select option { background: black !important; } No matter how many times I ...

Displaying HTML with the code represented as text rather than executing the function

I'm a beginner at website development, with only basic knowledge of C++. I have some code in HTML that I've been experimenting with: <html> <body> <script type="text/javascript" src="http://localhost/Coin/wp-content/uploads/custom ...

What is the best way to make a CSS element move with Javascript?

Currently working on a JavaScript game where I am in need of a CSS object to replace the original JavaScript object. Specifically, I want my "sword" CSS object to move along with my player object when it is Unsheathead. All the examples I find only show wh ...

What is the best way to enable this JavaScript function exclusively for a particular width?

Is there a way to make this javascript function active only when the screen width is at least 1070px? Currently, I have two different headers for screens smaller than 1070px, causing padding to be added regardless of the presence of "navbar_top". Can med ...

A guide to programmatically downloading a file with JavaScript on Internet Explorer

I'm currently facing a challenge with my web page. There is a button that, when clicked, should generate a CSV file (by converting from JSON) for the user to download. I've implemented the logic based on this jsfiddle, and it works perfectly in C ...