Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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 扩展父级<;部门>;到了孩子们的高度_Html_Css - Fatal编程技术网

Html 扩展父级<;部门>;到了孩子们的高度

Html 扩展父级<;部门>;到了孩子们的高度,html,css,Html,Css,我的页面结构与此类似: <body> <div id="parent"> <div id="childRightCol"> /*Content*/ </div> <div id="childLeftCol"> /*Content*/ </div> </div> </body> /*内容*/ /*内容*/ 当内部div的高度增加时,我

我的页面结构与此类似:

<body>
  <div id="parent">
    <div id="childRightCol">
      /*Content*/
    </div>
    <div id="childLeftCol">
      /*Content*/
    </div>
  </div>
</body>

/*内容*/
/*内容*/
当内部
div
高度增加时,我希望父
div
height
中展开

编辑:
一个问题是,如果子内容的
宽度
扩展超过浏览器窗口的
宽度
,我当前的CSS会在父
div
上放置一个水平滚动条。我希望滚动条处于页面级别。当前我的父div设置为
overflow:auto


你能帮我做一下CSS吗?

添加一个
清除:两个
。假设您的列是浮动的。根据您的身高是如何指定的,您可能需要一个溢出:自动

<body>
<div id="parent">
    <div id="childRightCol">
    <div>
    <div id="childLeftCol">
    <div>
    <div id="clear" style="clear:both;"></div>
</div>
</body>

您是否正在寻找一个合适的人选


如果是这样的话,请看一看,它的启动非常简单。

使用诸如自清除
div
之类的工具非常适合这样的情况。然后,您只需在父级上使用一个类。。。比如:

<div id="parent" class="clearfix">

这是否符合您的要求

.childRightCol, .childLeftCol
{
    display: inline-block;
    width: 50%;
    margin: 0;
    padding: 0;
    vertical-align: top;
}

对于那些无法在那里的说明中理解这一点的人:

尝试设置边距更多然后设置0,如果子div具有边距顶部或边距底部,则可以使用边距替换它

例如,如果你有

#childRightCol
{
    margin-top: 30px;
}
#childLeftCol
{
    margin-bottom: 20px;
}
最好将其替换为:

#parent
{
    padding: 30px 0px 20px 0px;
}

为父母试试这个,对我来说很管用

overflow:auto; 
更新:

还有一个有效的解决方案:

家长

display: table;
display: table-row;
孩子

display: table;
display: table-row;

我使父div围绕子div的内容展开,方法是将子div作为一个列,而不指定任何定位属性(如绝对值)

例如:

#wrap {width:400px;padding:10px 200px 10px 200px;position:relative;margin:0px auto;}
#maincolumn {width:400px;}
基于main column div是#wrap最深的子div,这定义了#wrap div的深度,两侧的200px填充创建了两个大空白列,供您随意放置绝对定位的div。您甚至可以使用position:absolute更改填充顶部和底部以放置页眉div和页脚div。

Add

clear:both; 
添加到父div的css中,或者在父div的底部添加一个div,该div不清除:都是


这是正确的答案,因为溢出:自动;可能适用于简单的web布局,但会干扰开始使用负边距等内容的元素

min-height:350px;
background:url(../images/inner/details_middle.gif) repeat-y 0 0 ;
padding:5px 10px;   
text-align:right;
overflow: hidden;
position: relative;
width: 100%;

您必须在父容器上应用clearfix解决方案。下面是一篇很好的文章,解释了Jens在评论中所说的修复方法

另一个答案是……而且是这样 建议设置显示:内联块。这对我来说非常有效 詹斯6月2日5点41分

这对我来说在所有浏览器中都适用。

如果#childRightCol和#childRightCol中的内容向左或向右浮动,只需将其添加到css中:

#childRightCol:before { display: table; content: " "; }
#childRightCol:after { display: table; content: " "; clear: both; }
#childLeftCol:before { display: table; content: " "; }
#childLeftCol:after { display: table; content: " "; clear: both; }
#父级{
背景颜色:绿色;
高度:自动;
宽度:300px;
溢出:隐藏;
}
#childRightCol{
颜色:灰色;
背景颜色:黄色;
利润率:10px;
填充:10px;
}


Lorem ipsum dolor sit amet,是一位杰出的献身者。你可以坐在椅子上。


此功能如规范所述-此处的几个答案是有效的,并且与以下内容一致:

如果它有块级子框,则高度是最顶部的块级子框的上边框边缘(未折叠边距)与最底部的块级子框的下边框边缘(未折叠边距)之间的距离。但是,如果元素具有非零的顶部填充和/或顶部边框,或者是根元素,则内容从最顶层子元素的上边缘开始。(第一种情况表示元素的顶部和底部边距与最顶部和最底部的子元素的顶部和底部边距折叠,而在第二种情况下,填充/边框的存在可防止顶部边距折叠。)类似地,如果元素具有非零的底部填充和/或底部边框,然后,内容在最底部子项的底部边距边缘结束


从这里开始:

试着给出父母身高的
最大含量

.parent{
   height: max-content;
}

下面的代码对我来说很有用

overflow:auto; 
css html

#childRightCol
{
浮动:对;
}
#childLeftCol
{
浮动:左;
}
#母公司
{
显示:内联;

}
我们从哪里开始

下面是一些样板HTML和CSS。在我们的示例中,我们有一个父元素和两个浮动的子元素

/*您开始使用的CSS可能与此类似。
*这还不能解决我们的问题,但我们很快就会解决。
*/
.包含div{
背景色:#d2b48c;
显示:块;
高度:自动;
}
·浮动分区{
浮动:左;
宽度:50%;
}
.浮动div ul{
显示:内联块;
高度:自动;
}

  • 第一项
  • 清单项目二
  • 清单项目三
  • 清单项目四
  • 清单项目5
  • 清单项目6
  • 清单项目7
  • 清单项目8

使用最小高度,而不是设置高度属性。

在父元素上使用
height:auto
或使用
min height
将起作用。为了避免由于填充或边框而导致的水平滚动条,可以在子元素上使用
框大小:边框框
,或在父元素上使用
溢出:隐藏
。 至于由于主体宽度而导致的水平滚动条,如果您使用的是
width:100vw
而不是
width:100%