基本上我使用的是 W3 网站上的“Tryit Editor”, 这是我开始时使用的代码
<!DOCTYPE html>
<html>
<head>
<style>
body
{
background-image:url("img_tree.gif"),url("img_flwr.gif");
background-color:#cccccc;
}
</style>
</head>
<body>
</body>
</html>
我想更改背景颜色和背景图片,以便它们只出现在一个 div 上,而不是出现在整个页面上。我还想在页面周围移动 div。我可以用背景元素制作 div,但无法在页面上移动它。我使用了下面的代码,认为
top:150px;
left: 150px;
会导致 div 改变位置
<!DOCTYPE html>
<html>
<head>
<style>
div
{
position=fixed;
top:150px;
left: 150px;
background-image:url("img_tree.gif"),url("img_flwr.gif");
background-color:#00dccc;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
唉,div 并没有改变位置。给了什么?
谢谢! :]
最佳答案
您在 position
声明中使用等号而不是冒号,这导致页面忽略它。改变它,它就会起作用!
编辑:感谢您修复我糟糕的术语 Pavlo,简直不敢相信我做到了 :P
关于css - 为什么我不能调整我的 div 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18609366/