批改状态:合格
老师批语:
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>0323作业</title>
<style type="text/css">
/*关于水平居中
1.父元素内为行内元素,多行行内元素,不定宽块元素的,都是通过设置父元素text-align:center属性实现子元素水平居中
2.不定宽的块元素需要先将子元素display属性值转为display:inline,然后在设置父元素text-align属性;*/
.box1 {
width:200px;
height: 200px;
text-align: center;
background-color:blue;
}
.box1 span {
line-height: 200px;
}
.box2 {
width:200px;
height: 200px;
/*设置水平居中*/
text-align: center;
background-color:brown;
/*转为单元格*/
display: table-cell;
/*设置垂直居中*/
vertical-align:middle;
}
.box3 {
width: 200px;
height: 200px;
background-color: red;
/*转为单元格*/
display: table-cell;
/*设置垂直居中*/
vertical-align: middle;
}
.box3 .text {
background-color: yellow;
width:100px;
/*通过设置margin:auto来实现水平居中*/
margin:auto;
}
.box4 {
width: 200px;
height: 200px;
background-color: green;
/*设置水平居中*/
text-align: center;
display: table-cell;
/*vertical-align:bottom; */
}
.box4 ul {
margin: 0;
padding: 0;
line-height: 200px;
}
.box4 li {
list-style: none;
display: inline;
}
</style>
</head>
<body>
<div class="box1">
<span>一行行内元素</span>
</div>
<hr>
<div class="box2">
<span>我里面有多行行内元素,不信你自己看。</span>
</div>
<hr>
<div class="box3">
<p class="text">我是一个块元素</p>
</div>
<hr>
<div class="box4">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
手抄


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