如果position:fixed 失效,那應該是你設置position的元素的父元素中有設置了transform屬性哦 。
把 transform刪除或設置為none就可以解決啦。
但是如果transform是必要的,不能刪除,我們可以在此父級最外層再加一層元素專門用于定位,這樣position:fixed就能生效啦。
舉個栗子:
/* 一定要將ancestor和parent的大小設置為一樣大*/
.ancestor{
position: relative; /*重點*/
width: 300px;
height: 300px;
}
.parent {
width: 300px;
height: 300px;
overflow: auto; /*重點*/
}
.child {
position: absolute;/*重點*/
width: 320px;
height: 320px;
}
嗯...大概意思就這樣。