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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:16:05+00:00 2026-05-25T16:16:05+00:00

When the browser opens up my page, the browser should already be in the

  • 0

When the browser opens up my page, the browser should already be in the center of the whole page.

Meaning: I have a horizontal one-page, which instead of starting from the left and going to the right (e.g. this), will start in the middle, and be able to scroll to the content on both the right AND the left.

Here is a visual:

enter image description here

If possible, I’d like to avoid dom-ready scrolling via JavaScript or jQuery (I’m using it for navigational aid and stuff anyways), and use only pure html5/css or at least focusing the screen pre-dom-ready through JavaScript/jQuery.

Two ideas on my part:

a) moving the container to the left e.g. using margin-left:-x, but that usually cuts it off.

b) moving the screen to the right from the start.

Alas, I have been too unsavvy to achieve this on my own.

p.s. here my jsfiddle for consistency: http://jsfiddle.net/alexdot/2Dse3/

  • 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-25T16:16:06+00:00Added an answer on May 25, 2026 at 4:16 pm

    Solution
    If you want to hide data, add visibility:hidden; to the elements with a content which should be kept hidden at the start. Execute my page scrolling code, and finally change visibility:hidden; to visibility:visible.

    What’s going to happen?

    1. CSS hides the contents of these elements: visibility:hidden
    2. The Page loads
    3. JavaScript causes the page to scroll to the center: window.scrollTo(..., ...)
    4. JavaScript shows the secret content (outside the view of the browser): visibility=visible
    5. The user scrolls to the left/right, and is able to read the secret

    Fiddle: http://jsfiddle.net/2Dse3/5/


    Scrolling code
    Scrolling the page to the center cannot be achieved with pure CSS/HTML. This can only be done by using JavaScript. For this simple purpose, I’d rather use native JavaScript than including a JQuery plugin (unnecessary server load).

    JavaScript code:

     window.scrollTo(
         (document.body.offsetWidth -document.documentElement.offsetWidth )/2,
         (document.body.offsetHeight-document.documentElement.offsetHeight)/2
     );
    /*
     * window.scrollTo(x,y) is an efficient cross-broser function,
     * which scrolls the document to position X, Y
     * document.body.offsetWidth contains the value of the body's width
     * document.documentElement contains the value of the document's width
     *
     * Logic: If you want to center the page, you have to substract
     * the body's width from the document's width, then divide it
     * by 2.
     */
    

    You have to adjust the CSS (see Fiddle):

    body {width: 500%}
    #viewContainer {width: 100%}
    

    A final note. What do you expect when the user has disabled JavaScript? Are they allowed to see the contents of the page? If yes, add this:

    <noscript>
      <style>
         .page{
           visibility: visible;
         }
      </style>
    </noscript>
    

    Otherwise, add <noscript>JavaScript is required to read this page</noscript>.

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

Sidebar

Related Questions

Say, for instance, you have a popup which opens from your main page. The
There is a page in asp.net which have a link that opens into a
I have this JPEG image , that opens fine in Picasa, Photoshop, web browser,
My InnoSetup script opens a web page (with the user's default browser) at the
I have a UIwebview which loads up a page ,first the links in the
I have a simple webview which loads a page. This page has a few
I've got some strange bug: when I open page first time in some browser
When you open a page in the browser, an instance of the page is
I used Netbeans6.7 to write a servlet, when it runs, it opens a browser
My product opens a web browser and points it at an HTML file containing

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.