Mark,

On Oct 18, 2006, at 4:07 PM, Mark Wheeler wrote:

> Ok, I've been following the "why margin-top/bottom don't work for
> span class?" thread, and have an offshoot question that has been
> bugging me for some time. Say I have a div that has a little bit of
> content such as:
>
> .div1 {
>       border: 1px solid red;
>       padding: 5px;
>       margin: 5px 10px;
> }
>
> <div class="div1">This is the content</div>
>
> And I want to be able to set the margins and padding to what ever I
> like, such as the above, how do I get the border to collapse around
> the content? If set .div1 to:
>
> display: block;
>
> I get my margins and padding, but the div width (shown by the border
> around the div) is the complete width of the page, and if I set .div1
> to:
>
> display: inline;
>
> I don't get my margins, but the border now does collapse to the
> content width.

The text inside your div is in an anonymous box which you can't  
style.  Adding a span to your code gives you something to hook into  
and you can put the border on the span.

<div class="div1"><span>This is the content</span></div>

Your other option is to use float which retains the block properties  
but 'shrinks to fit'  Incidentally, display: table; also shrinks to  
fit, but is not supported in ie/win.

hth

-- 
Roger Roelofs

______________________________________________________________________
css-discuss [EMAIL PROTECTED]
http://www.css-discuss.org/mailman/listinfo/css-d
IE7b2 testing hub -- http://css-discuss.incutio.com/?page=IE7
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to