[英]Content div won't expand to 100% of its container
I have 2 divs: #container and #main-content, beneath them is a footer which needs to be out of sight even if the height of the content inside #main-content is smaller than body height. 我有2个div:#container和#main-content,在它们下面的是一个页脚,即使#main-content内的内容的高度小于正文高度,也需要保持页脚不可见。
Everything is fine when I have a lot of content, but when I have only a few lines of text only the #container div expands,#main-content doesn't. 当我有很多内容时,一切都很好,但是当我只有几行文本时,仅#container div会扩展,而#main-content不会。
I tried using 100% height for #main-content but it doesn't expand to its parent height. 我尝试将100%的高度用于#main-content,但不会扩展到其父级高度。
html: 的HTML:
<div id="container" class="cf">
<div id="main-content" role="main" class="cf">
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php wp_title(); ?></h2>
<?php get_template_part( 'content', 'page' ); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div><!-- #main-content -->
</div><!-- #container -->
css: CSS:
body {
width: auto;
height: 100%;
}
html {
height: 100%;
}
#container {
width: 1180px;
margin: 0 auto;
height: auto !important;
min-height: 100%;
height: 100%;
}
#main-content {
background: white;
width: 850px;
height: 100%;
}
Did you try to remove : 您是否尝试删除:
height: auto !important;
The !important erase your latter 100% style. !important删除您后面的100%样式。 A parent's Height must be set for a child 100% height to work.
必须设置父母的身高,才能让孩子100%的身高正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.