简体   繁体   English

应用 CSS3 '不透明度' 属性

[英]Applying CSS3 'Opacity' Property

I'm working on a site where I've created a simple CSS3 hover effect, where if a link is hovered, it changes the opacity and looks like a rollover effect.我正在一个网站上创建一个简单的 CSS3 hover 效果,如果链接悬停,它会改变不透明度,看起来像翻转效果。 It seems to be working perfectly on all browsers (even older ones, such as Firefox 2).它似乎在所有浏览器上都能完美运行(甚至是较旧的浏览器,例如 Firefox 2)。 Just wanted some input if this is a problem and I should consider javascript instead?如果这是一个问题,只是想要一些输入,我应该考虑 javascript 吗? Or is using CSS a good (semantically correct) way of going about a rollover?或者使用 CSS 是一种很好(语义正确)的翻转方式?

Generally, if an effect can be achieved using CSS alone, it's usually better to use CSS then to use JavaScript to achieve it.一般来说,如果单独使用CSS可以达到效果,通常最好使用CSS然后使用JavaScript来实现。

Sure, you can use JavaScript and/or libraries like jQuery, but why?当然,您可以使用 JavaScript 和/或 jQuery 等库,但为什么呢? If the browser is capable of doing it natively, not only will it work better, it will look better and smoother.如果浏览器能够原生地做到这一点,它不仅会更好地工作,而且看起来会更好、更流畅。

Generally, people using newer browsers get benefits from the new technology.通常,使用较新浏览器的人会从新技术中受益。

People who do not update their systems tend to not care about how things look, so as long as the site is functional and the effect is not very important, I'd say don't bother to make all browsers behave exactly the same.不更新系统的人往往不关心事情的外观,所以只要网站功能正常且效果不是很重要,我想说不要费心让所有浏览器的行为完全相同。 It's a waste of time and effort.这是浪费时间和精力。

For anchor elements, the :hover pseudo-class is widely supported, and is a good way to go.对于锚元素, :hover伪类得到广泛支持,是 go 的好方法。 I believe the only in-use browser that doesn't support it is IE 6. The opacity property is less widely supported, so your effect may not look the way you want in some browsers.我相信唯一不支持它的正在使用的浏览器是 IE 6。 opacity属性的支持较少,因此您的效果在某些浏览器中可能看起来不像您想要的那样。 If you need to use the :hover pseudoclass on elements other than a , I think you'll lose IE 7 as well.如果您需要在 a 以外a元素上使用:hover伪类,我认为您也会失去 IE 7。

See http://www.w3schools.com/css/css_pseudo_classes.asp for some background information on :hover and other pseudo-classes.有关:hover和其他伪类的一些背景信息,请参见http://www.w3schools.com/css/css_pseudo_classes.asp

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

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