简体   繁体   English

如何防止 Internet Explorer 在按下时向按钮添加填充?

[英]How can I prevent Internet Explorer from adding padding to buttons when pressed?

I have designed my submit buttons using CSS.我使用 CSS 设计了我的提交按钮。 In any Webkit or Gecko browser it works perfectly, but Internet Explorer 9 adds padding to the button's text when it is pressed down.在任何 Webkit 或 Gecko 浏览器中,它都能完美运行,但 Internet Explorer 9 在按下按钮时会为按钮的文本添加填充。 In addition, you can see this stupid dotted border.此外,您还可以看到这个愚蠢的虚线边框。 It looks like this then:它看起来像这样:

http://img6.imagebanana.com/img/tkp7l8m3/button.png http://img6.imagebanana.com/img/tkp7l8m3/button.png

The special background image which I have specified in CSS for input:active is only shown in IE, if the button is clicked in the very thin area between the button's border and this dotted border.我在 CSS 中为 input:active 指定的特殊背景图像仅在 IE 中显示,如果在按钮边框和此虚线边框之间的非常薄的区域中单击按钮。 If the button is clicked in the middle it keeps the hover-background although it is pressed down.如果在中间单击按钮,它会保持悬停背景,尽管它被按下。

Can anyone help me remove this extra padding and the dotted border?谁能帮我删除这个额外的填充和虚线边框?

Thanks in advance提前致谢

Qoguth古古斯

To get rid of the dotted border you can use pure CSS:要摆脱虚线边框,您可以使用纯 CSS:

button { outline: none; }

As for padding when clicked, I fear it's part of the internal browser behavior that can't be changed.至于单击时的填充,我担心它是无法更改的内部浏览器行为的一部分。

You could try:你可以试试:

/* Swap 1px 6px for your desired top+bottom and left+right padding. */
button { padding: 1px 6px; }
button:active { outline: none; padding: 1px 6px; }

Presuming you actually want padding and not some other property.假设您实际上想要填充而不是其他属性。

Both of the answers given so far are incorrect in an important way.到目前为止给出的两个答案在一个重要方面都是不正确的。 You should only hide the keyboard focus outline on:active, hiding it on:focus too hurts keyboard navigation.您应该只将键盘焦点轮廓隐藏在:活动上,将其隐藏在:焦点上也会损害键盘导航。

button:active { outline: none; }

As has been stated, the increase in top-left padding is not overridable.如前所述,左上角填充的增加是不可替代的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM