代码如下:
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>0323</title> <style type="text/css"> .fu1{ /*设置复层宽度300;*/ width: 300px; /*设置子层高度300;*/ height:300px; /*设置背景颜色;*/ background-color: skyblue; /*文本居中;*/ text-align: center; } .fu1 a{ color:red; /*设置行高等于复层行高*/ line-height: 300px; } .fu2{ /*设置复层宽度300;*/ width: 300px; /*设置子层高度300;*/ height:300px; /*设置背景颜色;*/ background-color: skyblue; /*文本居中;*/ text-align: center; /*改为单元格表格*/ display:table-cell; /*垂直居中对齐*/ vertical-align: middle; } .fu3{ /*设置复层宽度300;*/ width: 300px; /*设置子层高度300;*/ height:300px; /*设置背景颜色;*/ background-color: skyblue; display: table-cell; vertical-align: middle; } .zi3{ width: 200px; height: 200px; background-color: yellow; margin:auto; text-align: center; } .fu4{ /*设置复层宽度300;*/ width: 300px; /*设置子层高度300;*/ height:300px; /*设置背景颜色;*/ background-color: skyblue; display: table-cell; vertical-align: bottom; text-align: center; } .fu4 ul { margin:0; padding: 0; background-color: yellow; /*text-align: center;*/ } .fu4 ul li{ display:inline; list-style: none; } </style> </head> <body> <div class="fu1"> <a href="">第一种对其方式子层是单行文本</a> </div> <hr> <div class="fu2"> <span class="zi2">第二种对其方式子层是多行文本</span><hr> <span class="zi2">第二种对其方式子层是多行文本</span> </div> <hr> <div class="fu3"> <div class="zi3">第三种对其方式子层是块元素</div> </div> <hr> <div class="fu4"> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例