Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
减少CSS-ID和背景参数_Css_Less - Fatal编程技术网

减少CSS-ID和背景参数

减少CSS-ID和背景参数,css,less,Css,Less,而不是在我的.less文件中重复此CSS。有人知道如何为以下内容创建较少的函数吗 li #prize-1 span { background: url('@{imagesUrl}/1.png') no-repeat; width: 874px; height: 188px; } li #prize-2 span { background

而不是在我的.less文件中重复此CSS。有人知道如何为以下内容创建较少的函数吗

li  #prize-1 span {
                background: url('@{imagesUrl}/1.png') no-repeat;
                width: 874px;
                height: 188px;
            }   
li  #prize-2 span {
                background: url('@{imagesUrl}/2.png') no-repeat;
                width: 874px;
                height: 188px;
            }

不是这样吗

.definition (@image: nameOfImageDefault) {
  background: url('@{imagesUrl}/@{image}') no-repeat;
  width: 874px;
  height: 188px;
}

li  #prize-1 span {
    .definition(nameOfImage);
        }   
li  #prize-2 span {
    .definition(nameOfImage);
}
我对LESS不太熟悉,所以我认为这是可行的

编辑:

我在他们的主页上遵循这个例子

.rounded-corners (@radius: 5px) {
  border-radius: @radius;
  -webkit-border-radius: @radius;
  -moz-border-radius: @radius;
}

#header {
  .rounded-corners;
}
#footer {
  .rounded-corners(10px);
}

还有哪部分不起作用?背景图像?可能尝试以名称作为变量的整个图像路径

@user1381806能否尝试将imageUrl定义为正在使用路径而不是定义中的变量。我没有较少的安装,因此无法测试它。你能发布你的代码吗?我编辑了我的答案,源代码,我刚刚在“图像”周围添加了{}我确信它是这样的,如果不是那样的话,但是有一种方法可以确定