Avatar of John Carney
John Carney
Flag for United States of America asked on

Giving a div an adjustable width.

Please take a look at this page: http://www.discretedata.com/JCPortfolio/testAuto.html

How do I style the container so that its width adjusts to the fixed size of the inner-container?

Thanks!

John
CSS

Avatar of undefined
Last Comment
John Carney

8/22/2022 - Mon
Mark Steggles

Hello,

You cant make a div do that. Is the inner container always going to have that width? Cant you just give the outer container a width of say 640px

Thanks
John Carney

ASKER
So you can do it with height but not width? I guess the only way to do it would be to make your container a one cell table. Is that considered to old-fashioned to do nowadays?

John
ASKER CERTIFIED SOLUTION
Mark Steggles

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark Steggles

*Unless a div is given a width it will always be as wide as it can be
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mark Steggles

I could write u a little javascript if u want
SOLUTION
David S.

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
John Carney

ASKER
Yes please, a javascript would be great!
John Carney

ASKER
I stumbled upon a stupidly simple solution that works in Firefox, Chrome and Safari, and almost works in Opera: give container the style "display:table" as Kravimir suggested, AND a width less than its child. (display:table alone doesn't work, at least not for me).
  Of course it doesn't work at all in IE, but it's very tantalizing, so I'm wondering if it triggers something in you that would be an all-purpose answer.  Here's what I mean: http://www.discretedata.com/JCPortfolio/testAuto2.html

Thanks,
John
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.