请问我的背景左右为什么会溢出视口?为什么我右边广告始终相对右边有一定距离?
来源:4-3 编程练习
V仔兽7022
2019-04-09 15:28:32
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
padding:0;
margin:0;
}
.back{
width:100%;
height:3000px;
background: url(http://climg.mukewang.com/59c9f7ce0001839219034033.png) center top no-repeat;
position:relative;
}
.ad1{
width:300px;
height:600px;
background:url(http://climg.mukewang.com/5a3383c70001f1b702240364.png) no-repeat;
position:fixed;
top:50%;
margin-top:-300px;
left:0;
}
.ad2{
width:300px;
height:600px;
background: url(http://climg.mukewang.com/5a3383d00001a3dd02240364.png) no-repeat;
position:fixed;
top:50%;
margin-top: -300px;
right:0;
}
</style>
</head>
<body>
<div class="back">
<div class="ad1"></div>
<div class="ad2"></div>
</div>
</body>
</html>
1回答
同学你好!
经过测试 背景左右没有溢出视口。或者说是因为浏览器分辨率的问题,
可以给背景图片设置一个固定宽度,或者设置min-width;
右边广告距离浏览器最右侧有距离是因为宽高设置的不太合适,
建议修改外层div为img图片的宽高,相应的margin-top的值也应该修改:
如果帮助到了你欢迎采纳~
祝学习愉快!
相似问题