Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<input type="search"> not styling

I am trying to create a simple search bar with a search icon next to it. But I have noticed I can't style a input with the type search. I tried it on safari (Version 9.0.3 (11601.4.4)) and then on chrome (version 49.0.2623.110). At first I thought it was because the input was not valid but found out it was fine to have the type search.

The only thing I was able to style was background-color and it only worked in chrome.

I also tried deleting all my css styles and only styling the input. It did not help.

I tried googling it with no success.

So is their a way around it or will I have to put my input type on text so I can style it?

Thanks in advance!

CODE:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <style>
        input {
            padding: 10px; /* Does not work */
        }
    </style>
</head>
<body>
    <input type="search" placeholder="Search">
</body>
</html>

this code does not work in Safari and Chrome on OS X

EDIT: I am using OS X so could it be a problem with webkit?

like image 931
Samuel Kodytek Avatar asked Mar 30 '16 12:03

Samuel Kodytek


People also ask

Can I style input type file?

Ordinary input of type file in webpages comes with a default style and the caption, choose file. The good news is that we can style and tweak it to what we want.

Can we use style in input tag?

A style attribute on an <input> tag assigns a unique style to the input control. Its value is CSS that defines the appearance of the input element.

How do you use input type search?

The <input type="search"> defines a text field for entering a search string. Note: Remember to set a name for the search field, otherwise nothing will be submitted. The most common name for search inputs is q. Tip: Always add the <label> tag for best accessibility practices!


1 Answers

Use appearance property to avoid propietary stylizing and then you are able to style it:

input[type=search]{
   -moz-appearance: none;/* older firefox */
   -webkit-appearance: none; /* safari, chrome, edge and ie mobile */
   appearance: none; /* rest */
}

More info:

  • https://developer.mozilla.org/docs/Web/CSS/-moz-appearance
  • https://caniuse.com/#search=appearance
like image 106
Marcos Pérez Gude Avatar answered Oct 25 '22 23:10

Marcos Pérez Gude