批改状态:合格
老师批语:总得来说写的不错,盒模型属性和元素大小相对简单了点!
(注意:IE浏览器内容区宽度包括了内边距和边框的宽度);

<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>fixed绝对定位</title><style type="text/css">/* 浏览器默认外边距8像素,全部初始化0 */* {padding: 0;margin: 0;}.box {width: 400px;height: 400px;background: lightgreen;position: fixed;left: 0;right: 0;top: 0;bottom: 0;margin: auto;}</style></head><body><div class="box"></div></body></html>

<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>absolute水平垂直居中</title><style type="text/css">/* 浏览器默认外边距8像素,全部初始化0 */* {padding: 0;margin: 0;}.box {width: 400px;height: 400px;background: lightgreen;/* 使用absolute时,父元素必须进行相对定位 */position: relative;}.box .boxitem {width: 300px;height: 300px;background: lightsalmon;/* 下面2行是文本在块元素中水平垂直居中 */text-align: center;line-height: 300px;/* 盒子在父容易中水平垂直居中样式 */position: absolute;left: 0;right: 0;top: 0;bottom: 0;margin: auto;/* 盒子宽高固定时,也可以这样来进行水平垂直居中position: absolute;top: 50%;left: 50%;margin-top: -150px;margin-left: -150px; */}</style></head><body><div class="box"><div class="boxitem">盒子在父容器中水平垂直居中</div></div></body></html>

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号