Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使div宽度拉伸以适合其内容_Html_Css - Fatal编程技术网

Html 使div宽度拉伸以适合其内容

Html 使div宽度拉伸以适合其内容,html,css,Html,Css,我有以下html代码: <table> <tr> <td> <div id="fixmywidth" style="position:relative; height:30px;"> <div style="z-index: 2000; margin-top: 5px; height: inherit; position: absolute;"> <table style

我有以下html代码:

<table>
  <tr>
    <td>
      <div id="fixmywidth" style="position:relative; height:30px;">
        <div style="z-index: 2000; margin-top: 5px; height: inherit; position: absolute;">
          <table style="height:inherit">
            <tr style="height:inherit">
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
              ........300 tds later
              <td align="center" style="width: 31px; height: inherit;">&nbsp;</td>
            </tr>
          </table>
        </div>
      </div>
    </td>
  </tr>
</table> 

……300 tds之后
如何使id为“fixmywidth”的div的宽度适合包含元素的宽度? 我试过宽度=100% 和widt=自动 但它们不会起作用 提前感谢一万亿美元,
Lina

这是不可能的,因为它里面的div实际上不在它里面,因为它的位置是相对的/绝对的


我不是100%确定你想在那里完成什么,但是如果你删除这两个,它的大小将正确。

这是不可能的,因为它里面的div实际上不在它里面,因为它的位置是相对的/绝对的


我不是100%确定你想在那里完成什么,但是如果你删除这两个,它的大小会正确。

从fixmywidth的直接子级删除position absolute

从fixmywidth的直接子级删除position absolute

通过“包含元素”,你是指包含
的元素吗,还是
中包含的元素

如果是后者,费边是对的,问题在于:

<div style="z-index: 2000; margin-top: 5px; height: inherit; position: absolute;">

位置:绝对位置
从文档流中取出,因此不占用任何空间。因此,其包含元素(
)不包含文档流中的任何元素,因此没有维度

您可以通过删除
position:absolute,但这可能不符合您的布局目标。

所说的“包含元素”,是指包含
的元素,还是包含在
中的元素

如果是后者,费边是对的,问题在于:

<div style="z-index: 2000; margin-top: 5px; height: inherit; position: absolute;">

位置:绝对位置
从文档流中取出,因此不占用任何空间。因此,其包含元素(
)不包含文档流中的任何元素,因此没有维度


您可以通过删除
position:absolute,但这可能不符合您的布局目标。

如果从“fixmywidth”中删除
位置:相对
,它应该可以工作。

如果从“fixmywidth”中删除
位置:相对
,它应该可以工作