+ Reply to Thread
Results 1 to 4 of 4

Thread: Centering Div content

  1. #1
    nmgod is offline x10Hosting Member nmgod is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    2

    Centering Div content

    Been a while since I've made a website and I cant remember a browser safe way of centering a div, eg using say align="center" or whatever it is in IE will not work. Shouldn't be to hard to asnwer

  2. #2
    techairlines's Avatar
    techairlines is offline x10 Flyer techairlines has much to be proud oftechairlines has much to be proud of
    Join Date
    Jul 2009
    Location
    New York City
    Posts
    2,853

    Re: Centering Div content

    Use this:

    Code:
    <div style="text-align:center;">CENTERED CONTENT</div>
    This is using CSS to apply center effects. You can also set CSS elements like:

    Code:
    .mycenteredcontent {
    text-align:center;
    }
    Code:
    <div class="mycenteredcontent">CENTERED CONTENT</div>
    Last edited by techairlines; 05-17-2010 at 09:02 PM.
    Best regards,
    Brian Yang - TechAirlines


    How am I doing? Click the star button at the bottom left to rate this post. Thanks.
    Terms of Service | Account Portal | Wiki

  3. #3
    nmgod is offline x10Hosting Member nmgod is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    2

    Re: Centering Div content

    Is that not only text centering, by centering i meant, say having "body" div to have like a box in the center, not the content withing that div but the div itself

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,152

    Re: Centering Div content

    Almost every browser will understand the auto setting for a margin:

    Code:
    #div_id {
         width: 760px;
         margin: 0 auto;
         }
    If you absolutely feel you need to fully support IE 6, then this hack will work:

    Code:
    #div_id {
         width: 760px;
         left: 50%;
         margin-left: -380px;
         }
    Frankly, I'd let IE6 slide these days. Neither CSS hacks nor the available "IE-updating" javascript libraries are worth the bother for niggling little details like horizontal positioning of containers. Your site will still work without the hacks, even if it isn't exactly the same in IE6 as it is in other browsers. And it just may give people a reason to get fundamentally fed up with a browser that has been obsolete for many years.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

+ Reply to Thread

Similar Threads

  1. html/css centering problem
    By Firenova in forum Programming Help
    Replies: 4
    Last Post: 01-07-2009, 07:19 PM
  2. Centering website using css
    By wiileg3nd in forum Programming Help
    Replies: 8
    Last Post: 08-23-2008, 01:58 PM
  3. centering websites
    By mikel2k3 in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 02-21-2007, 11:46 AM
  4. centering a banner
    By RollerC in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 07-04-2005, 05:54 PM
  5. Centering ads
    By Ericsson in forum Free Hosting
    Replies: 2
    Last Post: 03-20-2005, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers