width: 100%; height: 100%;的问题
在CSS中,如果我把.content的宽度设置为100%,如下代码所示,
.content
{
width: 100%;
height: 4040px;
background: url("../images/mooc.png") center no-repeat;
}
则背景图片显示不完整,浏览器窗口没有水平滚动条,显示效果如下图所示。

如果我把.content的宽度设置为1900px,
.content
{
width: 1900px;
height: 4040px;
background: url("../images/mooc.png") center no-repeat;
}
则背景图片显示完整,并且浏览器窗口有水平滚动条,显示效果如下图所示。

这是为什么呢?我的显示器分辨率是1920×1080。
我使用的图片mooc.jpg,大小是1900×4040(经过自己的修改)。
我的代码如下。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>4-1-示例</title>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
html,
body
{
width: 100%;
height: 100%;
margin: 0 auto;
}
.content
{
/*width: 100%;*/
width: 1900px;
height: 4040px;
background: url("../images/mooc.png") center no-repeat;
}
.opacity
{
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-image: url("../images/opacity.png");
}
.login
{
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 360px;
height: 360px;
background: url("../images/login.png") no-repeat;
}
</style>
</head>
<body>
<div class="content"></div>
<div class="opacity"></div>
<div class="login"></div>
</body>
</html>2
收起
正在回答 回答被采纳积分+1
1回答


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星