html - 如何增加带有子内容的 div 高度?

标签 html css

我试图让白色背景突出标题周围,同时突出其余内容。 overflow,clear,min-height max-height,*,我能想到的都试过了。

<html>
<head>
    <title>Ventura County CEC</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="global.css">

    <style type="text/css">
        html
        {
            height: 100%;
        }
        body
        {
            min-height: 100%;
        }
        #courseContainer
        {
            width: 960px;
            background-color: #ffffff;
            position: relative;
            margin: 0 auto;
            height: *;
            /*min-height: 1610px;*/
            padding-left: 15px;
            padding-right: 15px;
        }

        #courses
        {
            position: absolute;
            top: 221px;
            height: *;
            width: 960px;
            border: 1px #cccccc dotted;
            border-radius: 4px;
            /*height: -moz-calc(* + 3px);
            height: -webkit-calc(* + 3px);
            height: -o-calc(* + 3px);
            height: calc(* + 3px);*/
            padding-bottom: 3px;
            background: #ffffff;
        }

        /*#superCourses
        {
            background: #ffffff;
            width: 960px;
            height: *;
        }*/

        .course
        {
            position: relative;
            height: 120px;
            width: 952px;
            margin-top: 3px;
            margin-left: 3px;
            border: 1px #cccccc dotted;
            border-radius: 4px;
        }

        .course_title
        {
            position: absolute;
            left: 5px;
            width: 150px;
            height: 120px;
            line-height: 100px;
            text-align: center;
        }

        .titleAlign
        {
            display: inline-block;
            vertical-align: middle;
            line-height: normal;
        }

        .course_description
        {

            position: absolute;
            left: 150px;
            top: 10px;
            bottom: 10px;
            width: 340px;
            height: 100px;
            overflow: auto;
            z-index: 5;


        }

        .course_pics
        {

            position: absolute;
            left: 450px;
            height: 110px;
            width: 100px;
            margin-top: 5px;

        }

        .picture
        {

            position: absolute;
            height: 110px;
            width: 250px;

        }

        .course_ment_loc
        {
            position: absolute;
            right: 5px;
            top: 10px;
            width: 200px;
            text-align: center;
            vertical-align: middle;
            height: 110px;
        }

        .teacher
        {
            top: 0px;
        }

        .school
        {
            position: absolute;
            bottom: 0px;
        }

    </style>
</head>

<body>
    <div id="courseContainer">

        <?php include 'title.php';?>
        <div id="superCourses">
            <div id="courses">

                <div id="list">
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                    <?php include 'CECCourses/courseTemplate.php';?>
                </div>

            </div>
        </div>
    </div>
</body>

最佳答案

您的 #courses div 是绝对定位的,这就是为什么您的背景没有包围该元素。

如果您从该元素中删除 position: absolute; 它将解决您的问题并且背景将扩展到整个高度。请注意,#courses 的位置样式有两次属性:一次在您的 global.css 中,一次在 courses.php 中。


编辑:

如果在其他页面使用了#courses的定位,而global.css需要保持原样,只需更改courses.php的样式,将#courses改为相对定位即可:

#courses
{
    position: relative;
    top: 221px;
    height: *;
    width: 960px;
    border: 1px #cccccc dotted;
    border-radius: 4px;
    /*height: -moz-calc(* + 3px);
    height: -webkit-calc(* + 3px);
    height: -o-calc(* + 3px);
    height: calc(* + 3px);*/
    padding-bottom: 3px;
    background: #ffffff;
}

关于html - 如何增加带有子内容的 div 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22053778/

相关文章:

html - <table> 可以同时具有 border-radius 和 border 属性吗?

html - Bootstrap container-fluid 不会在平板电脑中扩展

css - 使用 Google Material Design 的 Summernote

css - 使用 CSS 选择器选择下拉值

html - Bootstrap 网格 3x3 Firefox 与 Chrome 错误

javascript - 如何使单选按钮水平并带有填充

html - 如何在下拉菜单中添加右下拉菜单?

jquery - 嵌套 div 使父 div 错位

javascript - 如何排除页面元素触发 jQuery 模糊事件?

javascript - 元素在输入焦点上随机消失 - Safari IOS