批改状态:合格
老师批语:还不错,一天的作业写在一起!
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>margin:auto 块元素垂直居中</title><style>.container {width: 300px;height: 300px;background-color: lightgreen;position: relative;}.container .item {width: 100px;height: 100px;background-color: violet;/* 水平居中 *//* margin-left: auto; *//* margin-right: auto; *//* 垂直居中,margin-top,margin bottom 0 *//* margin-top: auto; *//* margin-bottom: auto; *//* 通过绝对定位元素实现垂直居中 */position: absolute;/* 让当前元素绝对定位的上下文充满整个父级容器 */top: 0;left: 0;right: 0;bottom: 0;/* 水平垂直居中 */margin: auto;}</style></head><body><div class="container"><div class="item"></div></div></body></html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号