Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:16:42+00:00 2026-05-26T11:16:42+00:00

In my web page, I have a div that stays static on the left

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:16:43+00:00Added an answer on May 26, 2026 at 11:16 am

    Got it to work by using javascript:

    <script type="text/javascript">
        function setFloatingDiv()
        {
            document.getElementById('floatdiv').style.left = (screen.width - 1200)/2 + 'px';
        }
        </script>
    <body onload="setFloatingDiv()">
    

    Here’s a better way to do it so it works even if the window isn’t maximized:

    <script type="text/javascript">
     function setSidebar()
     {
        if (document.getElementById('main_container').offsetLeft > 150)
            {
                document.getElementById('floatdiv').style.visibility = 'visible';
                document.getElementById('floatdiv').style.left = (document.getElementById('main_container').offsetLeft - 150) + 'px';
            }       
            else //not enough space for it. Hide it
                document.getElementById('floatdiv').style.visibility = 'hidden';
     }
    </script>
    

    I call this function onload and onresize

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a web application, I have a page that contains a DIV that has
I have a web page that displays a long line graph inside a div
I have a web page with DIV s with a mouseover handler that is
I have designed a web page where on the left there is a div
I have a web page that has a DIV and an IFRAME. When a
I have a web page with large div(for example white) and another div that
I am creating a web page, where I have an image that I want
I have a web page that displays comments, and users can click a 'Flag'
I have a table on my web page that have checkboxes on them. I
I have an ASP.NET MVC page that has left Menu Navigation that is built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.