Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove iOS input shadow

Tags:

css

ios

input

On iOS (Safari 5) I have to following for input element (top inner shadow):

example

I want to remove top shadow, bug -webkit-appearance doesn't save.

Current style is:

input {    
    border-radius: 15px;
    border: 1px dashed #BBB;
    padding: 10px;
    line-height: 20px;
    text-align: center;
    background: transparent;
    outline: none;    
    -webkit-appearance: none;
    -moz-appearance: none;
}
like image 641
WHITECOLOR Avatar asked Apr 22 '14 06:04

WHITECOLOR


5 Answers

You'll need to use -webkit-appearance: none; to override the default IOS styles. However, selecting just the input tag in CSS will not override the default IOS styles, because IOS adds it's styles by using an attribute selector input[type=text]. Therefore your CSS will need to use an attribute selector to override the default IOS CSS styles that have been pre-set.

Try this:

input[type=text] {   
    /* Remove First */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    /* Then Style */
    border-radius: 15px;
    border: 1px dashed #BBB;
    padding: 10px;
    line-height: 20px;
    text-align: center;
    background: transparent;
    outline: none;    
}

Helpful Links:

You can learn more about appearance here:

http://css-tricks.com/almanac/properties/a/appearance/

If you'd like to learn more about CSS attribute selectors, you can find a very informative article here:

http://css-tricks.com/attribute-selectors/

like image 151
Mastrianni Avatar answered Nov 18 '22 09:11

Mastrianni


background-clip: padding-box;

Seems to remove the shadows as well.

As @davidpauljunior mentioned; be careful setting -webkit-appearance on a general input selector.

like image 27
jstnrs Avatar answered Nov 18 '22 09:11

jstnrs


webkit will remove all properties

-webkit-appearance: none;

Try using the property box-shadow to remove the shadow on your input element

box-shadow: none !important;
like image 7
ShinyJos Avatar answered Nov 18 '22 08:11

ShinyJos


Whilst the accepted answer is a good start, as others have pointed out, it only works for inputs whose type is "text". There are a myriad of other input types which also render as text boxes on iOS, and so we need to expand this rule to take into account these other types.

Here's the CSS I'm using to rid input text fields and textareas of the inner shadow, whilst preserving the default styling for buttons, checkboxes, range sliders, date/time dropdowns and radio buttons, all of which are authored using the humble <input> tag too.

textarea,
input:matches(
  [type="email"],
  [type="number"],
  [type="password"],
  [type="search"],
  [type="tel"],
  [type="text"],
  [type="url"]
) {
  -webkit-appearance: none;
}
like image 7
Tom Spencer Avatar answered Nov 18 '22 09:11

Tom Spencer


I tried to come up with a solution that a.) works and b.) I am able to understand why it works.

I do know that the shadow for inputs (and the rounded border for input[type="search"]) comes from a background-image.

So obviously setting background-image: none was my first attempt, but this does not seem work.

Setting background-image: url() works, but i am still concerned about having a empty url(). Altough it currently is just a bad feeling.

background-clip: padding-box; seems to do the job as well, but even after reading the "background-clip" docs I don't get why this completly removes the background.

My favorite solution:

background-image: linear-gradient(transparent, transparent);

This is valid css and I do understand how it works.

like image 4
Andreas Riedmüller Avatar answered Nov 18 '22 10:11

Andreas Riedmüller