批改状态:合格
老师批语:元素的对齐, 一直在布局界永恒的话题, 很有意思

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>盒模型常用属性</title><style>.box{width: 120px;height: 100px;}.box.one{/* 1.padding:内边距 */padding:40px;/* 2.margin:外边距 margin-top,margin-bottom */margin-bottom: 20px;/*3.border: 边框:=粗细+虚实+颜色 */border:10px solid rgb(49, 192, 44);/* 4.background-color: 背景色; */background-color: lightcoral;/* 5.background-clip:规定背景的绘制区域 它有三个值:*//* background-clip: content-box;--背景被裁剪到内容框。 *//* background-clip:padding-box-- 背景被裁剪到内边距框。 *//* background-clip:border-box --背景被裁剪到边框盒。 */background-clip: content-box;}.box.two{padding:10px;margin-top: 40px;border:2px solid lightcoral;background-color: lightgreen;background-clip:padding-box;}.box.parent{width:300px;height: 200px;border:5px solid yellow;background-color: lightblue;/* 6.position:一旦一个元素被添加了position,且值非static,那么她就是定位元素 *//* position: static;--HTML 元素的默认值,即没有定位,遵循正常的文档流对象。 *//* position:fixed;--元素的位置相对于浏览器窗口是固定位置。即使窗口是滚动的它也不会移动: *//* position:relative;--相对定位元素的定位是相对其正常位置。 *//* position:absolute;--绝对定位的元素的位置相对于最近的已定位父元素,如果元素没有已定位的父元素,那么它的位置相对于<html>: *//* position: sticky;-- 基于用户的滚动位置来定位。 */position:relative;/* 相对定位是相对自己做了偏移,这个元素在文档流中的位置不释放 */left:30px;top:40px;}.son.no1{width: 100px;height: 140px;background-color:orange;/* position:absolute;--绝对定位:相对于其定位父级进行定位 */position:absolute;/* fixed-固定定位总是相对于body定位,忽略其定位的父级 */position:fixed;/* 相同的属性,优先级按顺序执行,后面的覆盖前面的,这3个position,最后一个有效 *//* position:absolute; */left: 200px;top:10px;}.son.no2{width: 100px;height: 140px;background-color:purple;/* position:absolute;--绝对定位:相对于其定位父级进行定位 */position:absolute;/* fixed-固定定位总是相对于body定位,忽略其定位的父级 *//* position:fixed; *//* 相同的属性,优先级按顺序执行,后面的覆盖前面的,这3个position,最后一个有效 *//* position:absolute; */right: 170px;bottom:10px;}</style></head><body><div class="box one"></div><div class="box two"></div><hr/><div class="box parent"><div class="son no1"></div><div class="son no2"></div></div></body></html>



<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>元素大小的计算</title><style>/* 样式初始化 */.box1{margin: 0;padding:0;/*1. box-sizing 属性有3个值: *//* 1.1 box-sizing:border-box;元素的宽度和高度包括 padding 和 border *//* 1.2 box-sizing: content-box;指定元素的宽度和高度(最小/最大属性)适用于box的宽度和高度。元素的填充和边框布局和绘制指定宽度和高度除外 *//* 1.3 box-sizing: inherit;指定 box-sizing 属性的值,应该从父元素继承 */box-sizing: border-box;/* 元素的宽度和高度包括 padding 和 border */}.box11{width: 100px;height: 80px;background-color:red ;border:4px dashed blue ;padding:10px;margin-bottom: 20px;/* 1.1 box-sizing:border-box;元素的宽度和高度包括了 padding 和 border */box-sizing: border-box;/* 2.background-clip:规定背景的绘制区域 它有三个值:*//* 2.1 background-clip: content-box;--背景被裁剪到内容框。 *//* 2.2 background-clip:padding-box-- 背景被裁剪到内边距框。 *//* 2.3 background-clip:border-box --背景被裁剪到边框盒。 */background-clip:content-box;/* width :100=border4*2+padding10*2+contentbox72 ; *//* height:80=border4*2+padding10*2+contentbox52 ; *//* 背景颜色大小:72*52; */}.box12{width: 100px;height: 80px;background-color:red ;border:4px dashed blue ;padding:10px;margin-bottom: 20px;box-sizing: border-box;/* 2.2 background-clip:padding-box-- 背景被裁剪到内边距框。 */background-clip:padding-box;/* width :100=border4*2+padding10*2+contentbox72 ; *//* height:80=border4*2+padding10*2+contentbox52 ; *//* 背景颜色大小:(100-4*2)*(80-4*2)=92*72; */}.box13{width: 100px;height: 80px;background-color:red ;border:4px dashed blue ;padding:10px;margin-bottom: 10px;box-sizing: border-box;/* 2.3 background-clip:border-box --背景被裁剪到边框盒。 */background-clip:border-box;/* width :100=border4*2+padding10*2+contentbox72 ; *//* height:80=border4*2+padding10*2+contentbox52 ; *//* 背景颜色大小:100*80; */}.box21{width: 100px;height: 80px;background-color:orange;border:4px solid blue;padding: 20px;margin-bottom: 10px;box-sizing: content-box;background-clip:content-box/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:100*80; */}.box22{width: 100px;height: 80px;background-color: orange;border:4px dashed blue;padding: 20px;margin-bottom: 10px;box-sizing: content-box;background-clip:padding-box;/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:(100+20*2)*(80+20*2)=140*120; */}.box23{width: 100px;height: 80px;background-color:orange;border:4px dashed blue;padding: 20px;margin-bottom: 10px;box-sizing: content-box;background-clip:border-box;/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:(100+20*2+4*2)*(80+20*2+4*2)=148*128; */}.box31{width: 100px;height: 80px;background-color: lightgreen;border:4px dashed red;padding: 20px;margin-bottom: 10px;box-sizing: inherit;background-clip: content-box ;/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:100*80; */}.box32{width: 100px;height: 80px;background-color: lightgreen;border:4px dashed red;padding: 20px;margin-bottom: 10px;box-sizing: inherit;background-clip:padding-box;/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:(100+20*2)*(80+20*2)=140*120; */}.box33{width: 100px;height: 80px;background-color: lightgreen;border:4px dashed red;padding: 20px;margin-bottom: 10px;box-sizing: inherit;background-clip:border-box;/* width :=border4*2+padding20*2+contentbox100=148 ; *//* height:=border4*2+padding20*2+contentbox80=128 ; *//* 背景颜色大小:(100+20*2+4*2)*(80+20*2+4*2)=148*128; */}</style></head><body><h3> 一、 box-sizing: border-box; 元素的宽度和高度包括 padding 和 border </h3><p> box1: width :100=border4*2+padding10*2+contentbox72 ; </p><p> box1: height:80=border4*2+padding10*2+contentbox52 ; </p><br/><div class="box1"><p>1. box11:背景颜色大小:72*52; </p><div class="box11">box11 </div><p>2. box12:背景颜色大小:(100-4*2)*(80-4*2)=92*72; </p><div class="box12">box12</div><p>3. box13: 背景颜色大小:100*80; </p><div class="box13">box13</div></div><hr/><h3> 二、 box-sizing: content-box;指定元素的宽度和高度(最小/最大属性)适用于box的宽度和高度。<br>元素的填充和边框布局和绘制指定宽度和高度除外 */ </h3><p> box2: width :=border4*2+padding20*2+contentbox100=148 ; </p><p> box2: height:=border4*2+padding20*2+contentbox80=128 ; </p><br><div class="box2">1. 背景颜色大小:100*80;<div class="box21">box21 </div>2.背景颜色大小:(100+20*2)*(80+20*2)=140*120;<div class="box22">box22</div>3.背景颜色大小:(100+20*2+4*2)*(80+20*2+4*2)=148*128;<div class="box23">box23</div></div><hr/><h3>三、 box-sizing: inherit;指定 box-sizing 属性的值,应该从父元素继承</h3><p> box3: width :=border4*2+padding20*2+contentbox100=148 ; </p><p> box3: height:=border4*2+padding20*2+contentbox80=128 ; </p><div class="box3">1. 背景颜色大小:100*80;<div class="box31">box31 </div>2. 背景颜色大小:(100+20*2)*(80+20*2)=140*120;<div class="box32">box32</div>3.背景颜色大小:(100+20*2+4*2)*(80+20*2+4*2)=148*128;<div class="box33">box33</div></div></body></html>
margin-left:auto;margin-right:auto;
position:absolute;top:0;left: 0;right:0;bottom: 0;margin: auto;

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>元素的水平与垂直定位</title><style>.container{margin-top:60px;margin-left:20px;width: 300px;height: 300px;border:10px dashed orange;background-color: lightgreen;/* 转为定位元素 */position:relative;}.box1{width: 120px;height: 60px;border:5px dashed blue;background-color: yellow;color:red;/* 水平居中 *//* 让浏览器自动计算左右居中margin-left:auto; margin-right:auto; */margin-left:auto;margin-right:auto;}.box2{width: 160px;height: 80px;border:5px dashed yellow;background-color: lightsalmon;color:blue;/* 通过绝对定位来实现垂直居中 */position:absolute;/* 让当前元素绝对定位的上下文充满整个父级容器 *//* 左上角开始 */top:0;left: 0;/* 右下角结束 */right:0;bottom: 0;margin: auto;}form{width: 300px;height: 200px;background-color: lightpink;position: absolute;top:0;left: 0;right:0;bottom: 0;margin: auto;}form label{background-color: yellow;color:brown;}form input{background-color: lightgoldenrodyellow;color:red;}input:focus {background-color: rgb(39, 214, 62);}.btn{width: 90px;height: 40px;background-color: orangered;color:black;font-size: 1.2rem;margin-top: 10px;margin-left: 120px;}</style><body><div class="container"><div class="box1"> box1水平居中</div><div class="box2">box2垂直居中</div></div><hr/><form action=""><p>电话呼叫系统:</p><label for="acode">区号:</label><input type="area code" name="acode" id="acode"placeholder="3位数字" autofocus required /><br><label for="telephone">电话号码:</label><input type="text" name="phone" id="telephone" placeholder="8位数字" required/><br><button class="btn">拨打</button></form></body></html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号