Solved

CSS Style popup display

Posted on 2008-10-06
5
926 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

724 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