Results 1 to 3 of 3

Thread: Positioning text

  1. #1
    Join Date
    Mar 2005
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Positioning text

    Very quick question:
    How do i position something so that it is still centered, but set so that it is touching the top of the page?
    When i tried to use:
    HTML Code:
    <p align="center">
    <font face="Boca Raton ICG Solid" color="#3366FF" size="6" style='position:absolute;top:0'>My Heading</font></p>
    the text positioned at the top but not centered, instead being too far to the right, as if it was right justified.

    I know i'm doing something wrong, but i can't seem to found out what.

    Thanks,
    Martyn.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's a real hack looking piece of code. Not that that's a bad thing but, you will be doing alot of it if you do a little of it and it can tend to clutter up your mark up. Anyways, once you use position:absolute and give a coordinate for top or left, you lose any centering. You may be able to regain the center with clever padding or margins but, best to avoid the absolute positioning to begin with. If you want it at the top and centered, place your element just after the <body> tag. Like this:

    HTML Code:
    <body style="margin-top:0">
    <h1 align="center" style="margin-top:0">My Heading</h1>
    or using an on page stylesheet, which is a better habit:

    Code:
    <html>
    <head>
    <title>My Title</title>
    <style type="text/css">
    body {
    margin-top:0;
    }
    h1 {
    margin-top:0;
    text-align:center;
    }
    </style>
    </head>
    <body>
    <h1>My Heading</h1>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for that, it works a treat, although I had to set the margin for -5 instead of 0 to get it as high as I wanted.

    I realise the code was a bit of a mish mash, but it's an improvement on what it was like before - I had some word art as my heading instead: about 50 lines of gibberish code! At least this way i reduces it to 1 line, with the style going in my css file.

    Thanks again!

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
  •