Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome/Safari: box-shadow only appears on text input if border is specified

I'm running into a problem with WebKit browsers (Chrome 15.0.x and Safari 5.1.1) where box shadows are not being rendered on text inputs. Just by chance, I discovered that explicitly setting the border causes the box shadow to render, even if you set the border to 'none' or the default, 'inset'. The code below (view it in action on JSFiddle) demonstrated the problem when viewed with Chrome or Safari, but it renders as expected in Firefox 6.0.2 and Opera 11.52.

HTML

<input type="text" value="Works" style="border:none;" />
<input type="text" value="Works" style="border:inset;" />
<input type="text" value="Doesn't" />

CSS

input[type="text"] {
    margin: 1em;

    -webkit-box-shadow: 0px 0px 2px 1px green;
    box-shadow: 0px 0px 2px 1px green;
}

Am I missing some detail of using box shadows in WebKit or have I found a bug?

like image 358
spaaarky21 Avatar asked Nov 20 '11 02:11

spaaarky21


People also ask

How do I remove the border highlight on an input text element?

Answer: Use CSS outline property In Google Chrome browser form controls like <input> , <textarea> and <select> highlighted with blue outline around them on focus. This is the default behavior of chrome, however if you don't like it you can easily remove this by setting their outline property to none .

How do you make an input border invisible?

border: none transparent; outline: none; This will not only remove the border around the input field but also the orange highlight when the input is in focus. +1 outline:none makes the border disappear even when the input is focused.

Does the box shadow support all browsers True or false?

The box-shadow property of CSS 3 is supported by recent versions of all browsers.

Can you add shadow to text CSS?

The text-shadow CSS property adds shadows to text. It accepts a comma-separated list of shadows to be applied to the text and any of its decorations . Each shadow is described by some combination of X and Y offsets from the element, blur radius, and color.


1 Answers

inputs, in WebKit, have this property applied to them by default:

-webkit-appearance: textfield;

This is what you want if you want the appearance of the text field to be platform-dependent. Sometimes you can style it with this still set, but other times, it needs to be set to none, which makes it apply standard CSS and rely less on the operating system. It seems border automatically triggers this, but box-shadow does not, yet box-shadow is only applied if -webkit-appearance is none. (the fact that the platform-dependent appearance is not turned off if box-shadow is applied and that box-shadow is not rendered if the platform-dependent appearance is enabled may be a bug)

To fix this, simply explicitly tell it to not use the platform-dependent appearance:

input[type="text"] {
    -webkit-appearance: none;
}

Test it with -webkit-appearance: none; added.

The downside of this is you lose (some of) the platform's native look, but if you're trying to use box-shadow, you might be trying to style away the native look anyways.

like image 97
icktoofay Avatar answered Sep 28 '22 02:09

icktoofay