Fixing IE6/7 problems when using floated elements inside of a button element

后端 未结 2 1052
南方客
南方客 2021-01-24 02:05

I am creating CSS buttons for both links and form submissions. I use almost the same markup for both, with a different wrapper.

HTML Examples:

相关标签:
2条回答
  • 2021-01-24 02:58

    @Eric, save yourself time and go with a solution that's already been fought with and tested and verified in all the major browsers.....jQuery UI buttons does this right out of the box. As an extra bonus, they can be styled with Themeroller for quick changeout on the backend and even user-selectable themes on the front-end.

    Check out this tut for more details.

    0 讨论(0)
  • 2021-01-24 03:01

    There's a big stack of issues to consider here.

    I'm going to be very verbose with the changes required to fix this.

    To cajole it into working in IE6/7, these were my steps:

    • Switch to using display: inline-block instead of float for the internals of the button.
      See: http://jsbin.com/omici3/2
    • To fix the wonky alignment, we need to also add vertical-align: top.
      See: http://jsbin.com/omici3/3
    • If you look at that previous demo in IE7, and click and hold the button, you can see it's too wide. We can fix that with overflow: visible (as per here: IE7 CSS padding issue - cannot figure out), and display: inline.
      See: http://jsbin.com/omici3/4

    There's also some IE6 specific issues of low priority:

    • The button:hover selector will not work in IE6. IE6 only supports :hover on a elements. To work around this, you can use the Whatever:hover fix.
    • Due to your use of a .png image, in IE6 there is a grey background instead of transparency; there are fixes available. Though in this case, it's hard to notice. I'd say leave this one be - the extra effort is not worth the improvement.

    More important is the fact that your current implementation is slightly broken in Firefox:

    http://keeleux.com/dev/button/

    (screenshot from Firefox 4)

    • See here for why: Revisiting the Firefox button line-height bug... any 2011 solutions?
    • The easiest way to workaround it in your case it to simply move the line-height to the internal ems.
      The final fixed version: http://jsbin.com/omici3/5

    Note that a fair few of those issues can be worked around by simply using an a instead of a button.

    0 讨论(0)
提交回复
热议问题