删除 iOS 输入阴影

在 iOS (Safari 5)中,我必须为输入元素(顶部内阴影)执行以下操作:

example

我想删除顶部阴影,错误 -webkit-appearance不保存。

现在的风格是:

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;
}
107314 次浏览

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/

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;
background-clip: padding-box;

Seems to remove the shadows as well.

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

This works better for me. Plus it means I don't have to apply it to every different type of input (i.e. text, tel, email, etc).

* {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}

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.

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;
}