【发布时间】:2026-02-06 07:50:01
【问题描述】:
我有这个 CSS 代码:
<style>
body {
position:absolute;
background-image: url(art/c11.jpg);
width:100%;
height:100%;
}
</style>
当我在网上阅读时,我预计这会调整背景图像的大小并使其适合浏览器窗口。
但是没有。我想我显然做错了什么(我不知道足够的 CSS)。有什么建议吗?
更新:
我添加了孔示例(不起作用):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>No Title</title>
<style type="text/css">
body {
position:absolute;
background-image:url(art/c11.jpg);
background-size:100%;
background-repeat: no-repeat;
width:100%;
height:100%;
}
</style>
</head>
<body >
</body>
</html>
【问题讨论】:
-
你定位你的身体元素有什么原因吗?这应该不是必需的,但将主体的边距和填充设置为 0 通常是一个好主意。这会使一些浏览器的古怪默认值正常化。