Forum Moderators: not2easy

Message Too Old, No Replies

CSS Container DIV needs to grow with wide content

         

britsky

4:59 pm on Apr 1, 2008 (gmt 0)

10+ Year Member



I want my container DIV to be as wide as the content within it. The code below shows as close as I've come.

The problem is that there is another DIV (class="header") inside the container. The HEADER DIV is inherting the min-width of the CONTAINER DIV in IE 7, instead of going the entire width of the CONTAINER DIV


<html>
<head>
<style type="text/css">
.container {
border: 1px solid green;
width: auto;
min-width: 200px;
display: table;
}
.header {
background: gray;
font-size: 12pt;
padding: 2px;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
This Is The Header
</div>

<table border="1" cellpadding="2" cellspacing="0" width="300">
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
</table>
</div>
</body>
</html>

SuzyUK

7:58 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi britsky and Welcome to WebmasterWorld!

sorry not quite seeing what you're describing with the code above in IE7 the header is 100% of the page width?

IE doesn't support display: table (or any of the table properties) yet.. on its way in IE8, but maybe using inline-block for it would help?

.container {
border: 1px solid green;
min-width: 200px;
display: table;
}

.header {
background: gray;
font-size: 12pt;
padding: 2px;
}
</style>

<!--[if lte ie 7]>
<style type="text/css" media="screen">
.container {display: inline-block;}
.container {display: inline;}
</style>
<![endif]-->

IE has to have it in 2 x separate rules like that as it doesn't support inline-block on block level elements yet.

might work, but like I said I'm not seeing what you're seeing so it could be the wrong tack

-Suzy

Dave75

4:24 pm on Apr 2, 2008 (gmt 0)

10+ Year Member



Yup, take out the .container{display:table;} declaration.