Link to home
Start Free TrialLog in
Avatar of DOCDGA
DOCDGA

asked on

How can I dynamically change the width of a div tag based on its content

I have a table whose height and width change dynamically(as the records are added), and the table is placed inside a div tag, I would like to have the width of div tag enclosing the table also change dynamically with the width and height of the table.
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

for the div i would use

.divcss {

width: auto;
}

Does that not work?
Avatar of DOCDGA
DOCDGA

ASKER

Hi Joshua,
Thanks a lot for replying to my query. When I tried setting width to auto, the width of div increased to encompass with of table, but , the width of the table inside div tag has also increased considerably. I do not want the width of the table to be increased further. Is there any round about to fix it..
ASKER CERTIFIED SOLUTION
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DOCDGA

ASKER

Hi Joshua,

Thanks again for your suggestions. I have tried adding margins as you mentioned, I have not got results any different. But I think I will go ahead with making width - auto instead of using javascript to get width changed dynamically.
no problem,

the margin left and right auto should be added to the table class not the div. That will make a difference. It would be easier if you could post the page somewhere so we can see it.