In my web page, I have a div that stays static on the left even as the user scrolls.
This is the CSS for the div:
.floatingDiv
{
position:fixed;
top:300px;
left:70px;
padding:16px;
}
As you can see, I am positioning the div relative to the top left corner of the page.
However, my main content is only about 1000px wide, and I want to position this div from the left edge of my content rather than the left edge of the screen. At my resolution of 1440×900, the div currently is placed exactly halfway between the left edge of the screen and the left edge of the content, but if someone is using a wide-screen monitor, this floating div is rather far away from the content.
Got it to work by using javascript:
Here’s a better way to do it so it works even if the window isn’t maximized:
I call this function
onloadandonresize