Looking for CSS container element that terminates like a table cell

Discussion in 'CSS' started by creativeguy, Oct 31, 2006.

  1. #1
    I'm looking for a CSS element that behaves like a table, where the size of the container will always be just big enough to surround the data inside, and will grow or shrink based on the content inside without having to specify any widths or heights.

    A div (with a border) with no width specified will go on forever horizontally. A table (with a border) with no width will stop as soon as the data inside ends.

    Is there a way to simulate this table behavior using CSS?

    Thanks
     
    creativeguy, Oct 31, 2006 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    An element of {position: absolute;} or {float: left | right;} will shrink wrap its content if not explicitly dimensioned. There are other approaches, but IE (any version, including 7) has so little support for css that there's no purpose talking about them.

    There is so seldom reason for that behavior, that it might be a good idea to tell us what you want to accomplish—not how you want to do it.

    cheers,

    gary
     
    kk5st, Oct 31, 2006 IP
  3. Corey Bryant

    Corey Bryant Texan at Heart

    Messages:
    1,126
    Likes Received:
    51
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Corey Bryant, Nov 1, 2006 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    The span would still reside within a block element which would determine its ultimate width. Maybe an issue, maybe not.

    cheers,

    gary
     
    kk5st, Nov 1, 2006 IP