Results 1 to 4 of 4

Thread: Easy way to center a website, Not the usual css.

  1. #1
    Join Date
    Sep 2011

    Lightbulb Easy way to center a website, Not the usual css.

    I have written a short script that checks if a user has a screen rez lower than 1025 (so that the ipad is included) if it is bigger than 1025 then it centres a div according to the screen size.

    <script type="text/javascript">
    if ((screen.width<=1025)) {
    alert("Mobile device!");
    document.getElementById('page').style.left = (((screen.width-1000)/2)+'px');

    change 1000 to your screen size
    and add a div with the ID:'page'

  2. #2
    Join Date
    Sep 2011

    Easy way to center website

    using javascript some but even many browser fail to run
    the best way like is
         <table width=1000px align=center>
              .................your pages here............

  3. #3
    Join Date
    Sep 2011


    I tried that but in the end I found it easier to use js

  4. #4
    Join Date
    May 2010
    Effingham, IL

    CSS Media Queries

    i found this best can be achieved by using CSS Media Queries. You can set certain styles to display based on a width. Such as

    @media screen and (min-width: 1024) {
    #page {
      margin-right: auto;
      margin-left: auto;
      width: 1024px;
    This can be used to set all kinds of styles based on screen size. Using javascript today is not as big of deal as it was a few years ago, the only thing is everything is easier to control in CSS for the fact it is all together and you will be assured it will be displayed unless they have turn CSS off. In that case the webpage would only be text and images.
    Last edited by rebelweb2007; 09-18-2011 at 03:26 PM.
    Ryan Condron
    Freelance Web Developer

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center