Zerium
Zerium

Reputation: 17333

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

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.

Upvotes: 0

Views: 4420

Answers (2)

elclanrs
elclanrs

Reputation: 94101

If your element is at body level this should work:

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

Upvotes: 0

Joseph Silber
Joseph Silber

Reputation: 219920

CSS:

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

jQuery:

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

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

Upvotes: 2

Related Questions