7

This is somewhat annoying. It appears that webkit (through chrome 13 canary) is having a right go at styling various input types and it's clashing with the design in a major way.

In particular, these are causing me a headache:

  • selected element glow (via outline)
  • placeholder= text style
  • ugly glow around focused textarea and input fields

I am using boilerplate and modernizr.

A simple input[type=search] with a placeholder overrides the text styling.

I know you can target it via

input::-webkit-input-placeholder

However, this does not seem to be able to style things like text-shadow - which is a bit crap. Does anyone know if this is likely a bug that will be fixed or do I need to fall back on to a javascript placeholder solution?

The search input comes out with a white bg and removes the rounded corners defined in the base CSS class. I found a reset code:

input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-cancel-button,
input[type=search]::-webkit-search-results-button,
input[type=search]::-webkit-search-results-decoration {
  display: none;
}

input[type=search] {
  /* the webkit overrides need to stay at the top */
  -webkit-appearance: textfield;
  -webkit-box-sizing: content-box;
  /* your styles here */
}

and it kind of helps.

The glow around form elements I fix by setting outline: none.

I guess what I am really after is a CSS reset that takes out any pre-defined styles in the user agent stylesheet (according to web inspector) that affect it. Is there any reset available that can do that so despite of the doctype being HTML5, the elements are rendered as simply as they were before HTML5 and follow implicit rules setup for them in the base CSS?

I hate to say it but despite of all its memory hogging issues and slowness of plugins, FireFox 4 actually renders everything perfectly. Webkit should not be trying to style things for you, just provide an API that allows you to do so if you wanted to...

Dimitar Christoff
  • 26,147
  • 8
  • 50
  • 69
  • Whats the point of dropping the decoration around an ``? The decoration is the only thing that makes it different from a normal `type=text` field. You may as well just use `` if you don't want the decoration. – Spudley Jun 18 '11 at 16:25
  • 1
    semantics and possibly handhelds behaviours. what's the point of any of the html-5 elements, we were fine with divs and input[type=text] anyway. :) the point is, i should be able to style them but that has to be optional if I choose to, not via stuffed user agent styles – Dimitar Christoff Jun 18 '11 at 17:31
  • 1
    @Spudley In (at least) Safari, also has a "x" (clear) button, if text is entered. – Joel L Mar 29 '13 at 17:19

5 Answers5

5

A good form reset stylesheet (with a wee bit of JS) is Formalize.

Formalize resets everything and than works to ensure consistent forms across browsers.

christiangeek
  • 619
  • 5
  • 7
  • 1
    cheers, whereas it's not something I would use, https://github.com/nathansmith/formalize/blob/master/assets/css/_formalize.sass offers some interesting ideas so I will accept it. – Dimitar Christoff Jun 27 '11 at 13:42
3

Although this may require you to define additional styling, I typically place -webkit-appearance:none on most form elements.

Bot
  • 11,868
  • 11
  • 75
  • 131
Dan Nelson
  • 93
  • 1
  • 1
  • 6
1

This seems to be working perfectly for me:

input[type=search]::-webkit-search-cancel-button,
input[type=search]::-webkit-search-decoration,
input[type=search]::-webkit-search-results-button,
input[type=search]::-webkit-search-results-decoration {
  -webkit-appearance:none;
}
input[type=search] {
  -webkit-appearance:textfield;
  -webkit-box-sizing:content-box;
}
0

Quoting from "HTML5: Up and Running" by Mark Pilgrim:

"The placeholder atttribute can only contain text, not HTML markup. However, there are some vendor-specific CSS extensions (http://trac.webkit.org/export/37527/trunk/LayoutTests/fast/forms/placeholder-pseudo-style.html) that allow you to style the placeholder text in some browsers.

So I imagine you will have to fall back on a scripted solution for that aspect of your question at least, especially given that so far no version of IE supports placeholder text.

daysrunaway
  • 742
  • 4
  • 9
  • 24
0

CSS reset styles are always a good start, since they save you headhaches.

If you want to remove the glow you can probably play a little with the outline property like you said, also setting text-shadow:none might help.

Anyway it's just guessing if you first don't try to reset the styles with a reset, after all they are made specifically for making webpaged displayed the same on every browser.

Jose Faeti
  • 12,126
  • 5
  • 38
  • 52
  • that's the thing, they don't display the same in every browser. I am very happy with how FireFox does it but not webkit. – Dimitar Christoff Jun 23 '11 at 14:49
  • Then I would definitely start with a reset stylesheet, until now I've been happy with the YUI CSS Reset, Fonts and Base for example. Anyway in the end I will end up creating my own stylesheet cause many of those things are not needed for my websites and there are others wich I need and aren't there. But it's really helpful anyway. – Jose Faeti Jun 23 '11 at 14:51
  • boilerplate uses a mixed bag css reset that takes elements from YUI one as well as others. but they don't cover the html5 input element styles. – Dimitar Christoff Jun 26 '11 at 20:43