绝对定位元素的写法(十字架)
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>绝对定位元素的写法</title> </head> <style> *{ margin: 0; padding: 0; } .box{ width: 600px; height: 600px; margin: 0 auto; position: relative;; } .box1,.box2,.box3,.box4,.box5{ width: 200px; height: 200px; background: #efefef; text-align: center; line-height: 200px; position: absolute; } .box1{ left: 200px; top: 0; } .box2{ left: 0px; top: 200px; } .box3{ left: 200px; top: 200px; background: #e3e3e3; } .box4{ left: 400px; top: 200px; } .box5{ left: 200px; top: 400px; } </style> <body> <div class="box"> <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> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例