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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:46:03+00:00 2026-05-30T10:46:03+00:00

Before someone asks me why the hell I would want to do this let

  • 0

Before someone asks me why the hell I would want to do this let me come straight out and tell you. That way one of you clever peeps out there can tell me a far better way…

I’m making a viewer for paintings which should stretch to fill the page, well 90% of the height of the screen to be precise. I want to fade the paintings in one over the other and want to center each of them in the middle of the screen.

To fade the paintings in over each other I need to position them ‘absolute’ to stop them from stacking. Here’s where the trouble comes. Ever since I’ve set them to absolute, every method I use to center the containing div hasn’t worked.

Part of the problem is that I’m not setting any width for the paintings as I want them to dynamically size themselves to fill 90% of the user’s screen.

I’ve found a hundreds of methods for centering absolute content and believe I might need to shrink wrap the containing div. However I’ve not had any success as of yet.

HTML-

<div id="viewer_div">
    <img src="" id="first" />
    <img id="second" class="hidden"/>
</div>

Style Sheet

#viewer_div {
        width:1264px;
}


img {
    height:90%;
    display:block;
    margin-left: auto;
    margin-right:auto;
}

The above gives me the desired effect, but doesn’t allow me to position the images absolute. Can anyone suggest a way of centering the images but also allows me to fade one over the other?

  • 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-30T10:46:04+00:00Added an answer on May 30, 2026 at 10:46 am

    Either use JavaScript to calculate the width and move it,

    use a CSS hack to move the element right and left by 50%,

    or don’t absolutely position it.


    This answer is incredibly short, but it is to the point. If you require something to be centralised (meaning you would like the browser to determine where the centre point is, and position it there), then you can’t use absolute positioning – because that takes away control from the browser.


    To fade the paintings in over each other I need to position them
    ‘absolute’ to stop them from stacking.

    This is where your problem lies. You have assumed that you need absolute positioning for the wrong reason.

    If you are experiencing problems placing elements on top of each other, wrap the images in an absolutely positioned container which is 100% width and has text-align: center


    If you do feel that absolute positioning is necessary, the following hack can be used to achieve your desired results:

    div {
        position: absolute;
        /* move the element half way across the screen */
        left: 50%;
        /* allow the width to be calculated dynamically */
        width: auto;
        /* then move the element back again using a transform */
        transform: translateX(-50%);
    }
    

    Obviously the above hack has a terrible code smell, but it works on some browsers. Be aware: this hack is not necessarily obvious to other developers, or other browsers (especially IE or mobile).

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

Sidebar

Related Questions

Before someone said that I did not read I may say that I read
I'm hoping someone has seen this before because I can't for the life of
I was hoping someone could validate my assumptions before I recommend that my client
I'm hoping someone has run into this sort of problem before, and can give
Before you start firing at me, I'm NOT looking to do this, but someone
This is a noob question from someone who hasn't written a parser/lexer ever before.
Ok, I know someone here has tried this ninja-elite level of coding before. Essentially
Before someone shouts out the answer, please read the question through. What is the
Before someone says this is a dupe, I looked at the other answers regarding
I've got a 16GB memory card off someone that won't load properly (asks to

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.