简体   繁体   English

边框颜色过渡css3错误

[英]Border-color transition css3 bug

I was trying to do a transition on a border-color property on my website, but I have a little bug on it and I don't know where he comes from. 我试图在我的网站上进行边界颜色属性的转换,但我有一个小错误,我不知道他来自哪里。

When my mouse is on the button/link, the border becomes blue and then the transition comes. 当我的鼠标在按钮/链接上时,边框变为蓝色,然后转换到来。 I tried this code on firefox/chrome/opera and this problem appear on all of them, so it's probably an error from me. 我在firefox / chrome / opera上尝试了这个代码,这个问题出现在所有这些问题上,所以这可能是我的错误。

You can see the problem there: http://jsfiddle.net/u3Ahk/15/ 你可以在那里看到问题: http//jsfiddle.net/u3Ahk/15/

.bouton a {
    transition: background-color 1s, border-color 1s;
    padding: 5px 7px 8px 7px;
    text-decoration: none;
}

Thanks in advance ! 提前致谢 !

You have a zero-width border without an explicit color, that changes to a grey 1-pixel border on hover, and you're trying to transition only border-color . 您有一个没有明确颜色的零宽度边框,在悬停时会更改为灰色的1像素边框,并且您尝试仅转换border-color That doesn't really work — what happens is that the width changes to 1 pixel immediately, and then you have a blue border changing to a grey border. 这不起作用 - 会发生的是宽度立即变为1像素,然后您将蓝色边框更改为灰色边框。 You're changing one thing but transitioning something else entirely. 你正在改变一件事,但完全转变其他东西。

The reason why the border starts off blue is because you didn't specify a border color for the initial state, so it takes on the text color which is also blue. 边框开始为蓝色的原因是因为您没有为初始状态指定边框颜色,因此它采用的文本颜色也是蓝色。 That is by design , not a bug in any browser. 这是设计 ,而不是任何浏览器中的错误。 I can't tell what exactly about the border you want to transition (width only, color only, or both?), so it's difficult to propose a solution. 我不清楚你想要转换的边界究竟是什么(仅宽度,仅颜色,或两者兼而有之?),因此很难提出解决方案。

Updated fiddle. 更新了小提琴。

Explicitly state the transparent border in the normal state of the link: 在链接的正常状态下明确说明透明边框:

.bouton a {
    transition: background-color 1s, border-color 1s;
    padding: 5px 7px 8px 7px;
    text-decoration: none;
    border: 1px solid transparent; /* this */
}

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

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