覆盖的CSS属性是被取消还是被覆盖?

编程入门 行业动态 更新时间:2024-10-21 15:58:59
本文介绍了覆盖的CSS属性是被取消还是被覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的意思是

如果我这样做:

#item { background:url('image.jpg');}

然后在另一个样式表中

#item {background:red;}

浏览器将加载image.jpg,然后将其取消并设置为红色,还是直接变为红色? (不加载图像)

will the browser load image.jpg and then cancell it and set red, or will go straight to red? (without loading the image)

谢谢!

推荐答案

它将同时执行这两个操作,因为这两个语句与

It will do both, since those two statements are the same as

#item { background: red url('image.jpg'); }

#item { background-color: red; } #item { background-image: url('image.jpg'); }

在两种情况下,背景都会有图像,并且item元素的整个区域都将显示为红色.因此,不透明的图像(例如具有透明性的.png)也将在透明区域中也用红色填充.

In both cases, the background will have an image, and the entire area of the item element in red. So an opaque image, like a .png with transparency, would for instance be filled with red in the transparent areas as well.

但是,当脚本以级联方式解析CSS时,

However, as the script parses the CSS in a cascading fashion,

#item { background: url('image.jpg'); } #item { background: url('anotherimage.jpg'); }

它将加载"anotherimage",而忽略另一个. 在CSS完成编译并确定特异性.换句话说,第一个图像被覆盖,因此从不请求.

it will load "anotherimage" and ignore the other one. The request isn't sent until the CSS is done compiling and determined the order of specificity. In other words, the first image is overridden, and is therefore never requested.

背景"实际上是一个简短的属性,例如边界",它将所有不同的属性组合到一个语句中. 这是关于'background'属性的链接,向下滚动,您可以阅读它

The 'background' is actually a short hand property, like 'border', combining all of the different properties into a single statement. Here is a link about the 'background' property, scroll down and you can read about it.

更多推荐

覆盖的CSS属性是被取消还是被覆盖?

本文发布于:2023-11-08 07:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568760.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被覆   属性   CSS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!