Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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 CSS父对象根据绝对定位的内容进行调整_Html_Css - Fatal编程技术网

Html CSS父对象根据绝对定位的内容进行调整

Html CSS父对象根据绝对定位的内容进行调整,html,css,Html,Css,我希望我的父母div根据内容调整其大小,但我的问题是内容使用position:absolute将父级div呈现为没有任何内容 以下是a和相应的代码: HTML 我想我想从这个问题中得出以下结论: 我可能的解决方案是什么 如果我们考虑到跨浏览器友好性,这些解决方案中哪一个是最好的 你见过这条线吗@帕斯卡尔戈德巴赫好的,谢谢,我来看看。为什么是绝对的?您可以执行position:relative,这样可以在保留“阴影元素”的同时进行定位。@4castle,因为这样会影响其他内容的位置,如下所示。请

我希望我的父母
div
根据内容调整其大小,但我的问题是内容使用
position:absolute将父级
div
呈现为没有任何内容

以下是a和相应的代码:

HTML 我想我想从这个问题中得出以下结论:

  • 我可能的解决方案是什么
  • 如果我们考虑到跨浏览器友好性,这些解决方案中哪一个是最好的

你见过这条线吗@帕斯卡尔戈德巴赫好的,谢谢,我来看看。为什么是绝对的?您可以执行
position:relative
,这样可以在保留“阴影元素”的同时进行定位。@4castle,因为这样会影响其他内容的位置,如下所示。请注意,我还有其他块作为内容,它们也是绝对定位的。@4castle这里有另一个我使用
relative
display:inline块的地方在块上,但是同样的问题发生了。你看到这个线程了吗@帕斯卡尔戈德巴赫好的,谢谢,我来看看。为什么是绝对的?您可以执行
position:relative
,这样可以在保留“阴影元素”的同时进行定位。@4castle,因为这样会影响其他内容的位置,如下所示。请注意,我还有其他块作为内容,它们也是绝对定位的。@4castle这里有另一个我使用
relative
display:inline块的地方在块上,但同样的问题也会发生。
<p>Gray box adjusts based on the green box's size.</p>
<div class="box">
  <div class="block"></div>
</div>

<p>Gray box doesn't adjust because the green box is absolutely positioned.</p>
<div class="box">
  <div class="absolute block"></div>
</div>
.box {
  padding: 5px;
  background-color: #888888;
}

.block {
  width: 60px;
  height: 60px;
  background-color: #65da98;
}

.absolute {
  position: absolute;
  left: 50px;
}