Correction status:qualified
Teacher's comments:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>相对定位</title> <style> .box1 { width: 200px; height: 200px; background-color: lightblue; position: relative; left: 200px; top: 0; } .box2 { width: 200px; height: 200px; background-color: lightgreen; } .box3 { width: 200px; height: 200px; background-color: lightcoral; position: relative; left: 400px; top: -200px; } .box4 { width: 200px; height: 200px; background-color: lightgrey; position: relative; top: -200px; left: 200px; } </style> </head> <body> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> <div class="box4"></div> </body> </html>
点击 "运行实例" 按钮查看在线实例
<!doctype html> <html> <head> <title>4种元素的对齐方案</title> <meta charset="utf-8"> </head> <body> <div class="box1" > <a href="https://www.baidu.com">baidu</a> </div> <div class="box2"> <span>我是一个行内文本</span><br> <span>我是一个行内文本</span> </div> <div class="box3"> <div id="child">块元素</div> </div> <div class="box4"> <ul> <li><a href="">1</a></li> <li><a href="">2</a></li> <li><a href="">3</a></li> <li><a href="">4</a></li> <li><a href="">5</a></li> </ul> </div> <style> /*1. 子元素是单行行内元素: 如a, span a:水平居中: 在父元素应用: text-align: center; b:垂直居中: 在行内子元素上设置行高与父元素等高: line-height:200px; */ .box1{ color:white;/*在这个地方设置字体颜色没用*/ width:200px; height:200px; background:black; text-align:center;/*水平居中*/ } .box1 a { line-height:200px;/*垂直居中*/ color:white; } /*2 子元素是多行的行内元素: a:水平居中: 在父元素应用: text-align: center; b:垂直居中: 在父元素: display:table-cell;*/ .box2{ color:#FFD801; width:200px; height:200px; background:#F62217; text-align: center; /*水平居中*/ display:table-cell; vertical-align: middle; /*垂直居中*/ } /*3 子元素是块元素 a: 水平居中: 子元素设置左右外边距自动适应容器margin: auto; b:垂直居中: 在父元素: display:table-cell;*/ .box3{ color:#FF00FF; width:200px; height:200px; background:#FAAFBE; display:table-cell; vertical-align: middle;/*垂直居中*/ } .box3 #child{ width: 100px; height: 100px; background:red; color:black; margin:auto; /*水平居中*/ } .box4 { width: 200px; height: 200px; background-color: lightblue; text-align: center; /*水平居中*/ display: table-cell; vertical-align: bottom; /*位于底部*/ } ul { margin: 0; padding-left: 0; } .box4 li { display: inline; /*将块元素转为行内元素*/ } </style> </body> </html>
点击 "运行实例" 按钮查看在线实例
<!DOCTYPE HTML> <HTML> <HEAD> <TITLE>盒子模型基本要素</TITLE> <meat charset="utf-8"> </HEAD> <body> <div class="box1">我是第1个盒子</div> <div class="box2">我是第2个盒子</div> <div class="box3">我是第3个盒子</div> <div class="box4">我是第4个盒子</div> <style> .box1{ width:200px; height:200px; color:red; background:black; /*padding-top:10px; padding-right:30px; padding-bottom:20px; padding-left:20px;*/ padding:10px 30px 20px 20px; /*border-top-width:5px; border-top-color:red; border-top-style: solid;*/ border-top:5px solid red; border-right:5px dashed red; border-bottom:5px solid red; border-left:5px dashed red; /*margin-top:10px; margin-right:20px; margin-bottom:30px; margin-left:40px;*/ margin:10px 20px 30px 40px; } </style> </body> </HTML>
点击 "运行实例" 按钮查看在线实例