tags:

views:

365

answers:

3

Hi

i want to show a div which is always visible with the user as the user scrolls the page

are there any javascript solutions??

i have used the css position:fixed;

Now i want to show the div at the right hand corner of the parent div

i used the css

 .test {
     position: fixed;
     text-align: right;
  }

but that doesn't work with position:fixed;

For that i used the css but i think nothing works on the top of postilion fixed

My example page here

the div i want to align is "test" under the parent class "parent"

Is there any solution or any other javascript solution to this...

thanks

Pradyut
India

+3  A: 

With position fixed, you need to provide values to set where the div will be placed, since it's a fixed position.

Something like....

.test
{
   position:fixed;
   left:100px;
   top:150px;
}

Fixed - Generates an absolutely positioned element, positioned relative to the browser window. The element's position is specified with the "left", "top", "right", and "bottom" properties

More on position here.

gmcalab
"Generates an absolutely positioned element" - perhaps a rephrasing is in order, since "absolute positioning" is another distinct concept?
LeguRi
@Richard JP Le Guen - Perhaps discuss that with the author at w3c then.
gmcalab
i found a solution with using only left:400px; no need of using the top and bottom... but i should say... not a complete solution for a complex problem. either w3c or the browser guys should set a high standard for ui with css
Pradyut Bhattacharya
@Pradyut Bhattacharya - I don't see what the problem is, you have a fixed position set for the `<div>`. You need to supply the position it should live at, if you don't its going to sit at the default position. If you don't want that functionality, then I suggest you choose another type of positioning so `text-align: right` works, but you chose fixed so you have to define some values.
gmcalab
@gmcalab how about that i want the postion:fixed as i want the div to be visible as the user scrolls and the div to be aligned right and i m changing the text of the parent div with javascript and and the parent div's width changes to less than 200px.. ha ha a complicated question... but you don't have a answer now...
Pradyut Bhattacharya
@gmcalab - Dude, you linked to w3schools not w3c ;) There's kind of a big difference.
LeguRi
+2  A: 

You can use two imbricated div. But you need a fixed width for your content, that's the only limitation.

<div style='float:right; width: 180px;'>
 <div style='position: fixed'>
   <!-- Your content -->
 </div>
</div>
246tNt
A: 

Trying to do the same thing, if you want it aligned right, use right: 0px;

.test { position:fixed; right: 20px; }

/* will align right, with 20px padding to the right */

Chris