把寬改為100px之后,margin設(shè)為-50px 0 0 -50px 沒有居中?
.box1 {
? ? ? ? position: absolute;
? ? ? ? top:50%;
? ? ? ? left:50%;
? ? ? ? margin:-50px 0px 0px -50px;
? ? ? ? width: 100px;
? ? ? ? height: 200px;
? ? ? ? border: 1px solid red;
? ? ? ??
? ? }
.box1 {
? ? ? ? position: absolute;
? ? ? ? top:50%;
? ? ? ? left:50%;
? ? ? ? margin:-50px 0px 0px -50px;
? ? ? ? width: 100px;
? ? ? ? height: 200px;
? ? ? ? border: 1px solid red;
? ? ? ??
? ? }
2020-08-13
舉報(bào)
2020-08-13
margin里面上和左是自身寬高值的一半,.box1的高度是200px,margin應(yīng)該是:-50px 0 0 -100px
2020-08-18
上面回答是錯(cuò)的叭,margin:-100px 0 0 -50px,第一個(gè)是:-height/2 ? 最后一個(gè)是-width/2吧
2020-08-15
謝謝你
2020-08-13
這種效果