views:

286

answers:

4

Hi there,

I've seen so many times that some websites use a kind of button or a kind of bar which always float to a specific position like left edge of screen or at the bottom of the screen and whenever we scroll down a page it remains constant in terms of position..

How to apply this either by CSS or javascript or jquery.

Thanks in advance, Guru

A: 

The simplest way to achieve that effect is position: fixed

<div style="position: fixed; left: 64px; top: 64px">Hey, I'm fixed!</div>

From quirksmode.org:

An element with position: fixed is taken out of the normal flow of the page and positioned at the desired coordinates relative to the browser window. It remains at that position regardless of scrolling.

only downside: Doesn't work with IE6.

Pekka
I'm out of votes for the day or I'd give this +1: this is the only thing really like an answer. C'mon guys, let's not rush out just anything.
D_N
hi pekka,although u're guess was rightworking fine with chrome but not with internet explorer 8
Guru
@Guru I'm 100% sure `position: fixed` works with IE 8. Check out the example on quirksmode.org. Can you post an example that doesn't work?
Pekka
<div style="position: fixed; z-index:1000; left: 64px; top: 64px">Hey, I'm fixed!</div>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>a<br/>and so on...........
Guru
Above is the example code which I'm using....Plz do somethingand thanks for ur help:)
Guru
Hey now its working fine...Thanks dear for ur support and i hope I'll find the best always from ur side.Thanks again.Guru:)
Guru
@Guru Mark this as the correct answer then.
dalbaeb
+1  A: 
.someclass {
  position: fixed;
  top: 33px;
  right: 55px;
}
giorgian
A: 

JQuery:

You may find this useful for that.

CSS:

You just set position to fixed and give it top, left, bottom and right depending on where you want to make it appear, example:

<style>
#some_id
{
  position:fixed;
  top:100px;
  left:100px;
}
</style>

Now you assign that style id to the element you want to make fixed:

<div id="some_id">So, I'm FIXED :)</div>

.

Resources:

More info about CSS fixed property.

Sarfraz
A: 

Also you can add the z-index property for displaying the content over other contents , it helps to display the div as a separate object displayed irrespective of the page content..

ex:

<div style="position: fixed; z-index:1000; left: 64px; top: 64px">Hey, I'm fixed!</div>

value 1000 is given to override any z-index properties of any other elements

kvijayhari