IE8 <输入类型=“按钮”> - CSS 悬停在边框和填充设置为 0 的情况下不起作用

发布于 2024-10-20 06:10:38 字数 705 浏览 1 评论 0 原文

测试页:

<!DOCTYPE html>
<html>
    <head>
        <title>button border hover test</title>
        <style type="text/css">
            input
            {
                border: 0;
                padding: 0;
            }

            input:hover
            {
                background-color: fuchsia;
            }
        </style>
    </head>
    <body>
        <form>
            <input type="button" value="input element" /><br>
        </form>
    </body>
</html>

背景颜色没有变化。如果将填充设置为大于 0 的值,则背景颜色会发生变化。 我在 Firefox 中没有看到这种行为。

1px 的填充不会破坏布局,但是有人知道如何使用 0 填充来实现此功能吗?

Test page:

<!DOCTYPE html>
<html>
    <head>
        <title>button border hover test</title>
        <style type="text/css">
            input
            {
                border: 0;
                padding: 0;
            }

            input:hover
            {
                background-color: fuchsia;
            }
        </style>
    </head>
    <body>
        <form>
            <input type="button" value="input element" /><br>
        </form>
    </body>
</html>

The background colour does not change. If you set the padding to anything higher than 0, the background colour does change.
I'm not seeing this behaviour in Firefox.

Having a padding of 1px isn't disruptive to the layout, but does anyone know of a way to make this work with 0 padding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟雨凡馨 2024-10-27 06:10:38

有两种可能的解决方案。

  1. 请改用
  2. 使用填充。但即便如此,有时悬停也不起作用。

来自 http 的一些相关信息: //www.sitepoint.com/forums/showthread.php?769898-button-vs.-input-type-quot-button-quot

There are two possible solutions.

  1. Use a <button> element instead.
  2. Use padding. But even then, sometimes the hover doesn't work.

Some relevant information from http://www.sitepoint.com/forums/showthread.php?769898-button-vs.-input-type-quot-button-quot

<button> can contain HTML, and is easier to style with CSS, which
actually gets applied across browsers. However, there are some
drawbacks to using it in IE. IE doesn't properly detect the value
attribute (and uses the tag's content instead as the value), and all
values are sent to the server, whether or not the button is clicked.
This makes using it as a a little tricky.

<input type="submit"> doesn't have any value or detection issues.
However, you can't add HTML like with and can only use the
value tag. It's also harder to style, and the styling doesn't always
respond well across browsers.

深爱成瘾 2024-10-27 06:10:38

欢迎来到俱乐部。这让我发疯。
我有一个表格,最后一列有按钮。当您将鼠标悬停在一行上时,背景会发生变化。
如果将鼠标悬停在行中的按钮上,按钮上的文本颜色以及行背景都会发生变化。
我在按钮上有 0 填充。
所有这些在 FF 中都运行良好,没有任何问题。

在 IE8 中,这是一个完整的故事。行悬停效果很好,但是当您将鼠标悬停在行中的按钮上时,没有任何反应。
行背景没有改变,按钮文本颜色也没有改变(99.99% 的时间)。

我玩了这个,终于意识到发生了什么事。
悬停在按钮文本上时似乎不起作用。
我在按钮文本的每一侧添加了 20px 的内边距。
如果我将光标滑下填充区域中的按钮(不接触文本),它的效果和 FF 一样好。
一旦我将光标滑到按钮中间(穿过按钮文本),它就会中断。

去算算吧。我讨厌IE!!!!

Welcome to the club. This was driving me crazy.
I have a table with buttons in the last column. When you hover over a row, the background changes.
If you hover over the button in the row, the text color on the button changes as well as the row background.
I had 0 padding on the buttons.
All this works great in FF with no problems.

In IE8, a whole nuther story. The row hover worked great but when you hovered over the button in the row, nothing happened.
The row background didn't change and the button text color didn't change (99.99% of the time).

I played with this and finally realized what was going on.
It seems to be that hover doesn't work while over button text.
I added 20px of padding on each side of the text on the button.
If I slide my cursor down the buttons in the padded area (not touching the text) it worked as well as FF.
As soon as I slide the cursor down the middle of the buttons (through the button text), it breaks.

Go figure. I HATE IE!!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文