Css 如何避免使用多个响应背景重复背景规格
以下是当前代码:Css 如何避免使用多个响应背景重复背景规格,css,sass,background-image,responsive,Css,Sass,Background Image,Responsive,以下是当前代码: .description-1-section{ background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), url('../images/fondo-1-s.jpg'); background-repeat: no-repeat; background-size: cover; color: $white; @include mq($medium-up){
.description-1-section{
background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), url('../images/fondo-1-s.jpg');
background-repeat: no-repeat;
background-size: cover;
color: $white;
@include mq($medium-up){
background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), url('../images/fondo-1-m.jpg');
background-repeat: no-repeat;
background-size: cover;
}
@include mq($medium-aux-up){
background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), url('../images/fondo-1.jpg');
background-repeat: no-repeat;
background-size: cover;
}
}
我发现正在使用多个BG(在本例中为渐变+图像),当出于断点目的更新某些值时,似乎我必须重复附件指令(background repeat:no repeat;background size:cover;
)
在这个用例中有没有避免这种重复的方法?使用CSS变量,并将背景大小和重复放在速记中。您还将避免重复渐变:
.description-1-section{
background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), var(--im,url('../images/fondo-1-s.jpg')) center/cover no-repeat;
color: $white;
@include mq($medium-up){
--im: url('../images/fondo-1-m.jpg');
}
@include mq($medium-aux-up){
--im: url('../images/fondo-1.jpg');
}
}
要测试的工作示例:
。说明-1-部分{
背景:
线性梯度(0度,#464646 30.75%,rgba(51,51,51,0)100%),
var(--im,url('https://picsum.photos/id/1/600/200“))中间/盖不重复;
高度:50px;
}
医学博士{
--im:url('https://picsum.photos/id/10/600/200');
}
.ml{
--im:url('https://picsum.photos/id/12/600/200');
}
}
使用CSS变量,并在速记中输入背景大小和重复。您还将避免重复渐变:
.description-1-section{
background: linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%), var(--im,url('../images/fondo-1-s.jpg')) center/cover no-repeat;
color: $white;
@include mq($medium-up){
--im: url('../images/fondo-1-m.jpg');
}
@include mq($medium-aux-up){
--im: url('../images/fondo-1.jpg');
}
}
要测试的工作示例:
。说明-1-部分{
背景:
线性梯度(0度,#464646 30.75%,rgba(51,51,51,0)100%),
var(--im,url('https://picsum.photos/id/1/600/200“))中间/盖不重复;
高度:50px;
}
医学博士{
--im:url('https://picsum.photos/id/10/600/200');
}
.ml{
--im:url('https://picsum.photos/id/12/600/200');
}
}
使用速记
背景
重置未单独列出的隐式属性
背景速记CSS属性一次设置所有背景样式属性,例如颜色、图像、原点和大小,或重复方法
我建议只使用背景图像
background-image:
linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%),
url('../images/fondo-1-s.jpg');
使用速记
后台
重置未单独列出的隐式属性
背景速记CSS属性一次设置所有背景样式属性,例如颜色、图像、原点和大小,或重复方法
我建议只使用背景图像
background-image:
linear-gradient(0deg, #464646 30.75%, rgba(51, 51, 51, 0) 100%),
url('../images/fondo-1-s.jpg');
不要使用速记
背景:
可能是一个好的开始,因为它会覆盖其他bg属性。改用bg图像。我找不到任何关于如何在没有速记的情况下设置多个背景的有用信息。背景图像:url(1),url(2)代码>-看起来很简单。嗯,太好了!:)您应该将其作为答案发布。不要使用速记背景:
可能是一个好的开始,因为它会覆盖其他bg属性。改用bg图像。我找不到任何关于如何在没有速记的情况下设置多个背景的有用信息。背景图像:url(1),url(2)代码>-看起来很简单。嗯,太好了!:)你应该把它作为答案贴出来。这很有趣,谢谢。如果不使用一些PultPube,它会有一些跨浏览器的问题。@ LucaReghellin,你只会像IE一样有问题:这足够给我的客户一个问题。@ LucaReghellin,顺便说一下,你正在使用SASS,所以考虑变量这很有趣,谢谢。如果不使用一些PultFube,它会有一些跨浏览器的问题。@ LucaReghellin,你只会像IE一样有问题:它足以成为我的客户的一个问题。@ LucaReghellin,顺便说一下,你使用SASS来考虑变量。