Make block-level element shrink?

L

Leif K-Brooks

Sorry for sending this again, but I'm not positive it got sent right the
first time.

I need to make a block-level element shrink to its contents the same way
an inline element does, but keeping the linebreaks. Is there a way?
 
E

Eric B. Bednarz

Leif K-Brooks said:
I need to make a block-level element shrink to its contents the same
way an inline element does, but keeping the linebreaks. Is there a way?

It's hard to guess what you really want to achieve; I suppose visual
presentation, in terms of border/padding/background properties?

If so, the naughty way is something like

div
{
float: left;
clear: both;
margin: 1em;
border: thin solid ThreeDShadow;
padding: 0.5em;
color: MenuText;
background: Menu;
}

As far as I know most browsers will do what you want; it violates the
specs, however, because non-replaced floated elements require an
explicit width.

Other than that, ad-hoc tagsoup comes to mind:

div
{
padding: 1em 0;
}
div span
{
border: thin solid ThreeDShadow;
padding: 0.5em;
color: MenuText;
background: Menu;
}

<div><span>foobar</></>
 
L

Lauri Raittila

In said:
Sorry for sending this again, but I'm not positive it got sent right the
first time.

It was.
I need to make a block-level element shrink to its contents the same way
an inline element does, but keeping the linebreaks. Is there a way?

This don't work on most browsers:

div {display:inline-table}
div:after, div:before {content:"\A"}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,095
Messages
2,570,616
Members
47,232
Latest member
helpplease!

Latest Threads

Top