<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/css/demo-1503.css">
<title>固定定位</title>
</head>
<body>
<h1>采用固定定位制作广告位</h1>
<div class="ads">
<!--关闭按钮-->
<button onclick="this.parentNode.style.display = 'none'">关闭</button>
<h2>广告位</h2>
<img src="/static/images/1.jpg" width="300px">
</div>
</body>
</html>
样式文件如下:
body{
margin:0;
height: 2000px;
background-image: url(/static/images/3.png);
background-size: initial;
}
.ads{
width: 350px;
height: 250px;
background-color: azure;
position: fixed;
right: 0;
bottom: 0;
}
.ads button{
float:right;
margin-right: 20px;
}
重点: 要实现广告位漂浮在网页的右下角需要设置广告位div样式right:0;bottom:0;