views:

346

answers:

2

I'm trying to set a width for a child element which parent's position is relative. But when I give a width to child larger than parent's width, the parent's width in FireFox will be changed. And which in IE6/IE7, I must change the parent's width then the child's can be changed. Now, I need to change the child's width but not change it's parent's.Thx!

#container {
  width:300px;
  height:300px;
  position: relative;
  background:#666;
}

#box {
  height:100px;
  position: absolute;
  top: 100px;
  left: 50px;
  background:#006;
  max-width:300px;
  min-width:220px;
}

<div id="container" style="float:left;">
    <div id="box">
       <div>
           <table style="border:none;padding:0 0 0 0; margin:0 0 0 0em;" border="0" cellpadding="0" cellspacing="0">
              <tr>
               <td style="width:300px; word-wrap:break-word; word-break:break-all;">               
         bmkmgklkldfbmm bmsdfkmsdfl vmsdfklvmkbsbndfbf msdvmkdvsdfkmvcnas dcbnasdjkcn asdjudhcud cadjkcnasdcbnasd jkcnasdj
                  </td>   
              </tr>
           </table>
       </div>
    </div>
</div>

   <div style="float:left;"> 
    udhcudcadjkcnasdcbnasdjkcnasdj
   </div>
A: 

Are you using a DOCTYPE? That is your best first step at ensuring that browsers act the same.

Kevin Conner
Yes.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Zodiac
A: 

Try adding overflow: hidden; to #container. Another option is overflow: scroll;. This property describes what should happen to a container element when its children are bigger than it is. I'm guessing the default behavior is different in Firefox vs. IE.

Here's some documentation.

Kevin Conner
I tried,but it doesn't work.And "overflow: scroll;" is not a good design,thx.
Zodiac