Solved

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

Posted on 2014-09-29
5
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Stressed Out?

Watch some penguins on the livecam!

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…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

634 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