Cellpadding & Cellspacing equivalent in CSS

Discussion in 'CSS' started by ketan9, Dec 22, 2006.

  1. #1
    What is Cellpadding & Cellspacing for table in html equivalent in CSS? I don't want to specify this all the time for my tables and just want to set it in CSS but couldn't find an element that does this, so please help identify.

    Thanks.
     
    ketan9, Dec 22, 2006 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    For cellpadding, simply use padding. For cellspacing, the css is border-spacing, but IE doesn't support that property.

    cheers,

    gary
     
    kk5st, Dec 22, 2006 IP
  3. tgo

    tgo Peon

    Messages:
    124
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cellspacing can be replaced with margin:#px;
    cellpadding can be replaced with padding:#px;
     
    tgo, Dec 22, 2006 IP
  4. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes padding...
     
    weknowtheworld, Dec 22, 2006 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Also, the last I checked, cellpadding and cellspacing were NOT depreciated attributes (even in Strict DOCTYPES) and are perfectly acceptable in your (X)HTML markup.

    Just let the HTML markup define the default presentation of the tabular data (in case the stylesheet doesn't get parsed by the user agent), and then use CSS to change its appearance to suit the presentation that your stylesheet has defined for your particular site's needs :).
     
    Dan Schulz, Dec 24, 2006 IP
  6. ketan9

    ketan9 Active Member

    Messages:
    548
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Based on my experiments, it looks to me that cellpadding and cellspacing for table is not replacable by padding & margin in CSS.
     
    ketan9, Dec 26, 2006 IP
  7. Josh Inno

    Josh Inno Guest

    Messages:
    1,623
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Dan:

    Ah, so you can actually set the border-spacing in CSS to over-ride the cellspacing attribute in the HTML?
     
    Josh Inno, Dec 27, 2006 IP
  8. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Only if you use Microsoft's box model.

    Think of that Christmas present you got this year.

    You had the container (box) that held whatever it is you got this year (the content). Inside that container you probably had some bubble wrap protecting your present (padding). On the outside, you had the wrapping paper (border). Now let's say you had another present, one that was 2 inches away from the other. That space between them would be the margin.

    That's how the W3C box model works.

    So to answer your question (admittedly with another question), why would you want to use border-spacing when you could just apply a margin to your TD elements?
     
    Dan Schulz, Dec 27, 2006 IP
  9. Josh Inno

    Josh Inno Guest

    Messages:
    1,623
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Quite simply, I currently wouldn't. But if I can gain some amount of knowledge to help me keep my options open... well, so much the better.

    Currently, instead of using cellspacing = "0" to fix the default cell spacing problem in IE, I've been using the css table attribute of border-collapse: collapse; so that I don't have to add that cellspacing="0" attribute to any of my pages.
     
    Josh Inno, Dec 27, 2006 IP
  10. tayiper

    tayiper Active Member

    Messages:
    421
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #10
    tayiper, Dec 28, 2006 IP
  11. Josh Inno

    Josh Inno Guest

    Messages:
    1,623
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #11
    tayiper: Thanks for the link! I'll have to take a look as soon as I finish up the tutorial I'm working on.
     
    Josh Inno, Dec 28, 2006 IP
  12. tayiper

    tayiper Active Member

    Messages:
    421
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #12
    tayiper, Dec 29, 2006 IP