<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>0426作业</title> <!--<link rel="stylesheet" href="static/css/style8.css">--> <style> body { margin: 0; background-color: green; /*background-size: cover;*/ } .shade { /* 遮罩绝对定位,并自动伸展到整个窗口 */ position: absolute; left: 0; top: 0; width: 100%; height: 100%; /* 将背景设置为纯黑,并通过透明度使背影内容透出来 */ background-color: black; opacity: 0.7; } .login img { height: 460px; width: 380px; } .login { position: absolute; left: 50%; top: 50%; width: 200px; height: 300px; background-color: blanchedalmond; margin-left: -100px; margin-top: -150px; border-radius: 10%; color: red; line-height: 300px; text-align: center; box-shadow: 2px 2px 1px #888; } .ads{ position: fixed; right: 0; bottom:0; background-color: blanchedalmond; border-radius: 30%; } button { position: absolute; top:0; right: 0; margin-right: 5px; background: none; border: none; font-size: 2em; color: red; } </style> </head> <body> <div class="shade"></div> <div class="login">请在这里登录</div> <div class="ads"> <p> 总结:<br> 1.遮罩的使用,遮罩两个属性值注意 opacity 透明度; 设置一个背景色。<br> 2.浮动窗口居中需要拉回去。<br> <button onclick="this.parentNode.style.display = 'none'">X</button> </p> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例