#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0

    Cool formatting a javascript table with css


    ok heres a hard one (well for me anyway), ok heres what im trying to do (please let me know if this is not possible), i have a table that i have wrote in javascript, now im trying to format the table using css, as i just want to center all the table data, I am at university doing a javascript module or i wouldnt have bothered writting the jscript for the table, i would have just used html, but this way i will get more marks! ok heres the page script that i have

    <HEAD>
    <STYLE>
    .tb { align: center}
    </STYLE>
    </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    document.writeln("<TABLE BORDER=\"0\" class=tb id=tb1>");
    </SCRIPT>

    IM TARING MY HAIR OUT HERE!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Cambridge, UK
    Posts
    31
    Rep Power
    12
    change align:center to text-align:center;

    or add:

    style="text-align:center;" into the js document.write

    Good Luck
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    3
    Rep Power
    0

    Cool THX MATE WORKS A TREAT!


    I USED THE TEXT ALIGN AND, ITS GOOD! (bruce almighty)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Cambridge, UK
    Posts
    31
    Rep Power
    12
    A few other things you might want to do - although they are not essential they will make your code look neater and more robust on different browsers:

    1) Change all your html tags to lowercase
    2) Always enclose all html tag attributes with " "

    You can also move BORDER=\"0\" into the css definition:

    .tb
    {
    text-align:center;
    border: 0px;
    }

    Then if you have more style changes they can be added there as well e.g font-size:10px; color: red etc !!

    You can also use single quotes in your document.writeln('<html>'); Then adding " " is not so much hassle and code more readable



    Hope you get a good mark

IMN logo majestic logo threadwatch logo seochat tools logo