老师麻烦帮我检查下
来源:2-14 编程练习
豆包侠
2021-08-19 17:47:06
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding:0;
}
.test{
width: 800px;
height: 100px;
background: red;
position:fixed;
top:0;
left:25%;
}
.out{
width: 100%;
height: 2000px;
background-color: #abcdef;
}
</style>
</head>
<body>
<div class="out">
<div class="test"></div>
</div>
</body>
</html>
1回答
好帮手慕星星
2021-08-19
同学你好,代码没有实现水平居中显示
left设置25%,是根据浏览器页面宽度计算的,而每个显示器分辨率不同,宽度也就会不同。
所以建议这样设置
left为50%,是元素的左上角在页面中心位置,然后向左移动自身宽度一半,元素中心就会和页面中心重合。
祝学习愉快!