批改状态:合格
老师批语:理解了为什么这么做,步骤很重要
盒模型的大小为:
div {width: 300px;border: 25px solid green;padding: 25px;margin: 25px;}
position 属性指定了元素的定位类型。
不设置box-sizing与设置box-sizing对比
div{width:100%;height:100px;border:10px solid grey;box-sizing:border-box;background:red;}


.content.box1 {width: 300px;height: 200px;background-color: lightblue;position: absolute;left: 30px;top: 20px;}

.content.box2 {width: 300px;height: 200px;background-color: lightgreen;position: relative;left: 30px;top: 20px;}

.content.box2 {width: 300px;height: 200px;background-color: lightcoral;position: fixed;right: 30px;top: 20px;}

.content.box1 {width: 600px;height: 400px;background-color: lightblue;position: relative;}.content.box2 {width: 200px;height: 100px;background-color: yellow;position: absolute;top: 0;right: 0;bottom: 0;left: 0;margin: auto;}

.content {width: 1000px;position: relative;margin: auto;}.content.box1 {width: 200px;height: 400px;background-color: lightblue;position: absolute;top: 10px;left: 0;}.content.box2 {width: 800px;height: 400px;background-color: yellow;position: absolute;top: 10px;right: 0;}

.content {width: 1000px;position: relative;margin: auto;}.content.box1 {width: 200px;height: 400px;background-color: lightblue;float: left;}.content.box2 {width: 600px;height: 400px;background-color: yellow;float: left;}.content.box3 {width: 200px;height: 400px;background-color: lightcoral;float: right;}

再给左右两侧通过相对定位将它们最终放到正确位置上
.content {width: 1000px;position: relative;margin: auto;float: left;}.content.box1 {width: 100%;height: 400px;background-color: lightblue;padding: 0 200px;}.content.box2 {width: 200px;height: 400px;background-color: yellow;margin-left: -100%;position: relative;left: -400px;}.content.box3 {width: 200px;height: 400px;background-color: lightcoral;margin-left: -200px;position: relative;left: 0;}

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