1

I'm doing research on this topic by the last day but i have not found any solution. i'm badly stuck in my project. Please someone help me to out.

My related search is Can I position an element fixed relative to parent?.

But this is not able to fulfill my will.

3
  • 1
    Welcome to stackoverflow ;) Commented Nov 21, 2015 at 7:19
  • 2
    position:fixed is for this Commented Nov 21, 2015 at 7:22
  • 1
    Welcome to StackOverflow. Please post what you have tried and where you are getting problem so that we can help Commented Nov 21, 2015 at 7:23

1 Answer 1

4

I made a JSFiddle for this.

What you want specifically is position:relative; on the parent and position:absolute; on the child element you want to position.

(Then set the position of the child element)

EDIT

New JSFiddle using jQuery UI .position()

HTML

<div class="anchor"> <div class="content"> </div> <button class="fixed-button">Fixed position button</button> </div> 

JavaScript

$(function(){ $(".fixed-button").each(function(arg, el){ $(el).position({ of: $(el).closest(".anchor")[0], my: "left top", at: "left+500 top+10" }); }); }); 

EDIT 2

I just realized that this can be done by CSS only now that we have the "anchor" surrounding the content and the button. See this new and (hopefully) final JSFiddle

CSS

.anchor{ position: relative; } .fixed-button{ position: absolute; top: 10px; right: 50px; } 
Sign up to request clarification or add additional context in comments.

5 Comments

how can i freeze element with abosolute position @Argon
Did you look at the "?" in the JSFiddle?
yes i have seen but i want to freze button inside scrollable container
I have updated my answer with one way to accomplish this with jQuery UI.
+1 I have added some <br> to your example to have result more visible here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.