Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Simple CSS box problem

Question posted by: j055 (Guest) on June 27th, 2008 07:19 PM
Hi

The following HTML shows a table with some wide content which overlaps
an outer div when the browser width is narrowed? How do I allow the
table content to push the div to the width of the table?

I want the div to normally be centered and 90% of the page width. The
table content is dynamic so I never know how wide it's going to be. I
just want to handle things more gracefully than overlaping it.

Many thanks
Andrew

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Box problem</title>
<style type="text/css">
.box
{
margin: 0 auto;
width: 90%;
border: solid 2px red;
}
</style>
</head>
<body>
<div class="box">
<table cellspacing="0">
<tr>
<td>

verywidestuffverywidestuffverywidestuffverywidestu ffverywidestuffverywidestuffverywidestuffverywides tuffverywidestuffverywidestuff
</td>
</tr>
</table>
</div>
</body>
</html>
Jonathan N. Little's Avatar
Jonathan N. Little
Guest
n/a Posts
June 27th, 2008
07:19 PM
#2

Re: Simple CSS box problem
j055 wrote:
Quote:
Hi
>
The following HTML shows a table with some wide content which overlaps
an outer div when the browser width is narrowed? How do I allow the
table content to push the div to the width of the table?
>
I want the div to normally be centered and 90% of the page width. The
table content is dynamic so I never know how wide it's going to be. I
just want to handle things more gracefully than overlaping it.
>
Many thanks
Andrew
>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Box problem</title>
<style type="text/css">
.box
{
margin: 0 auto;
width: 90%;
border: solid 2px red;
}
</style>
</head>
<body>
<div class="box">
<table cellspacing="0">
<tr>
<td>
>
verywidestuffverywidestuffverywidestuffverywidestu ffverywidestuffverywidestuffverywidestuffverywides tuffverywidestuffverywidestuff
</td>
</tr>
</table>
</div>
</body>
</html>


It's the old "10 lbs of **** in a 5-lb bag" problem. You either have to
*not* constrain the width of the container OR accept results of overflow.

"overflow: visible" is what you are now witnessing, "overflow: hidden"
will crop off the content at the border, or "overflow: auto" will create
a scroll bar when the content does not fit.

My advice, none of the above, but rather rethink your design. Of course
a real-world example (via a URL please!) would be more enlightening then
that unrealistic code snippet

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Ben C's Avatar
Ben C
Guest
n/a Posts
June 27th, 2008
07:19 PM
#3

Re: Simple CSS box problem
On 2008-06-06, j055 <andrew.jocelyn@orbnet.co.ukwrote:
Quote:
Hi
>
The following HTML shows a table with some wide content which overlaps
an outer div when the browser width is narrowed? How do I allow the
table content to push the div to the width of the table?
>
I want the div to normally be centered and 90% of the page width. The
table content is dynamic so I never know how wide it's going to be. I
just want to handle things more gracefully than overlaping it.


Add display: table to the styles for .box.

Not expected to work in IE, where you will just have to use a <table>.
Or just put the red border on the table you already have and forget the
div, although in the real page, the div perhaps has some purpose.

There are other ways, but not if you want .box centered and with a
minimum width of 90%. If you didn't mind it on the left, you could use
float: left and min-width: 90% instead of display: table.
Quote:
Many thanks
Andrew
>
><html xmlns="http://www.w3.org/1999/xhtml">
><head>
<title>Box problem</title>
<style type="text/css">
.box
{
margin: 0 auto;
width: 90%;
border: solid 2px red;
}
</style>
></head>
><body>
<div class="box">
<table cellspacing="0">
<tr>
<td>
>
verywidestuffverywidestuffverywidestuffverywidestu ffverywidestuffverywidestuffverywidestuffverywides tuffverywidestuffverywidestuff
</td>
</tr>
</table>
</div>
></body>
></html>


 
Not the answer you were looking for? Post your question . . .
190,182 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors