I'm trying to make a search bar that will look nice. What I did is, I made an image of an search bar and I'm adding the image to the back-ground of the input and I'm editing the place and the size that the font will appear. The only thing that I can't find a way to edit is the small 'x' button that appears when I'm using input type search. I want to move it a little bit left so it will fix my search bar image.
Here is my HTML:
<input id="search" name="Search" type="search" value="Search" />
Here is my CSS:
#search{
width: 480px;
height: 49px;
border: 3px solid black;
padding: 1px 0 0 48px;
font-size: 22px;
color: blue;
background-image: url('images/search.jpg');
background-repeat: no-repeat;
background-position: center;
outline: 0;
}
I'm not sure is this what you were looking for, but you can style your search bar like this
fiddle
HTML
CSS
For anyone finding themselves here (as I did) thinking "how do I inspect this element to apply custom styles?", you'll need to enable the user agent shadow DOM to make these vendor elements accessible.
For WebKit (Safari) & Blink (Chrome,Edge,Opera,Brave) browsers, follow these steps:
As you can see, I'm a man of culture, if there is a dark theme, I use it
Styling the "x" cancel search button in Webkit browsers
Assuming you're talking about "Cancel search" [X] icon that appeas in Webkit browsers only (Chrome, Safari, Opera) you can use
-webkit-search-cancel-button
pseudo-element. E.g:Demo: http://jsfiddle.net/5XKrc/1/
Screenshot:
Using this approach you can even create your own cancel button, for example this style:
Instead of [X] will create a red circle.
Demo http://jsfiddle.net/5XKrc/3/
Screenshot:
For IE10 and above you can use following to move the button:
Oh and do use
placeholder="Search"
instead ofvalue="Search"
- it will display word "search" when input is empty - and will automatically remove it when user types something.Users expect things not to move much is UIs. If you decide to move the 'x' icon consider using pseudo-classes and move your search icon instead:
If the search icon is embedded your background image move it into a second image with
role="presentation"
attribute and place it immediately after yourinput
in the markup:Position it where the user expects:
Then hide and show it using the
:placeholder-shown
pseudo-classes:You may style the 'x' icon if you wish. But you might not want to anymore.