【发布时间】:2012-04-03 15:31:43
【问题描述】:
我有 2 个 div:#container 和 #main-content,它们下方是一个页脚,即使 #main-content 内的内容高度小于正文高度,页脚也需要看不见。
当我有很多内容时一切都很好,但是当我只有几行文本时,只有#container div 扩展,#main-content 没有。
我尝试为#main-content 使用 100% 高度,但它没有扩展到其父高度。
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:
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%;
}
【问题讨论】:
-
您必须将 min-height 设置为 main-content,因为默认情况下 div 不会扩展高度,div 是块级元素,默认情况下会扩展 100% 的宽度。
-
我试过了,不行
-
你能告诉我们你的工作代码吗?我是说网站
-
您只是想获得 100% 高度的白色背景吗?
-
我正在使用第二个 div 为主要内容获取白色背景,稍后我将在 #container 中添加一个没有白色背景的侧边栏