csshtml

Div taking all horizontal space


Why? i dint speficy the width, so it should be as big as content inside it.

#swfbox {
 padding: 10px 10px 10px 10px;
 margin: 50px auto 0px;
 background: #310600;
 border: 3px solid #4b0900;
}

i have it centered and load swf files in it, so for it to work i have to set its width to the width of the swf file, which is bad since i every file has different width.


Solution

  • <div> elements are block-displayed elements, which means they default to 100% width unless otherwise specified.

    If you want the element to expand based on its content, you might want to try setting the display property on the <div> to inline (or just use a span since it's essentially an inline-div).

    Edit:

    I guess inline didn't work quite the way I expected, so I learned something today. What you're going to want to do instead is to set display: inline-block, but that comes with it's own set of problems.

    First, according to the Quirks Mode page for the display property, IE6 and IE7 only support inline-block on elements with a natural display: inline which means you need to use <span> elements rather than <div> elements.

    Second, inline-block has its own set of quirks which you should read up on before using it, to prevent being surprised by further "gotchas". This page has a pretty good write-up on inline-block.