HighDots Forums  

How to make a multi-line div shrink to its content

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss How to make a multi-line div shrink to its content in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
crazyhorse
 
Posts: n/a

Default How to make a multi-line div shrink to its content - 10-27-2007 , 06:16 PM






Hi all,

I've got a list with 3 bullet points. Each line is only about 20
characters long. The list is left-aligned.

I want to put the list between two paragraphs, put a border around the
list (but only want the border to be as wide as the text in the list,
not the whole page width), and then center the list+border relative to
the margins of the paragraphs.

So the list itself is centered, while the list items are left-aligned.

I can't do absolute dimensions because the page has to be flexible for
localized strings.

As far as I can tell, this seems impossible to do in CSS. Am I missing
something?? Please say yes..

Thanks
michael


Reply With Quote
  #2  
Old   
Ben C
 
Posts: n/a

Default Re: How to make a multi-line div shrink to its content - 10-27-2007 , 06:32 PM






On 2007-10-27, crazyhorse <mjbaldwin (AT) yahoo (DOT) com> wrote:
Quote:
Hi all,

I've got a list with 3 bullet points. Each line is only about 20
characters long. The list is left-aligned.

I want to put the list between two paragraphs, put a border around the
list (but only want the border to be as wide as the text in the list,
not the whole page width), and then center the list+border relative to
the margins of the paragraphs.
Do you mean horizontally centered?

Quote:
So the list itself is centered, while the list items are left-aligned.

I can't do absolute dimensions because the page has to be flexible for
localized strings.

As far as I can tell, this seems impossible to do in CSS. Am I missing
something?? Please say yes..
Yes, but so are most browsers. To do that you need display: inline-block
(ideal, not supported in Firefox) or display: table (not supported in
IE).

ul
{
display: table;
margin: 0 auto;
border: 1px solid black;
}

would do it (works in most things except IE), or

ul
{
display: inline-block;
border: 1px solid black;
}

and then set text-align: center on the container (works in Opera and
Safari probably but not Firefox and almost certainly not in IE).


Reply With Quote
  #3  
Old   
crazyhorse
 
Posts: n/a

Default Re: How to make a multi-line div shrink to its content - 10-27-2007 , 07:50 PM



On Oct 27, 8:32 pm, Ben C <spams... (AT) spam (DOT) eggs> wrote:
Quote:
On 2007-10-27, crazyhorse <mjbald... (AT) yahoo (DOT) com> wrote:

Hi all,

I've got a list with 3 bullet points. Each line is only about 20
characters long. The list is left-aligned.

I want to put the list between two paragraphs, put a border around the
list (but only want the border to be as wide as the text in the list,
not the whole page width), and then center the list+border relative to
the margins of the paragraphs.

Do you mean horizontally centered?

So the list itself is centered, while the list items are left-aligned.

I can't do absolute dimensions because the page has to be flexible for
localized strings.

As far as I can tell, this seems impossible to do in CSS. Am I missing
something?? Please say yes..

Yes, but so are most browsers. To do that you need display: inline-block
(ideal, not supported in Firefox) or display: table (not supported in
IE).

ul
{
display: table;
margin: 0 auto;
border: 1px solid black;
}

would do it (works in most things except IE), or

ul
{
display: inline-block;
border: 1px solid black;
}

and then set text-align: center on the container (works in Opera and
Safari probably but not Firefox and almost certainly not in IE).

Yes, I meant horizontally center.

Thank you for the help. It seems to me then that the best option is to
simply put the content in a one-celled table that doesn't specify any
dimensions and then center the table, and forget about CSS altogether
in this case -- that would work on all browsers universally, no? And I
wouldn't have to worry about "hacking" the CSS to apply differently to
different browsers?



Reply With Quote
  #4  
Old   
Ben C
 
Posts: n/a

Default Re: How to make a multi-line div shrink to its content - 10-28-2007 , 04:23 AM



On 2007-10-27, crazyhorse <mjbaldwin (AT) yahoo (DOT) com> wrote:
Quote:
On Oct 27, 8:32 pm, Ben C <spams... (AT) spam (DOT) eggs> wrote:
On 2007-10-27, crazyhorse <mjbald... (AT) yahoo (DOT) com> wrote:
[...]
I want to put the list between two paragraphs, put a border around the
list (but only want the border to be as wide as the text in the list,
not the whole page width), and then center the list+border relative to
the margins of the paragraphs.
[...]
Yes, but so are most browsers. To do that you need display: inline-block
(ideal, not supported in Firefox) or display: table (not supported in
IE).
[...]
Thank you for the help. It seems to me then that the best option is to
simply put the content in a one-celled table that doesn't specify any
dimensions and then center the table, and forget about CSS altogether
in this case -- that would work on all browsers universally, no?
I don't know about "all browsers universally", but that probably is your
best bet if you require IE support. Unless you compromise a bit and set
an explicit width on the <ul>.

You could still use display: table. IE will probably default to display:
block, and will show the <ul> full width. That's still readable and
perfectly OK as a temporary solution until they upgrade to a more
functional browser-- it's not as if perfectly good browsers aren't
freely available for Windows.

Quote:
And I wouldn't have to worry about "hacking" the CSS to apply
differently to different browsers?
I don't know. Better to avoid any hacks like that if you can.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.