Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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 多个背景图像,并非全部居中_Css_Background Image_Z Index - Fatal编程技术网

Css 多个背景图像,并非全部居中

Css 多个背景图像,并非全部居中,css,background-image,z-index,Css,Background Image,Z Index,我正在尝试使用CSS向DOM元素(td)添加多个背景图像。我可以指定多个相互叠加的背景图像,如下所示: td{ background-image: url("img1.svg"), url("img2.svg"); } 这导致img2堆叠在img1的顶部。但是,我需要指定一个背景图像应该偏离中心,而另一个应该居中。在CSS中有没有一种方法可以做到这一点,或者我需要想象一下这样做吗?您可以使用背景位置属性 background-position: left top, center cen

我正在尝试使用CSS向DOM元素(td)添加多个背景图像。我可以指定多个相互叠加的背景图像,如下所示:

td{
    background-image: url("img1.svg"), url("img2.svg");
}

这导致img2堆叠在img1的顶部。但是,我需要指定一个背景图像应该偏离中心,而另一个应该居中。在CSS中有没有一种方法可以做到这一点,或者我需要想象一下这样做吗?

您可以使用
背景位置
属性

background-position: left top, center center;

如果不想少打字,可以使用
background
速记属性。我真的更喜欢速记


您可以使用
背景位置
属性

background-position: left top, center center;

如果不想少打字,可以使用
background
速记属性。我真的更喜欢速记


您只需对位置规则执行相同的操作:

td{
    background-image: url("img1.svg"), url("img2.svg");
    background-position: center center, left top;  /* or */
    background-position: center center, 0px 0px;   /* x y */
}
第一个应用于第一个图像,第二个应用于第二个图像,依此类推

有关更多详细信息:

您只需对位置规则执行相同的操作:

td{
    background-image: url("img1.svg"), url("img2.svg");
    background-position: center center, left top;  /* or */
    background-position: center center, 0px 0px;   /* x y */
}
第一个应用于第一个图像,第二个应用于第二个图像,依此类推

有关更多详细信息:

它应该是
左上
。虽然当你使用关键词时没关系,但当你使用像素时,它会被解释为
Xpx-Ypx
而不是
Ypx-Xpx
@Sourabh你绝对正确。修正到左上角。ThanksIt应该位于左上方。虽然当你使用关键词时没关系,但当你使用像素时,它会被解释为
Xpx-Ypx
而不是
Ypx-Xpx
@Sourabh你绝对正确。修正到左上角。谢谢