如何在我的案例中设置我的元素的固定位置

时间:2014-01-08 01:18:32

标签: html css

无论设备或屏幕大小是多少,我都会尝试将元素设置在屏幕左侧和右侧的边缘。

我正在使用bootstrap并且有类似

的东西
<a href='#' id='prev' class='btn btn-primary'>left button</a>

<a href='#' id='next' class='btn btn-primary'>right button</a>

我的css就像

#prev{
    position: fixed;
    top: 50%;
    left: 0%;
}

#next{
    position: fixed;
   top: 50%;
    left: 95%;
}

我想要像

这样的东西
left button(edge of screen)                           right button(edge of screen)

左键似乎很好,但我的问题是右键。 我的CSS仅适用于某些屏幕尺寸,但并非全部。有人可以帮我解决这个问题吗?非常感谢!

3 个答案:

答案 0 :(得分:0)

尝试设置right属性:

#prev{
    position: fixed;
    top: 50%;
    left: 0;
}

#next{
    position: fixed;
   top: 50%;
    right: 0;
}

JS小提琴: http://jsfiddle.net/6gw3K/

答案 1 :(得分:0)

使用权限:0代表#next

#prev{
    position: fixed;
    top: 50%;
    left: 0;
}

#next{
    position: fixed;
    top: 50%;
    right: 0;
}

答案 2 :(得分:0)

假设固定位置不是硬性要求,您可以考虑使用浮动。 E.g:

#pref{ float:left; }
#next{ float: right; }

请参阅this jsfiddle