Note that there are some explanatory texts on larger screens.

plurals
  1. POPercent Position CSS/ Javascript
    primarykey
    data
    text
    <p>If Have a div say </p> <pre><code>&lt;div style="position:absolute;top:0%;left:94%;width:40px;height:40px;"/&gt; </code></pre> <p>when viewed on different screen resolution the 94% starts to slide to the right, is that normal behavior.</p> <p>The div is relative to the document, so when the window resize's , I want it to move along with the window. </p> <p>I hope I am making sense. As I have it right now, it stays close to where I placed it, but as the screen gets larger or the doc is viewed on a higher resolution, it starts to shift. </p> <p><strong>Question</strong>: How can I position a div absolutely with percents and keep it in the correct position when the screen size/ resolution changes. </p> <p><strong>Edit:</strong> Here is what I am trying to do. I am writing an application in which a user can pick some items from a tool box, drag and drop onto a window sort of like Visual Studio, except the result is not a form its an HTML page. I got all this working and it works just fine. My problem started when I started testing on different screens and resolutions the end result is always different from the screen the user used to create the html page. Every thing in the page is absolutely positioned except the main content area which is relative, it contains all the absolutely positioned Items. </p> <p>What I had tried was the percent left and top values for the items on the screen, and that was what lead to my original question, at the suggestion of calculating my own values I tried this </p> <pre><code>var currH = $(window).height(); var currW = $(window).width(); var rW = currW / OrgWidth; //Orignal Width of the window when the item was placed var rH = currH / OrgHeight; //Orginal height of the window when the item was placed var x =$("#Button_Tools").offset().left * rW; var y =$("#Button_Tools").offset().top * rH; $("#Button_Tools").css("left", x.toString() + "px"); $("#Button_Tools").css("top", y.toString() + "px"); </code></pre> <p>I calculate this when the window first loads to and it moves the button to the exact same location the percent value moved it to. </p> <p>What am I doing wrong? Any Takers. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload