Solved

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

Posted on 2014-09-29
5
236 Views
Last Modified: 2014-10-06
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.
0
Comment
Question by:DOCDGA
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40351094
for the div i would use

.divcss {

width: auto;
}

Does that not work?
0
 

Author Comment

by:DOCDGA
ID: 40352374
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..
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40352383
add

margin-left: auto
margin-right: auto
0
 

Author Comment

by:DOCDGA
ID: 40353428
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.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40353436
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question