Putting search icon in search input, then centering both in page - html

I've managed to get the search icon IN the input field, and can center the input field with margin: 0 auto and displaying it to block (but this keeps from the icon being in the field and keeps it at the right of the page, since it's on block - yet it's the only way I've managed to center it). New to HTML/CSS, so is there a proper way to do this? Looking to learn.
Currently have this code:
#import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
.search {
position: relative;
color: #aaa;
font-size: 16px;
}
.search input {
width: 500px;
height: 32px;
background: #fcfcfc;
border: 0;
border-bottom: 5px solid #000;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
margin: 0 auto;
}
.search input {
text-indent: 32px;
}
.search .fa-search {
position: absolute;
top: 10px;
left: 10px;
}
<div class="search">
<span class="fa fa-search"></span>
<input placeholder="Search term" id="search" class="keyword">
</div>

The input is an inline element, consider centering the the wrapper which is a div (block element) on where you can use margin:auto. You may also use max-width to make it responsive on small screen:
#import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
.search {
position: relative;
color: #aaa;
font-size: 16px;
max-width: 500px;
width:100%;
margin:0 auto;
}
.search input {
width:100%;
height: 32px;
background: #fcfcfc;
border: 0;
border-bottom: 5px solid #000;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.search input {
text-indent: 32px;
}
.search .fa-search {
position: absolute;
top: 10px;
left: 10px;
}
<div class="search">
<span class="fa fa-search"></span>
<input placeholder="Search term" id="search" class="keyword">
</div>

Related

Replacing default icon of select tag and clicking on dropdown icon doesnot populate dropdown list

I have a piece of html code using the select tag. I need to override the default dropdown icon with a new segoe icon. I did that using the following code:
.select {
border: 1px solid #ccc;
overflow: hidden;
height: 40px;
width: 240px;
position: relative;
display: block;
}
select {
height: 40px;
padding: 5px;
border: 0;
font-size: 16px;
width: 240px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.select:after {
content: "\e0e5";
font-family: segoe mdl2 assets;
color: #000;
padding: 12px 8px;
position: absolute;
right: 0;
top: 0;
background: red;
z-index: 1;
text-align: center;
width: 10%;
height: 100%;
box-sizing: border-box;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<label class="select">
<select name="email" id="email">
<option>aaaa1</option>
<option>aaaa2</option>
<option>aaaa3</option>
<option>aaaa4</option>
<option>aaaa5</option>
<option>aaaa6</option>
</select>
</label>
My problem is, when clicking on the new dropdown icon, the dropdown list doesn't populate. As it is like an icon over the select option tag. I tried to use z-index but it moves the icon completely to back. Can someone provide a solution?
I found the solution. By adding a CSS property
.select:after {
pointer-events: none;
}
in addition to all the CSS properties above, it works.
Changes Some css
select{
height: 40px;
padding: 5px;
border: 0;
font-size: 16px;
width: 240px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
z-index:1; /*Add Z-index*/
position:relative; /*Add Position*/
background:transparent; /*Add Background*/
}
.select:after {
content:"\e0e5";
font-family: segoe mdl2 assets;
color: #000;
padding: 12px 8px;
position: absolute;
right: 0;
top: 0;
background: red;
/*z-index:1;*/ /*Remove Z-index */
text-align: center;
width: 10%;
height: 100%;
box-sizing: border-box;
}
https://jsfiddle.net/yqmb3wxL/

Input field doesn't render well in Safari

I've been checking an input field across various browsers. It only doesn't render well in Safari for some reason. It's ignoring the padding assigned to itself.
Do you know any issue caused by that?
Below there is the form and its styling.
Thanks
<form class="search" name="searchCity" ng-submit="search(city)">
<input class="search__field" name="searchField" type="search" title="Please enter city name" required placeholder="City to find" ng-model="city" ng-pattern ="regex"/>
<button ng-disabled="searchCity.$invalid" class="search__button" type="submit"><img src="./img/search_icon.gif" alt="Search city" /></button>
</form>
//Form elements style global
form{
font-size:1.2em;
width:100%;
textarea{
display: block;
margin: 20px 0;
width: 100%;
height: 200px;
padding: 10px;
}
select{
padding: 13px;
-webkit-appearance: menulist-button;
height: 45px;
}
input{
&[type="checkbox"], &[type="radio"]{
display: none;
+ label{
position: relative;
cursor: pointer;
vertical-align: middle;
}
&:before{
content: "";
border: 1px solid gray;
background-color: white;
border-radius: 50%;
width: 17px;
height: 17px;
display: inline-block;
vertical-align: middle;
margin-right: 5px;
}
}
&[type="checkbox"]{
+ label{
&:before{
border-radius: 0;
margin-right: 10px;
}
}
}
&:checked{
+ label:after{
content: "";
background-color: green;
border-radius: 50%;
width: 9px;
height: 9px;
position: absolute;
left: 5px;
top: 5px;
}
}
&[type="text"],
&[type="search"],
&[type="password"],
&[type="number"]{
padding: 13px;
border: solid 1px #a4a4a4;
}
}
}
Input type search isn't supported in a few browsers but it should be supported in Safari, maybe try using input type text since it behaves the same as search.

Search button with image in background height inconsistencies

I made a search bar with a button that has an image as a background. I really can't get the button and the search bar to be the same height on all the browsers and devices.
My HMTL:
<form action="test.php">
<input type="search" placeholder="Indiquer un département...">
<input type="image" name="search" src="./img/loupe.png">
</form>
My CSS:
.search form input[type=search] {
position: relative;
left: 1.8em;
width: 65%;
padding: 0.87em;
margin-top: 3em;
background-color: #ffffff;
float: left;
-webkit-appearance: none
}
.search form input[type=search]:hover {
border: 1px #a1a1a1 solid;
}
.search form input[type="image"] {
height: 1.96em;
display: inline-block;
position: relative;
padding: 0.5em 20px;
left: 1.8em;
margin-top: 3em;
background-color: #4689f5;
color: #ffffff;
border: 1px #2f78eb solid;
cursor: pointer;
-webkit-appearance: none;
}
.search form input[type="image"]:hover {
background-color: #367ae8;
border: 1px #2d59b5 solid;
}
Thank you.
Try vertical-align: middle in your input[type="image"].

How to make a submit button stand next to a search input

I wonder if i can put a submit button inside a search input, in the right side. I tried using float: right however doesn't work.
Codepen: http://codepen.io/celicoo/pen/XbKYyY
HTML:
<section class="search">
<div class="search__container">
<div class="search__row">
<div class="col-lg-12">
<div class="search__box">
<h2 class="search__title">Procurando por: Nome de ...</h2>
<form class="search__form" action="#" method="get">
<input class="search__input" type="text" placeholder="Busque um Crawler.." />
<button class="search__submit" type="submit">Procurar</button>
</form>
</div>
</div>
</div>
</div>
</section>
CSS:
.search {
color: #676a6c;
margin-top: 25px;
&__row {
margin-left: -15px;
margin-right: -15px;
overflow: hidden;
}
&__box {
background: #FFFFFF;
padding: 10px;
}
&__form {
margin-top: 10px;
}
&__input {
background-color: #FFFFFF;
background-image: none;
border: 1px solid #e5e6e7;
border-radius: 1px;
color: inherit;
display: block;
padding: 12px;
width: 100%;
font-size: 14px;
outline: none;
}
&__input:focus {
border: 1px solid #E97228;
}
&__submit {
background-color: #E97228;
border-color: #E97228;
color: #FFFFFF;
border: 1px solid transparent;
outline: none;
}
}
I was trying to use float right like i said, but isn't work, the float will only push the submit button to the right, but not inside the input.
Your input for .search__input has a width of 100% so nothing can actually go beside it.
You need to make the width less than 100% and add float:left;
Example:
.search__input{width:50%; float:left;}
I assume you are trying to have the submit button 'inside' the input... or overlapping it.
You need to create a wrapping div around the input and submit with position: relative;, and then give the submit button a position: absolute; and a top and right value.
I added display: inline & have placed your search bar inside a container.
Try this css:
.search {
color: #676a6c;
margin-top: 25px;
&__row {
margin-left: -15px;
margin-right: -15px;
overflow: hidden;
}
&__box {
background: #FFFFFF;
padding: 10px;
}
&__form {
margin-top: 10px;
}
&__input {
background-color: #FFFFFF;
background-image: none;
border: 1px solid #e5e6e7;
border-radius: 1px;
color: inherit;
display: block;
padding: 12px;
width: 50%;
font-size: 14px;
outline: none;
display: inline;
margin:0px;
}
&__input:focus {
border: 1px solid #E97228;
}
&__submit {
background-color: #E97228;
border-color: #E97228;
color: #FFFFFF;
border: 1px solid transparent;
outline: none;
padding: 12px;
margin:0px;
}
&__container {
width: 250px;
}
}

Add icon via :before to <input> element

I've got an <input>-element. I'd like to precede it with a search-icon using the :before selector including a SVG-font I created.
.icon-search:before {
content: "\f109";
text-indent: -2em;
}
My problem is that the pseudo-selector :beforedoesn't seem to work with <input> Can you tell me how to make this work in the most elegant way?
This is how I want it to look once I'm done.
The before/after pseudo element is contained inside the element but input can't have that, so you have to use another selector like span or div. This is an implementation similar to what bootstrap does...
FIDDLE
HTML:
<div class="wrapper">
<div class="inputgroup"> <span class="innericon searchicon"></span>
<input type="text" class="search" placeholder="search..." />
</div>
</div>
CSS:
body {
color: gray;
}
.wrapper {
margin: 20px auto;
width: 40%;
}
* {
box-sizing: border-box;
}
.inputgroup {
position:relative;
display: inline-block;
height: 30px;
line-height: 30px;
vertical-align: middle;
}
.search {
border-radius: 8px;
height: 30px;
line-height: 30px;
padding: 3px 6px 3px 32px;
border: none;
font-size: 13px;
display: inline-block;
vertical-align: middle;
border: 1px solid #CCC;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
}
.inputgroup .innericon {
position: absolute;
top: 4px;
left: 8px;
z-index: 2;
display: block;
text-align: center;
pointer-events: none;
}
.searchicon:before {
content: "\f109";
}
Here is one way to achieve this: http://jsfiddle.net/n9gjb3kr/
You need to put your input inside a div:
<div class="icon-search"><input type="text"></input></div>
.icon-search:before {
content: "\f109";
position: absolute;
left: 0;
top: 0;
height: 24px;
width: 24px;
margin-left: .5em;
width: 0;
overflow: visible;
display: inline-block;
line-height: 24px;
z-index: 1;
}
.icon-search {
position: relative;
line-height: 24px;
}
.icon-search > input {
border-radius: 12px;
height: 24px;
border: 1px solid black;
margin: 0;
padding: 0;
padding-left: 32px;
}
You can wrap the input into span, setting the span with position:relative and
then add to input and icon position:absolute and play with margins and z-index to create the same effect. This is pretty solid for responsive as well, if you style the span and the input the right way taking the responsive design in account.
OR
Using jquery as already mentioned in the comments