gpt4 book ai didi

css - 为什么我的背景图片没有出现在 CSS 中?

转载 作者:行者123 更新时间:2023-11-28 02:37:11 31 4
gpt4 key购买 nike

这是我在这里的第一篇文章,我是 CSS 的新手。我正在尝试获取尺寸为 32 x 16 的马里奥 Sprite 。当我打开 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>

最佳答案

如果您确定文件夹“sprites”在元素的根目录中,请尝试在其前面加上“../”前缀,然后先尝试不使用绝对定位。如果成功,则再次返回定位如下;

#stillMario {
width: 16px;
height: 32px;
margin: auto;
background-image: url("../sprites/still.png");
//position:absolute;
//left: 0px;
//top: 0px;
//bottom:0px;
}

如果有用请告诉我

关于css - 为什么我的背景图片没有出现在 CSS 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47360750/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com