的问题,我相信,是你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 –