Solved

CSS Style popup display

Posted on 2008-10-06
5
921 Views
Last Modified: 2012-05-05
Hi,

I am using the style below to display a popup when a user clicks on a link. This works perfect if the link is in the top of the screen. When the user scrolls down in the page and they click some other link with the same behavior the popup displays, but ... as you guessed it... still at the top of the page. In order for them to view the popup they then need to scroll to the top of the page.

How can I make this popup display relative to where the user clicks?

Thanks
<style type="text/css">
        .black_overlay
        {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.8;
            opacity: .80;
            filter: alpha(opacity=80);
        }
        .white_content
        {
            display: none;
            position: absolute;
            top: 5%;
            left: 5%;
            width: 70%;
            height: 70%;
            padding: 16px;
            border: 16px solid #C0C0C0;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }
    </style>

Open in new window

0
Comment
Question by:ALawrence007
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:zivperry
ID: 22650525
You have to use Javascript to re-allocate the div. CSS is not enough in this case.

0
 
LVL 44

Accepted Solution

by:
scrathcyboy earned 500 total points
ID: 22656245
It is because you are using position: absolute -- which is always referencing to the top left of the screen.

Replace that with position:relative in all cases, and then position the popup some pixels to the right and below the link -- you play with the numbers -- until the position of the popup is correct relative to where the link is on the page.  Try it -- it will work.
0
 

Author Closing Comment

by:ALawrence007
ID: 31503428
That worked and solved my issue. Thanks
0
 
LVL 1

Expert Comment

by:zivperry
ID: 22659798
scrathcyboy, this it a mistake.

absolute not reference to the top left of the screen, it's reference to the top left of the containing box element.

from W3:

9.6 Absolute positioning

In the absolute positioning model, a box is explicitly offset withrespect to its containing block.  It is removed from the normal flowentirely (it has no impact on later siblings).  An absolutelypositioned box establishes a new containing block for normal flowchildren and absolutely (but not fixed) positioned descendants.  However, the contents of anabsolutely positioned element do not flow around any other boxes. Theymay obscure the contents of another box (or be obscured themselves), depending on thestack levels of the overlapping boxes.
References in this specification to an absolutely positionedelement (or its box) imply that the element's 'position' property has the value'absolute' or 'fixed'.
from: http://www.w3.org/TR/CSS21/visuren.html#absolute-positioning



0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22661273
zivperry, the way he's using it, it does, containing block is the body, hence top left.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
css help with menu spacing 10 47
form button worked now it doesnt anymore 9 54
Error in script 11 56
manage footer size 4 54
Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question