
2条回答 默认 最新
本堃不方 2021-12-02 08:49关注最好的就是用弹性盒子,margin值也可以
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box1{ width: 200px; height: 200px; background: salmon; display: flex; justify-content: center; align-items: center; flex-direction: column; } .box1>div{ width: 80%; height: 80px; background: aqua; } .box2{ width: 200px; height: 200px; background: salmon; } .box2>div{ width: 80%; height: 80px; background: aqua; margin: 0 auto; } </style> </head> <body> <div class="box1"> <div>1</div> <br> <div>2</div> </div> <br> <div class="box2"> <div>1</div> <br> <div>2</div> </div> </body> </html>本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用