SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question CSS and nested elements

    I have a quick question regarding CSS. I'm a developer and run into a CSS issue sometimes that I can't seem to figure out. Here's an example. I want to style all the text on my pages to have a font size of 10 pixels. So of course I'm doing the following:


    Code:
    body { font-size: 10px; }
    Sometimes it will take care of the content throughout all pages and sometimes it wont. I don't understand why this happens. It especially occurs with a lot of nested tables, divs, etc. Any suggestions would be helpful. Thanks! I'm just tired of styling every single element (text size and fonts mostly) over and over again. That is the beauty of CSS - eliminating repetitive scripting and I don't think I'm taking advantage of it. Thanks!

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you can do, that will only work on some elements of course, is use:

    font-size: inherit;

    And this will rely on the parent's styling. Now some elements like <input> <textarea> use the browser's default font styling and you will have to style these directly.

    Another thing I would try is this:

    *, html, body { font-size: 10px }

    This refers to almost everything on the page.

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work, but IE3/4/5.x for Windows (and possibly IE6/7 in quirks mode?) have a bug that causes font size not to be inherited by tables.
    Code:
    body,table {font-size:10px}
    This should take care of most inheritance problems.

    Note, however, that using pixels for font size is a very bad idea since it prevents IE users from resizing the text. Unless you have a font size that everyone is guaranteed to be able to read (and that's a lot larger than 10px), you won't be very popular among many of your visitors.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you guys are great..thanks!


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
  •