Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position an x in an input widget to clear the content?

With twitter bootstrap it is quite straight forward to create a Search style input widget:

enter image description here

Also the x is doable with Twitter bootstrap, but positioning the x in that spot, requires some CSS finetuning.

I managed to get the x in that position, but it isn't very reliable. With a responsive-design and different resolutions the x gets completely displaced.

.filter-close {
    float: none;
    position: relative;
    left: 5em;
    top: 1.25em;
    z-index: 3;
}

<form action="." method="get" class="form-search">
 <a class="close filter-close" href="#">x</a>                                           
    <div class="input-append">                  
        {{filter_form.last_name}}<button type="submit" class="btn"><i class='icon-filter'> </i></button>                </div>                          
</form>

Before trying to reinvent the wheel, is there any existing javascript library that could turn an input in an input-with-an-x-button? Something like Chosen.js for this purpose? Or any advice how I could do this in a better way?

Many Thanks,

like image 261
Houman Avatar asked Oct 03 '12 21:10

Houman


People also ask

How do I clear my input box?

To clear an input field after submitting:When the button is clicked, set the input field's value to an empty string. Setting the field's value to an empty string resets the input.

Which is the correct HTML tag for making a text input field?

The <input type="text"> defines a single-line text field. The default width of the text field is 20 characters.


1 Answers

Check out this post

This fiddle basically does what you are looking to do.

You are headed in the right direction.

like image 142
karthikr Avatar answered Oct 24 '22 18:10

karthikr