css - 背景: transparent url(); do?是什么

标签 css background

我看到一段css代码是这样的

   body { background: transparent url ('background.jpg') repeat scroll;} 

透明值有什么作用?我试着用谷歌搜索这个,但没有帮助。 background.jpg 不会覆盖它吗?

谢谢。

最佳答案

transparent 是颜色。元素可以同时具有背景图像和背景颜色。

以上等同于:

body {
    background-color: transparent;
    background-image: url('background.jpg');
    background-repeat: repeat;
    background-attachment: scroll;
}

颜色通常很重要,例如背景图像无法加载,或者图像包含透明区域,或者图像没有重复填充整个区域(诚然,在您的示例中并非如此)。

但是,由于 transparent 是“初始值”,因此在使用 background 速记时永远不需要,因为速记会自动将所有未指定的属性设置为它们的初始值.

因此,透明作为背景色有意义的唯一用例涉及:

  1. 不使用简写,而是直接使用background-color属性;
  2. 使用它来覆盖直接应用于该元素的另一个选择器。

一个例子是

body.foo { background-color: blue; }
body.foo.bar { background-color: transparent; }

关于css - 背景: transparent url(); do?是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10328204/

相关文章:

css - 子菜单箭头未在移动设备上显示

jquery - 删除 2 个 jquery 选项卡之间的填充

html - CSS 背景图像对齐问题

r - +r +ggplot +jpeg +背景 +透明

css - 这个 CSS 路径名是什么意思?

jquery - 网页在较小的分辨率下无法响应(仅由于文本溢出)

html - 事件日期的最佳 UI 是什么?

c# - 图像透明度与另一个向后 c#

php - 在 'layered' 元素上翻转...可能吗?

android - 如何向按钮添加边框和背景图像