Aligning text with CSS

They have: 80 posts

Joined: May 2001

I can't figure out why this isn't working:

.tp { font-family:verdana,arial,sans-serif; color:#999999; font-size:10px; font-weight:normal; text-align: right; }

I'd like the "Back to top" text button to be right justified on each page. Here is a sample page: http://www.allthingschristmas.com/stories.html

Thanks,
Deborah

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

It is right-aligned. Unfortunately, the element is not block-level that you're putting the right-aligned text in, so it's collapsing.

You'll have to use proper markup, and nest all inline elements within block level elements in order to get the effect you want.

Specifically:

...

They have: 80 posts

Joined: May 2001

Thanks - what you gave me worked perfectly, but I went with a center alignment. Now it's just matter of fixing all 150 pages!
Deborah

He has: 1,380 posts

Joined: Feb 2002

you wouldnt have to do that if you used the latest specifications of XHTML, following the "strict" documentation...when you create a table you do all the widths, heights, etc in stylesheets, as well as any text formatting. css is seen as a cosmetic language, working on the formatting of the elements, whereas HTML is seen as the structure language. i only switched over to doing this weeks ago, and its already helped out alot. i reccommend it.

http://www.w3.org/TR/xhtml1/ for XHTML 1.0 (1.1 exists, but isnt standard yet)
http://www.w3.org/TR/REC-CSS1 for CSS1 (CSS2 exists as well, but isn't standard either)

good luck

They have: 80 posts

Joined: May 2001

Thanks Kyle, but I just did 150 pages of the site in XHTML transitional and I only have about a dozen pages left to fix. I'll switch over to strict XHTNL next year LOL
Deborah

He has: 688 posts

Joined: Feb 2001

Quote: Originally posted by dmwhipp

.tp { font-family:verdana,arial,sans-serif; color:#999999; font-size:10px; font-weight:normal; text-align: right; }

I'm absolutely NOT an expert in this stuff but from the tutorials I've read on CSS, you should always put your font-family as the last attribute. I forgot the specifics but I think I read on Mulder's style sheets that some browsers will apparently ignore the font-family unless it is listed last.

And I don't know if it matters but I don't believe you need a ";" after your last attribute.

(Anybody else can confirm or refute this fact)

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

IE3 will have problems if font-family isn't last. Frankly, I don't think we need to worry about it anymore.

While a semi-colon is not needed on the last line, it's good practice to include it. That way when you edit the element's declarations, you won't accidentally forget to finally close that line first (leading to difficult to find errors).

Additionally, to make things nice and sensible to the people-types:

.tp {
    font: 10px verdana, arial, sans-serif normal;
    color: #999;
    text-align: right;
    }
'

Or, alternatively:

.tp {
    font-size: 10px;
    font-family: verdana, arial, sans-serif;
    font-weight: normal;
    color: #999;
    text-align: right;
    }
'

The indents make it much easier to troubleshoot.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.