SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Can you center an element?

    I am trying to center a <div> on the page where the id has a 780px width. The effect I am after is currently achieved by using a table with the width set to 100% and 3 columns. The center column is 780px. But, to appease the search engine gods I am trying to eliminate the table and accomplish the same effect with css.

    I've tried everything I can think of, but to no avail. Any suggestions? Thanks

    Oh, the page can be seen a www.sportsvend.com.

  2. #2
    SitePoint Addict Messiah's Avatar
    Join Date
    Jun 2001
    Location
    Bloomington, In.
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dlindelof - Yes, centering a <div> is not so difficult. However, I am not exactly sure what your entire layout requires. I will go on the assumption that you are using a single column site and that that one single column is your <div> that you would like centered on the page.

    div#yourid {
    margin: auto;
    width: 780px;
    }

    By setting your margins to auto, is equivalent to centering. However, this method will fail in certain build of IE. So, you must also add the:

    text-align: center;

    To your div definition. The full code would look like:

    div#yourid {
    margin: auto;
    text-align: center;
    width: 780px;
    }

    Hope that answers your question. And remember, I could only make a suggestion based on what you presented
    Messiah | Ink-Press: web publishing simplified!


Bookmarks

Posting Permissions

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