1

我有一个显示图像的 img 标签。这很好。在同一个文件中,我有一个 div,其类具有具有相同 url 和相同文件的背景图像。img 有效,但 CSS 背景无效。

<img src="../../Content/Themes/Default/images/DeleteIcon.jpg" />

#droptarget
{
    border: 1px solid #959595;
    height: 100px;
    width: 100px;
    content:'Drop here to Delete';
    background: url('../../Content/Themes/Default/images/DeleteIcon.jpg') no-repeat 140px 102px;
}
4

3 回答 3

1

摆脱你的 x 和 y 坐标偏移。它将它推出div。

 background: url('../../Content/Themes/Default/images/DeleteIcon.jpg') no-repeat;
于 2013-08-03T07:59:36.137 回答
1

0 0用作背景位置:jsFiddle
这里

于 2013-08-03T08:00:56.620 回答
0

你也可以这样使用background-imagebackground-repeat

#droptarget {
    border: 1px solid #959595;
    height: 100px;
    width: 100px;
    content:'Drop here to Delete';
    background-image: url('../../Content/Themes/Default/images/DeleteIcon.jpg');
    background-repeat: no-repeat;
}

如果您background-position从其他元素继承,您可以添加:

#droptarget {
    border: 1px solid #959595;
    height: 100px;
    width: 100px;
    content:'Drop here to Delete';
    background-image: url('../../Content/Themes/Default/images/DeleteIcon.jpg');
    background-repeat: no-repeat;
    background-position: 0 0;
}
于 2013-08-03T08:07:39.710 回答