Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-29
5
Medium Priority
?
246 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

971 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