多个背景图像上的 CSS 背景大小

标签 css background background-image background-size

我需要将其中一张图片设为 background-size:100%; 但将另外两张图片设为自动。我不确定你是怎么做这个速记的。

background: url(/assets/images/site/bg-hero-l.svg) left top no-repeat,
            url(/assets/images/site/bg-hero-r.svg) right top no-repeat,
            url(/assets/images/site/hero-banner.jpg) top no-repeat fixed;

最佳答案

From MDN :

The <bg-size> value may only be included immediately after <position>, separated with the / character, like this: center/80%.

因此,您需要根据哪些背景需要 100% 大小来执行类似的操作:

background: url(/assets/images/site/bg-hero-l.svg) left top no-repeat,
            url(/assets/images/site/bg-hero-r.svg) right top no-repeat,
            url(/assets/images/site/hero-banner.jpg) top/100% no-repeat fixed;

关于多个背景图像上的 CSS 背景大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55378949/

相关文章:

html - 如何在 HTML 中使一个部分适合 100% 的视口(viewport)

css - 背景封面不适用于移动设备

html - 背景图片仅适用于 Chrome

指针光标的 CSS 类

jquery - sweetAlert - 不在确认按钮点击时调用函数

animation - css3 过渡不应该在高度 : 100% and height: 200px? 之间设置动画

javascript - 不使用 ID 和 FOR 并使用 angular.js 的自定义复选框/单选按钮

css - 加载 CSS 时背景属性的 URL 消失

java - 将视频或动画添加到 netbeans 中的 jframe

html - 如何使用伪类 :active :visited :hover? 为带有背景图像的 div 设置样式