May 16, 2008

Css Centering

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Css Centering

KansukeKojima
Description
Learn to center the content, or other objects of your pages with CSS. This is a useful tool for creating succesful, and well designed web-pages.

Try it out

Create a new .css file called whatever.css. Alright, now input the following lines into your new css document.



CODE
#wrapper {
margin: 0 auto;
width: 800px;
}



Alright. Now that was fairly simple. The important part is the 'margin' property. The property is used to define where something is located from the sides of the screen, or from the insides of a container. By using the value 'auto' our page will automatically center itself across the screen. (Note: in this case, the id #wrapper, must contain all the content you wish to center on your page.)

Congratualations, you have just learned to center your pages with CSS. This is a very useful piece of knowledge to have, as it drastically improves the look of fixed width layouts.

 

 

 


Reply

dave2win
You can also do it in a different way. [This is just another process & the above process is also very good].

Suppose you want to center a 900px picture. You link that html file to an external CSS File & copy the following code:--

CODE
.center{
width:900px;
margin-left:-450px;
}


Here also the picture is centered with respect to its Parent. THe negative value for the margin tag allows the picture to move 450px in the left as a result it gets centered.

Now just add the class property to the img tag or whatever you want to center and put its value as center. Now you are done. Open the file in a Web Browser and see your creation.

Good Luck with your Project.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : css, centering

  1. Centering A Div Containing Image.
    I have a logo I need centered in a aujustable width page (9)
  2. Centering The Text In A Simple C++ Program?
    (8)
    I'm currently learning C++ in college. For now it's very basic stuff (cout, cin, if, switch,
    voids, etc). But I'm also abit of a "must look neat" freak for certain things. One of which is
    that I don't like the text on the program being aligned to the right. For example, I currently
    have something like this: QUOTE Welcome! Please enter your first name. __ And what's
    your second name? __ But I want it to be like this: QUOTE Welcome! Please enter your
    first name. __ And what's your second name? __ My question is simply:....
  3. Centering Page Of Html At Various Display Widths
    Viewing Screen Shots No Matter Resolution (14)
    I am running into a HUGE problem creating a website. When viewing the site on 800x600 it views in
    the center of the page. When viewing the site on 1024x768 it views on the left side of the page. How
    do I make the page always appear in the middle? I have seen many sites set up that will adjust
    accordingly, but I cannot figure it out. If you want to view my source you can do so by going to the
    website: www.faithcity.org/test.html. Moving to the html Topic ....
  4. Centering Background Image In Css
    (8)
    Well, the title says what I need. Basically, I want a background image that can be used in the body
    or inside a div (or table), which is centered.....
  5. Centering On Bordered Pages ....
    (3)
    Having downloaded a lovely bordered page background, I now can't center anything on the page
    properly, obviously because of the border .... please help .... I'm not using CSS, just
    plain old HTML. Cheerie .... ~M~ ....
  6. Up Centering Tables And Image Mouse Over Effect
    (3)
    Hi all, I got a few html questions... 1. How can I make the content of a table start from the top?
    (Normally it centers vertical...) 2. How can I make an image change into a different 1 if you go
    over it with the mouse? (This is a frontpage effect but suckely I dont have any working version of
    frontpage)....

    1. Looking for css, centering

Searching Video's for css, centering
advertisement



Css Centering



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE