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 6981595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:10:39+00:00 2026-05-27T18:10:39+00:00

I created a div that is always on top .visibleDiv, #topLeft { position: fixed;

  • 0

I created a div that is always on top

.visibleDiv, #topLeft
{
    position: fixed;
    width: 150px;
    border: solid 1px #e1e1e1;
    vertical-align: middle;
    background: #ffdab9;
    text-align: center;
}

#topLeft
{
    top: 10px;
    left: 10px;
}

And I display it like so

<div id="topLeft">
    Top Left
</div>

But I also have a div called container. And i would like topLeft to stay at the top left within that container instead of the top left of the screen. I am quite new to css and have been scratching my head for a while on how to achieve such an effect.

So to explain more clearly I would like to try to achieve this effect

______________
|Other things|
|____________|
________________________________
| TOP LEFT MESSAGE|            |
|_________________|            |
|                              |
|                              |
|         CONTAINER DIV        |
|                              |
|                              |

And when you scroll down I want the topleft to be at top left of screen within container tab like so

|__________________            |
| TOP LEFT MESSAGE|            |
|_________________|            |
|                              |
|                              |
|         CONTAINER DIV        |
|                              |
|                              |
|______________________________|

If anyone could point me in right direction or show me how to achieve that with an explanation I would be really grateful. Thank you to anyone in advance for helping or just reading this post.

  • 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-27T18:10:40+00:00Added an answer on May 27, 2026 at 6:10 pm

    Simply add position:relative to your container element.

    See this fiddle

    Update

    jQuery is very useful here. You can use it to easily calculate when the “container” hits this top of the view port then re-assign a class to your “topLeft” element to fix it.

    HTML

    <div class="head">
    Some Stuff
    </div>
    <div class="container">
        <div id="topLeft">Top Left Stuff</div>
        Container Stuff
    </div>
    

    CSS

    .container
    {
    
        background-color:#FAA;
        height:1000px;
    }
    
    #topLeft
    {
        width: 150px;
        border: solid 1px #e1e1e1;
        vertical-align: middle;
        background: #ffdab9;
        text-align: center;
    }
    
    .fixit
    {
        position:fixed;
    
        top: 0px;
    }
    

    Javascript

    <!-- Include jQuery Library -->
    <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
    <!-- Wire Up Our Magic -->
    <script type='text/javascript'>
    $(window).load(function(){
    $(window).scroll(function () { 
        if(($(".container").position().top - $(window).scrollTop()) <= 0)
           {
               $("#topLeft").addClass("fixit");
           }
           else
           {
               $("#topLeft").removeClass("fixit");
           }
    
        });
    });
    
    </script>
    

    See it in action here

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

Sidebar

Related Questions

I always thought that replacing the <center> tag with <div style=text-align:center;> will get me
When I create a div it always add space to top and left side.
<td width=120 valign=top height=100%> <iframe src=menu.php width=100% height=100% frameborder=0> </iframe> </td> This code always
I have created a tooltip that appends a DIV with text to the page.
Is it possible to create a footer div that sits at the bottom of
I'm gonna create two div tags with CSS that appear in the page like
I write a simple piece of code that creates a div and assign it
I have a script that create a new div element. Then, I want to
i am trying to bind an event to a dynamically created div. function GameField(playerNumber)
I created a div(search result term bar) which should display only when user enters

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.