问题
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