使用css3的transform:translate(-50%,-50%)能夠居中,但我為什么做不出來,設置寬高都為200px;但是展示時候它一半被隱藏起來了,只剩下100px展示。
2 回答

Bigboss_0101
TA貢獻1條經驗 獲得超0個贊
<!DOCTYPE html><html lang="en"><head>
?<meta charset="UTF-8">
?<title>Document</title>
?<style>
? ?*{
? ? ?margin:0;
? ? ?padding:0;
? ?}
? ?#box1{
? ? ?width: 1000px;
? ? ?height: 1000px;
? ? ?background: #ccc;
? ? ?position:relative;
? ?}
? ?#box2{
? ? ?width: 200px;
? ? ?height: 200px;
? ? ?background: #f00;
? ? ?position:absolute;
? ? ?top:50%;
? ? ?left:50%;
? ? ?transform:translate(-50%,-50%);
? ?}
?</style></head><body>
?<div id="box1">
? ?<div id="box2"></div>
?</div></body></html>
- 2 回答
- 0 關注
- 5567 瀏覽
相關問題推薦
添加回答
舉報
0/150
提交
取消