• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Center the entire website

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,

I want to center the entire site and look good for all the screen resolution. It looks good for screen resolution 1024*768. When the resolution increases to 1366x768 the site is left aligned and I want it to make it centered.

My page has the following structure

Want I want to add is a div tag in my body without changing the look of the site excepting the contents are centered.And the div tag to have the following properties.


text-align:left;
width:748px;

where exactly should i be adding the div tag may with the name wrapper


Thanks
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the left and right margins to auto.
 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setting the right and left margin to auto didnt have any change

Here is the attributes that I have in my .css file


Am I missing something?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't set the margins on the body, but on a div that's within the body. There are CSS examples of this all over the web.
 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi saw most of the tutorial on the web I tried every other possible combination

http://buildinternet.com/2008/11/how-to-center-a-website-with-css/
http://bluerobot.com/web/css/center1.html

But I am still not able to center my website. Can someone please help. Below is my code and the .css





I use internet explorer 8 and firefox 3.6. My screen resolution 1920*1080. the site is still left centered.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just starting Java, but have been playing with HTML and CSS for a few years.

To centre a design do the following:



If you paste that into a text editor and save as "index.html" you will see that the page is centred (centered for those on the other side of the pond).
I have added a black background to the body and a white background to the container div.

I have used HTML5, but you can use any DOCTYPE you like.

The other method you can use is positioning and negative margins.

Create a positioning context. { position : relative; }
Set left 50% to put the left hand edge of your container div in the center of the page. { left : 50%; }
Pull the container back half the container width by using negative margins. { margin-left : -480px; }

// 960px / 2 = 480px





Obviously rather than putting the CSS in the head, you'd ideally want to place it in an external css file and link to it.

Hope this helps.
 
Dave Bilson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Romeo Ranjan wrote:

where exactly should i be adding the div tag may with the name wrapper


Thanks



Put the wrapper div inside your body tags, but around your web site content.

 
How do they get the deer to cross at the signs? Or to read this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic