SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto size <DIV> in relation to its containing contents

    Hi all,

    If I have a <DIV> with elements contained in it, how can I get the <DIV> to just be the height, and if possible, the width to be as high and wide as the <DIV>s containing elements?

    Thanks

    Tryst

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,556
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    Hmmm,

    Can you run that by me again lol

    I'm not quite sure what you are asking but a div with no height specified (height:auto) will be as high as the content requires. The same goes for width except that if you have a border it will be 100% wide.

    Perhaps thats what you mean

    The only way I can think of is when you make the parent absolute and then it collapses to fit the content (but of course it causes other display issues).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    #outer{
    border:1px solid red;
    position:absolute;
    }
    </style>
    </head>
    <body>
    <div id="outer"><p>Hello this is some text</p></div>
    </body>
    </html>
    Paul

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I have at the moment is a <DIV> which just contains a few input textboxes. But when I set the background colour of the <DIV> it takes up around 80% of the screen for some reason.

    NO no, sorry, my mistake. I was compeletly screwing things up in my CSS. You are right, its just I had a hidden statement in my CSS which making the <DIV> pretty huge

    Thanks

    Tryst


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
  •