Position clear button in bootstrap input field - html

I'm trying to position a clear button inside an input field, at the right before to the search icon, however it's not working; the "x" is displayed in front of the input field instead.
i use absolute positioning with right:0 and top:4px
You can see my example here: http://www.bootply.com/YUwdJ5Kvx6

A little update to get what you want:
input {
/* Avoid use typing under the clear button. */
padding-right: 30px !important;
}
.input-group-btn {
position: relative;
/* This avoid the "clear" button being hidden while
the input has focus on. */
z-index: 1000;
}
.input-group-btn a.btn {
position: absolute;
right: 38px;
top: 0px;
}
/* This avoid the bad effect when clicking the button. */
.input-group-btn a.btn:hover,
.input-group-btn a.btn:active {
box-shadow: none;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet"/>
<div style="width: 300px;">
<div class="input-group">
<input class="form-control" placeholder="Search by ID..." type="text">
<span class="input-group-btn">
<a class="btn" style="color: rgb(204, 204, 204); text-decoration: none; " href="#clear">
<i class="glyphicon glyphicon-remove"></i>
</a>
<button type="submit" class="btn btn-default">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
I added position: relative to input-group-btn for position: absolute to work on the close button. Then just a negative right: 36px to move the button in the input field.
I put the close button inside the input-group-btn because it was easier for me, and it automatically takes care of the vertical alignment of your button (I just added the btn class to the a tag).
I added padding-left: 30px !important to the input field to avoid user typing under the x button. To have a symmetrical space, you would need 38px, but it looks a bit much... You can change this value at your discretion to get the result you want.
Since the a tag is inside the input-btn-group with the btn class, you need something like a:hover { box-shadow: none ; } to avoid ugly box-shadow in your input when clicking on the close button.

Try this i have appended the button before and after. Comment if this is you want or not. Did i understood you correct?
<form action="#" method="get" class="sidebar-form" id="id_search" style="width:300px;margin-left:100px;margin-top:100px;">
<div class="input-group double-input">
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
<input type="text" placeholder="Second" class="form-control" />
<span class="input-group-btn">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
</div><!-- /input-group -->
</form>

Related

bootstrap input-group with select2 and css positioning

I'm trying to create a search box with a "drop down box" after the user insert search query into the input. It will make an ajax call and then create a drop down with some results.
I'm having some troubles using boostrap to do that.
Basically I want a structure like:
[CLOSE BUTTON][SELECT2][INPUT][SEARCHBTN]
The form is ready and working but I have two problems:
1- The select2 doesnt combine with input-group. If I insert it into input-group, it doesnt fit at all. The below code is what I have that works minimally, but it doesn't show like an input-group from bootstrap. It's showing as a separate select2. I'd like to make them seems the same "input".
2- I can't work in CSS to show a box with the results. It shows the results without box and in wrong scheme.
<div id="page-header-search" class="overlay-header">
<div class="content-header content-header-fullrow">
<form action="/search/" method="post" id="search-query" name="search-query">
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="btn btn-secondary" data-toggle="layout" data-action="header_search_off">
<i class="fa fa-times"></i>
</button>
</span>
<select class="js-select2 form-control input-group.input-group-sm" id="search_category" name="search_category" style="width: 10%;" data-placeholder="Choose one..">
<option></option>
<?php ListMainCategories($link); ?>
</select>
<input type="text" class="form-control" placeholder="Search or hit ESC.." id="search_text" name="search_text">
<span class="input-group-btn">
<button type="submit" class="btn btn-secondary">
<i class="fa fa-search"></i>
</button>
</span>
</div>
<div class="input-group" id="resultados">
<div class="results" id="results"></div>
</div>
</form>
</div>
.resultados .results{
position:relative;
width: 100%;
color: #313131;
font-family: Rubik, sans-serif;
font-weight: 300
}
.resultados .results a{
position: relative;
float: left;
width: 100%;
border-bottom:1px solid #E0E0E0;
background-color: #ebebec;
list-style-type: none;
margin: 0px;
transition: all 275ms ease-in-out;
display: block;
cursor:pointer;
top: 0px;
right: 0px;
text-align: left;
/*border-radius: 40px;*/
transition: .5s ease-out;
padding-left: 20px;
}
How can I make changes to get a good result?
How can I make the box with results seems an extension of the search input?
I can't get it working.

How to make a button responsive in small screens?

.form-control {
width: 30%;
float: left;
margin-left: 33%;
}
h1 {
margin-top: 2px;
}
.card-block {
padding-top: 3px;
border-left: 5px solid #CCC;
}
.card {
background: azure;
}
.container {
margin-top: 10px;
}
body {
background: lightgray;
}
#search {
padding-top: 13%;
}
<html>
<head>
<title>Wikipedia Viewer</title>
</head>
<body>
<div id="search">
<h1 class="text-center">Wikipedia Viewer</h1>
<input type="text" class="form-control" name="" placeholder="Search Wikipedia">
<button id="go" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span></button>
<button class="btn btn-primary">Random</button>
</div>
<script type="text/javascript" src="Wikipedia Viewer.js"></script>
</body>
</html>
How can I make that Random button to stay in the same line, even in small screens? It works fine with fontawesome icons but the text length makes it jump to the next line. Also, it would be nice if there is a way to add a fontawesome icon next to it and make it stay in the same line in smaller screens (not required).
Try this
Use btn-sm in button class
<button id="go" class="btn btn-primary btn-sm">
<span class="glyphicon glyphicon-search"></span>
</button>
Wrap the controls in a container and use flexbox:
.container {
display: flex;
}
HTML
<div id="search">
<h1 class="text-center">Wikipedia Viewer</h1>
<div class="container">
<input type="text" class="form-control" name="" placeholder="Search Wikipedia">
<button id="go" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span></button>
<button class="btn btn-primary">Random</button>
</div>
</div>
JSFiddle demo: https://jsfiddle.net/9vev9esr/4/
make the position of button fixed:
button{
position:fixed;
}
This should solve your problem

CSS positioning for close button in form

I've created a search form using bootstrap. I've also used jquery to generate a delete search button (x) when text is input, however, I am stuck trying to get it on the same line as the search form (ideally in the box to the right).
As you can see in the second picture, when "1" is entered into the form the button is generated below the search form. I have included my code below, any help would be greatly appreciated.
<form id="PWFS">
<label for="Label">Info</label>
<button type="button" class="btn btn-link btn-xs"<i class="fa fa-question-circle fa-lg"></i></button>
<div class="row">
<div class="col-md-8">
<div class="input-group btn-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-search"></i></span>
<input type="text" class="form-control search" id="search" placeholder="Workflow #">
<span id="searchclear" class="searchclear fa fa-times"></span>
</div>
</div>
<button id="WFFsearch" type="submit">Search</button>
</div>
</form>
</div>
<br>
CSS
.searchclear {
position: relative;
z-index: 10;
right: 5px;
top: 0;
bottom: 0;
height: 14px;
margin: auto;
font-size: 14px;
cursor: pointer;
color: #ccc;
}
Thank you Lal, Phil and adamdc78. I just had to change the position to absolute.

Bootstrap input group 1px diference

I use input-group in modal dialog. And the button is 1px less then other elements. How can I fix it, more then less why I have this bug? I use Bootstrap 3
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="buttons input-group col-sm-offset-1 col-sm-9">
<input type="number" min="1" value="1" class="form-control" />
<span class="input-group-addon">ks</span>
<span class="input-group-btn">
<button type="button" class="btn btn-default glyphicon glyphicon-remove color-red"/>
</span>
</div>
For me, the bug was because of a rounding error.
there's this style rule
.btn {
line-height: 1.42857;
}
which should be
.btn {
line-height: 1.42857143;
}
Turns out importing bootstrap within other SASS files resulted in a loss of precision. The SASS compile process needed the flag --precision 8 to work correctly.
For you, though, as noted in another answer, you just need to put your icon in another tag.
<span class="input-group-btn">
<button type="button" class="btn btn-default color-red">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
I encountered this today, and with a bit of googling and experimentation, it seems the correct way to use a glyphicon is to always use the icon class on it's own span, and not to combine it with other classes / components.
If your example; you would do the following:
<span class="input-group-btn">
<button type="button" class="btn btn-default color-red">
<span class="glyphicon glyphicon-remove"></span>
</button>
</span>
With this there is no need to to any style changes.
It's caused by using a glyphicon on the button, and seems to be a bug with bootstrap. Use
.input-group-btn>.glyphicon {margin-top: -1px;}
to fix it.
http://fiddle.jshell.net/85m5mwsg/2/
Remove top of .glyphicon
http://jsbin.com/dufisukefe/3/edit
.input-group-btn .glyphicon
{
top :0px
}

search icon with form element inside input box

I am trying to add search image inside search box with form element.
My code is
<div class="col-xs-9">
<form action="search">
<input class="form-control" type="search" />
<span class="glyphicon glyphicon-search"></span>
<button type="submit" class="btn"><i class="glyphicon glyphicon-search"></i>
</button>
</form>
</div>
I want when user click on the search image inside search box form action should call
code is http://jsfiddle.net/chetfarley/WK3Q6/1/
Trying code from https://stackoverflow.com/a/19918345/876739
You can do it like this:
HTML:
<div class="col-xs-9">
<input class="form-control" type="search" />
<button type="submit"><span class="glyphicon glyphicon-search"></span></button>
</div>
CSS:
.form-control + button {
position: absolute;
right: 20px;
top: 7px;
border: 0;
background-color: transparent;
box-shadow: none;
}
And a little event listener, you won't need if you just want the form to be submited:
document.getElementsByTagName("button")[0].addEventListener("click", function(){
alert("doing");
});
Here is the demo: http://jsfiddle.net/WK3Q6/275/