SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best way to have div width grow with content?

    Divs by default take up the entire span of the browser window. I just want it to take up the width of the contained content. What's the best way to do this. I've seen using display:table, but it doesn't work in IE7.

    What is the proper method for this?

    Thanks, Paul

  2. #2
    Ripe Tomatos silver trophybronze trophy Rayzur's Avatar
    Join Date
    Jun 2007
    Location
    Texas
    Posts
    4,174
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I've seen using display:table, but it doesn't work in IE7.
    What is the proper method for this?
    Hi,
    Your on the right track, display:table is the best way to go for that. IE6/7 are best controlled with a small bit of js.

    I gave some info about it in this recent thread.

    When using display:table it will treat width as if it were min-width, basic table behavior. By doing that any other block level children with width:auto; (such as a <p> tag) will not force the parent to fill the viewports available space. If there is a block child with a defined width greater than the parent's width it will expand to accommodate it. (kinda like IE6 does)

    Here are some examples I put together a while back.

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reference! Bookmarked!

    Paul


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
  •