实例
<!DOCTYPE html> <html> <head> <title>用绝对定位实现块级元素十字排布</title> <meta charset="utf-8"> </head> <style type="text/css"> body{ margin:0; background: coral; position: relative; } .box1{ width: 200px; height: 200px; background: lightblue; text-align:center; line-height:200px; position:absolute; left:200px; } .box2{ width: 200px; height: 200px; background: lightgreen; text-align:center; line-height:200px; position:absolute; left:400px; top:200px; } .box3{ width: 200px; height: 200px; background: lightcoral; text-align:center; line-height:200px; position:absolute; left:200px; top:400px; } .box4{ width: 200px; height: 200px; background: lightgray; text-align:center; line-height:200px; position:absolute; top:200px; } .box5{ width: 200px; height: 200px; background: wheat; text-align:center; line-height:200px; position:absolute; left:200px; top:200px; } </style> <body> <div class="box1">1</div> <div class="box2">2</div> <div class="box3">3</div> <div class="box4">4</div> <div class="box5">5</div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例