View Full Version : <div> CSS box problem

10-03-2007, 11:00 PM

I'm new to using <div> and css to create a layout for a site, im used to using <table> and css.

My question is thus. On the following site i have a box which will go around any message or form on my site. The problem is that the box covers the entire width of the page and i only want it to wrap around its contents, (IE the login form on the example page below) i just can't figure out how to do it.

The site is...


10-03-2007, 11:50 PM
Are you talking about the div with the id "container" or the div with the id "box"?

Either way, to edit the width you can do something like this:

width: 200px;


width: 50%;

All you need to do is define the width. You can define the width by using pixels (px), percentages (50%), etc.

10-04-2007, 12:21 AM
You then need to float the element if you want other <div></div> elements to be next to it.

10-04-2007, 08:44 AM
My bad, should have gone into a bit more detail.

The problem <div> is the one with the ID 'box'. I want it to automatically fit around whatever is in the <div> i can't use a fixed width because the contents could be bigger or smaller on different pages.

Thanks for your help