How to position an element just off the top of the browser viewport using only css?

最后都变了- 提交于 2019-12-11 18:48:56

问题


I want an absolutely-positioned element to be just out of the browser window - just off the top of the browser viewport. Note that I cannot provide an exact height of the specified element.

Can this be done? If not, using jQuery is fine too.


回答1:


CSS:

#theElement {
    position: fixed;
    bottom: 100%;
}

jQuery:

var $el = $('#theElement');

$el.css({
    position: 'fixed',
    top: '-' + $el.outerHeight()
});



回答2:


If your element is at body level this should work:

#element {
  position: absolute;
  top: -100%;
}


来源:https://stackoverflow.com/questions/14543589/how-to-position-an-element-just-off-the-top-of-the-browser-viewport-using-only-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!