[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"qk_443_300.png","link":"https://pan.quark.cn/s/6229b93c70d0","name":"夸克网盘","status":9,"txt":"夸克网盘","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
方法一:常见的居中方法,定位 <!DOCTYPE html> <html> <head> <meta charset="utf-8" />
<title></title> <style type="text/css"> /*常见的居中:定位方法*/ .father{ width: 200px;
height: 200px; background-color: red; position: relative; } .child{
width:100px; height: 100px; background-color:blue; position: absolute; /* * top
bottom 为 0垂直居中 * left right 为0 则水平居中 */ top: 0; bottom: 0; right: 0; left: 0;
margin: auto; } </style> </head> <body> <!-- div 的几种居中方法 --> <div
style="width:200px;text-align: center; ">方法一:</div> <div class="father"> <div
class="child"></div> </div> </body> </html> } 方法二:负边距居中法 <!DOCTYPE html>
<html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css">
/*负边距居中*/ .father2{ width: 200px; height: 200px; background-color: red;
position: relative; } .child2{ width: 100px; height: 100px;
background-color:blue; text-align: center; position: absolute; top: 50%; left:
50%; margin-top: -50px; margin-left: -50px; } </style> </head> <body> <!-- div
的几种居中方法 --> <div style="width:200px;text-align: center;">方法二:</div> <div
class="father2"> <div class="child2"></div> </div> </body> </html>
方法三:弹性布局居中(未知宽高也可以) <!DOCTYPE html> <html> <head> <meta charset="utf-8" />
<title></title> <style type="text/css"> /*弹性布局居中(未知宽高也可以)*/ .father3{ width:
200px; height: 200px; background-color: red; margin-bottom: 100px; position:
relative; display: flex; align-items: center; justify-content: center; }
.child3{ width: 100px; height: 100px; background-color: blue; } </style>
</head> <body> <!-- div 的几种居中方法 --> <div style="width:200px;text-align:
center;">方法三:</div> <div class="father3"> <div class="child3"></div> </div>
</body> </html>