这里的div为什么加了个固定定位,但为什么不是在浏览器的左上角呢
来源:2-7 编程练习
慕用6234762
2021-01-17 16:50:58
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>3-1作业</title>
<style>
div {
font-size: 14px;
font-weight: bold;
line-height: 50px;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 200px;
height: 50px;
margin: auto;
cursor: pointer;
text-align: center;
background: #abcdef;
/*此处写代码*/
}
/*此处写代码*/
</style>
</head>
<body>
<div>www.imooc.com</div>
</body>
</html>
1回答
好帮手慕慕子
2021-01-17
同学你好,因为div的top、right、bottom和left属性值设置为0,然后又设置了margin属性值为auto,如下图所示:
语法中规定,这样设置后,div就会自动均分四周剩余的空间,实现水平垂直居中显示,所以不会在浏览器的左上角显示。
祝学习愉快~
相似问题