[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CSS Style popup display

Posted on 2008-10-06
5
Medium Priority
?
933 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses

656 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