views:

369

answers:

13

For my application, I wanted to style the submit buttons nicely. With normal CSS, I managed to get it to look good in Firefox, and horrible in IE. Then I saw this blog entry:

http://www.sohtanaka.com/web-design/liquid-color-adjustable-css-buttons/

Using that technique you get gorgeous buttons, in pretty much all browsers. However, there are also a few accessibility issues:

  • Since it uses links instead of real HTML input or button elements, clicking the button does not submit the form. This is easily resolved using Javascript, but it would be ideal if the submit button works without Javascript enabled.
  • Another issue is that hitting [ENTER] does not submit the form. A dirty hack is to include an invisible input element of type "submit" or "image".

Basically what I want is perhaps the impossible: The quality of the styling as seen in the blog entry, yet implemented using normal elements so that I get normal behavior.

Do I really have to chose between dirty hacks or poor styling?

Every button styling tutorial that I have seen so far has sub optimal results in IE :(

+8  A: 

Do I really have to chose between dirty hacks or poor styling?

No, you could use Javascript like the rest of us. Load in your standard form (complete with submit-button), and then use neatly-written Javascript to dynamically "fix" some of the ugly elements. I'd suggest evaluating the jQuery framework for this type of thing if you wish to use clean code, and get cross-browser support.

Jonathan Sampson
If you can apply CSS that fixes the ugly elements dynamically, then you can just as well apply it statically. No need for Javascript at all. Besides, the OP explicitly states he wants the submit button to work without Javascript, so he probably wants it to look good without Javascript as well.
RegDwight
The point is that you use ugly normal buttons, then use JS to replace them with pretty buttons that require JS. If they don't have JS, they have ugly buttons, and the swap isn't made. If they do have JS, then the swap is made, and it's "OK" to use JS to handle the clicks.
Will Hartung
And my point is that you don't have to use ugly buttons to begin with. You can have pretty buttons right away, purely with CSS, so that there's no need to swap anything at all, whether the user has JS enabled or not.
RegDwight
RegDwight, that depends on what your definition of "pretty buttons" is. Granted, CSS can do a lot on its own (I rarely use anything else for forms), but there's a lot CSS simply cannot do. I'm merely acknowledging that there are scenarios where javascript is the solution.
Jonathan Sampson
+1  A: 

You might be able to transport the liquid button thingy you mention into a <button type="submit"></button> setup by replacing the surrounding <div>s by button elements, and the <a>s by <span>s.

Pekka
A: 

You could use a normal submit button, and use JavaScript to swap it out for a pretty JS-enhanced button. This way, you only use JavaScript where you know it'll be supported and you won't leave NoScript users with a broken page

Charlie Somerville
A: 

Check out YUI's buttons... they seem to have figured this out

http://developer.yahoo.com/yui/examples/button/btn_example01.html

Zoidberg
Definitely interesting, but that approach still requires Javascript.
Ferdy
Yeah, it does, but with Firebug in firefox, you can see what CSS the javascript has applied after the fact, and just copy it and fine tune it to your needs.
Zoidberg
+3  A: 

See this tutorial. No JavaScript, no links instead of buttons, works in IE6 through IE8.

RegDwight
I think that's probably the best possible approach if you're really averse to using javascript.
Sam Murray-Sutton
A: 

Sexy CSS Buttons

Nimbuz
Nice, but these still use links instead of real HTML input or button elements.
Daniel Vassallo
Those buttons have the exact same issues I mentioned, they are not real.
Ferdy
A: 

Yes, you do.

Except that it's not 'poor styling', it's browser chrome. Form elements are part of the browser. 'Styling' them confuses the user and impedes usability. Seriously, just leave them well alone.

No matter how far you go with input styling, you will inevitably hit the brick wall of the file upload element, which is pretty much impossible to style. And if you can't style them all, why style any of them.

Seriously, this is akin to styling scrollbars. Don't bother.

graphicdivine
GMail styles the upload element. And I did it too :) ... But I agree that it is difficult.
Daniel Vassallo
Daniel: Cross-browser? Webkit?
graphicdivine
Agreed, you should always think very carefully before going against established conventions in web design and form buttons are definitely one of those.
Sam Murray-Sutton
@graphicdivine: There are some cheeky ways to do it cross-browser: http://www.quirksmode.org/dom/inputfile.html or http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom. However they do come with their own bag of disadvantages... I still agree with your answer.
Daniel Vassallo
+2  A: 

For my application, I wanted to style the submit buttons nicely. With normal CSS, I managed to get it to look good in Firefox, and horrible in IE.

For IE you need to add overflow: visible; to get rid of "unexplainable" padding. That's basically all you need to take into account for IE (as long as you're not in quirksmode).

Then I saw this blog entry:

Wouldn't go for it. Just stick to <button type="submit"> or <input type="submit"> with a good shot of CSS. You can even use CSS background images on those buttons. I wouldn't grab Javascript for layout issues as well, because that may cause "wtf?" experiences during page load when the user instantly sees parts of page rapidly changing. Just use CSS the smart way.

BalusC
Agreed. YMMV with IE6, but IE7+ and other real browsers let you do some decent stuff with buttons.
Keith Williams
+1  A: 

Actually, you don't have to use Javascript or anything similar. You may use buttons as well.

Continuing from http://www.sohtanaka.com/web-design/liquid-color-adjustable-css-buttons/ make the following changes:

  1. Add the following to the CSS declaration

    .btn button { float: left; height: 40px; background: url(images/btn_stretch.png) repeat-x left top; line-height: 40px; padding: 0 10px; color: #fff; font-size: 1em; text-decoration: none; border: 0; }

  2. Add the following to the HTML code:

    <div class="btn btn_learnmore"> <button>You Should Give it a Try</button> <span></span> </div>

Edit: also add margin: 0 to the button css declaration.

Anax
I was hopeful about this, but it really screws up the styling. Both in Firefox and IE it ignores the stretch overlay and also adds a bottom margin to the buttom. And again, firefox really renders text between button elements in a weird way.
Ferdy
It looks fine on 5 browsers I tested it: IE, FF, Chrome, Opera and Safari. IE and Opera still misplace the text when you click the button, which is a nice touch. Why you do think the styling is broken? Did you use border:0 and margin:0?
Anax
A: 

I do believe there is an <input type="image" src="ButtonBg.jpg" />

http://webdesign.about.com/cs/forms/a/aaformsubmit.htm

I've never really used it though.

LeguRi
A: 

Thank you all for your suggestions, some remarks from my side:

  • Most external examples suggested ignore my question. I know how to style elements using js replacement or normal links, that's not the problem.
  • I tried to suggestion you use that blog I mentioned yet replace the divs with button elements. This works remarkably well in IE, but not in Firefox due to padding differences. Also, Firefox really screws up font rendering within button tags.
  • Not styling anything at all I do not see as an option, nowadays almost all web applications have styled buttons.

This leads me to the conclusion that there is no answer to all of the following: high quality styling, cross-browser styling, javascript-free, hack-free.

Therefore I decided to keep things as is, and accept the fact that users need to have Javascript enabled to use my application, thanks for the help all.

Ferdy
@Ferdy: This would normally go as an edit of your question. Otherwise few will see it down here.
Daniel Vassallo
A: 

Have you taken a look at Awesome Buttons?

http://www.zurb.com/article/266/super-awesome-buttons-with-css3-and-rgba

They are pretty awesome, can be applied to links or buttons and look good in all the browsers I've tried (ie6 has a few little issues, but a little css just for them fixes things up).

John Duff
A: 

We just use CSS to make some very nice looking buttons. Works in IE6 - 8 and Firefox.

input.blueButton
{
    background-image: url(../Images/blueButton.gif);
    width: 80px;
    height: 21px;
    font-family: Arial;
    font-size: 11px;
    font-weight: bold;
    color: White;
    background-color: Transparent;
    border-style: none;
    cursor: pointer;
    padding-bottom: 1px;
    margin: 0 3px;
}
Martin