简体   繁体   English

效率更高的CSS:背景图片还是背景RGBBA?

[英]More efficient css: background image or background rgba?

Which is more efficient: 哪个更有效:

I'm trying to find out which method of providing a semi transparent background is more efficient/faster: 我正在尝试找出提供半透明背景的方法更有效/更快:

background-color: rgba(255, 255, 255, .12);

Or 要么

background-image: url('/path/to/semi-transparent/pixel.png');

Couldn't find any resources. 找不到任何资源。

I understand that the background-color one doesn't require an HTTP request and that the background-image takes more processing. 我知道background-color不需要HTTP请求,并且background-image需要更多处理。


Notes: 笔记:

Compatibility is a big issue as I (no one really should) can't drop support for < IE8. 兼容性是一个大问题,因为我(没有人真的应该)不能放弃对<IE8的支持。

A lot of answers/comments are mentioning that the background-color: rgba is faster and more efficient but that background-image is more compatibility friendly. 许多答案/评论都提到了background-color: rgba更快,更有效,但是background-image更加兼容。 If true (haven't seen any hard tests) then: is there a fallback solution other than using a library like Modernizr that will work? 如果为true(未进行任何硬性测试),那么:除了使用像Modernizr这样的库可以工作之外,是否还有一个后备解决方案? ie (this does not work as it does both at the same time - but looking for something along these lines) 即(这不能同时起作用,而是要沿着这些方向寻找东西)

background: rgba(255, 255, 255, .12) url('/path/to/semi-transparent/pixel.png');

Definitely the first one would be faster. 肯定第一个会更快。 Using an image will use an additional HTTP request to fetch it, also the size of the image would affect the loading time. 使用图像将使用附加的HTTP请求来获取它,图像的大小也会影响加载时间。 Using hex color values instead of rgb would also be better as the browser ultimately converts rgb to hex. 使用十六进制颜色值代替rgb也会更好,因为浏览器最终会将rgb转换为十六进制。

I would say that the first is more efficient and fast. 我要说的是,第一个更有效,更快捷。 The latter is a more compatible option and should be used if the first, more efficient method does not work with the browsers you want it to work with. 后者是更兼容的选项,如果第一种更有效的方法不适用于您希望使用的浏览器,则应使用后者。

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

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