这是我在这里的第一篇文章,我是CSS的新手。我正在尝试获取尺寸为32 x 16的精灵Mario。当我打开html文件时,什么也没有出现。我试着检查html元素,但我看不到div。
CSS
#stillMario {
width: 16px;
height: 32px;
margin: auto;
background-image: url("sprites/still.png");
position:absolute;
left: 0px;
top: 0px;
bottom:0px;
}
HTML
<!DOCTYPE html>
<html>
<head>
<title>Super Mario</title>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="stillMario"></div>
<script src="myjs.js"></script>
</body>
</html>
发布于 2017-11-18 07:29:38
使用<img>元素而不是设置<div>的背景。
示例:<img src=""sprites/still.png"" alt="Mario" height="32" width="16">
发布于 2017-11-18 07:34:00
如果您确定文件夹'sprites‘位于项目的根目录中,请尝试在它前面加上'../’前缀,然后先尝试不使用绝对位置。如果有效,则再次返回定位,如下所示;
#stillMario {
width: 16px;
height: 32px;
margin: auto;
background-image: url("../sprites/still.png");
//position:absolute;
//left: 0px;
//top: 0px;
//bottom:0px;
}如果有效,请让我知道
https://stackoverflow.com/questions/47360750
复制相似问题