0

我正在尝试为父位置相对的子元素设置宽度。但是当我给孩子的宽度大于父母的宽度时,FireFox 中父母的宽度将会改变。而在 IE6/IE7 中,我必须更改父级的宽度,然后才能更改子级的宽度。现在,我需要改变孩子的宽度,但不要改变它的父母。谢谢!

#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>
4

2 回答 2

0

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.

于 2009-12-23T05:24:11.637 回答
0

你在使用 DOCTYPE 吗?这是确保浏览器行为相同的最佳第一步。

于 2009-12-23T03:52:46.857 回答