关于背景,老师请问如何设置背景使其按照视口等比例显示?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>4-3</title>
<style>
.main{
width: 100%px;
height: 4033px;
background-image: url(http://img1.sycdn.imooc.com/climg//59c9f7ce0001839219034033.png);
position: relative;
margin:0px;
padding: 0px;
}
.right{
width: 224px;
height: 324px;
position: fixed;
right: 0px;
top:50%;
margin-top: -162px;
}
.left{
width: 224px;
height: 324px;
position: fixed;
left: 0px;
top:50%;
margin-top: -162px;
}
</style>
</head>
<body>
<div class="main">
<div class="right">
<img src="http://img1.sycdn.imooc.com/climg//5a3383c70001f1b702240364.png">
</div>
<div class="left">
<img src="http://img1.sycdn.imooc.com/climg//5a3383d00001a3dd02240364.png">
</div>
</div>
</body>
</html>
正在回答
同学,设置百分比是相对于父级来计算的。如果类名为main的元素的高度设置100%,那么需要给body和html设置高度,例如:
祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星