的問題,我相信,是你left
和right
值。下面的代碼將做到這一點。
body {
width: 5000px;
height: 5000px;
}
#element {
width: 75px;
height: 25px;
position: fixed;
top: 100%;
left: 50%;
transform: translate(-50%, -100%);
border: solid orange 2px;
}
<div id="element"></div>
的translate
方法調整元件相對於自身的位置。例如,如果您有一個帶有width: 100px
並且設置爲transform: translateX(-50%)
的元素,它會將元素50px
移動到位置所在的左側。
top: 100%;
left: 50%;
作品是這樣的...
_________________
| |
| |
| |
| |
| |
| |
| |
|_________________|
|___e___|
和
transform: translate(-50%, -100%)
作品是這樣的...
_________________
| |
| |
| |
| |
| |
| |
| _______ |
|____|___e___|____|
你能鏈接一個JSFiddle嗎? –
此外,我敢肯定這個問題是http://stackoverflow.com/questions/3303173/position-element-fixed-vertically-absolute-horizontally –