What is the best way to adjust the height of a div based on its child content

I've been experimenting with various methods to extend the white background around the title to cover the rest of the content. I've tried using overflow, clear, min-height, max-height, and even the '*' selector but nothing seems to work.

<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>

Answer №1

It seems like the #courses div is positioned absolutely, causing the background not to cover the entire element.

To fix this issue, try removing the position: absolute; from the element. It appears that the position style for #courses is defined twice - once in global.css and once in courses.php.


Edit:

If the positioning of #courses is necessary for other pages and global.css cannot be modified, you can simply adjust the styles in courses.php to change #courses to be relatively positioned:

#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;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a webpage that dynamically loads both content and video using HTML and Javascript

I designed a loading page for my website, but I could use some assistance. The loading page remains visible until the entire HTML content is loaded and then it fades out. However, I am facing an issue because I have a background video that I want to load ...

Utilize Bootstrap's form-inline feature to arrange fields side by side in one neat

I am looking to customize my sign-in form layout by displaying the fields in a row next to each other rather than under each other. header: Update: I have successfully implemented this code <header class="navbar navbar-fixed-top navbar-inverse"> & ...

Tips on eliminating borders in react-table components

Within my React.js component, I have implemented a table using react-table along with some material-ui components displayed alongside the table: import React from 'react' import { useTable, useGlobalFilter, usePagination } from 'react-table& ...

Interested in transferring an additional column value to the $scope.seriesSelected variable?

I've been delving into Timeline charts using the angularjs google chart API and have come across an interesting limitation. It seems that only 4 columns are allowed, with the extra column designated for tooltips. However, I have a specific requirement ...

The hyperlink for making phone calls appears twice on an Android phone

When you click on the number, it will be displayed twice in the phone screen like this... 12345678910,12345678910 ...instead of just once... 12345678910 Take a look at the code snippet below: {#if order.salesRep} <div class="info"> ...

Navigating through various div elements in Javascript and sending parameters to a script

Context In my project, I am using PHP to generate a series of voting sections. Each section follows the same format except for a unique number assigned to it, which increases with each iteration of the PHP loop. To keep track of the unique numbers, I uti ...

Intermittent Z-index conflicts in need of a solution - seeking guidance

Is there a way to make the h1 heading and img image elements appear on top of the opaque div they are enclosed in? I want them to look unaffected by the transparency of their parent div. Here is a Fiddle demonstrating my issue: <div id="main"> ...

Content below divs that are fixed and absolutely positioned

I have a design layout similar to this (a small snippet) and I am facing an issue where the text within .content is not clickable. The positioning of #gradient is fixed due to the background image, and #empty has an absolute position to cover the entire bo ...

`On mobile devices, the Bootstrap button no longer displays focus changes once clicked.`

When clicking a primary bootstrap button, it changes its background color to blue on mobile devices. For example, the first button appears normal and the second one turns blue after clicking. However, this background effect disappears when clicking anywhe ...

Having difficulty adjusting the width of the CSS menu bar to fit the entire page

I found a useful CSS menu tutorial online that seems to work well, but unfortunately, it doesn't stretch the full width of the page. You can check out the tutorial here: Even after trying to set the width to 100%, the menu still falls short of extend ...

Use the controller to set the body's background image

Seeking help to update the image URL within the CSS code snippet provided. I would like to accomplish this from the controller and can work with either LESS or SCSS. Is there a solution for this? .background{ height: 100%; width: 100%; backg ...

What is the best way to maintain the formatting of a textarea in the database?

My HTML form includes a text area and a functionality to save the data into a database upon submission. The issue arises when the saved data is retrieved from the database, as the original formatting of the text gets altered. For instance: "This is a text ...

elements that do not adhere to set width constraints

I've successfully arranged elements in my HTML using flexbox to achieve a responsive design for a website. However, I've encountered an issue where the elements do not resize properly. After applying a class of flex to the home-promos div and re ...

Unable to match the height of the inner card image in bootstrap with the height of the outer card image

I'm facing an issue with two bootstrap cards, one nested inside the other, both containing images. Check out the StackBlitz here The inner image doesn't flex to the same height as the outer one, resulting in a small space between the two cards ...

Transmit data from an HTML form to PHP using JSON

I am attempting to utilize JavaScript to send POST data. I have the data in an HTML form: <form name="messageact" action=""> <input name="name" type="text" id="username" size="15" /> <input name="massage" type="text" id="usermsg" si ...

What is the best way to ensure that only one of two textboxes is filled out in an HTML form?

Looking to create 2 fields that are mutually exclusive. One will be a FileField and the other a TextBoxField. Is there an HTML form template available for this specific scenario? I've scoured the web but haven't come across one yet. Apologies ...

Image not appearing on basic HTML website

This particular issue has left me completely puzzled. After removing all the unnecessary elements from a problematic website, I am now left with an extremely basic and minimalistic site: <!DOCTYPE html> <html lang="en"> ...

Preventing default behavior in a JQuery post request

Encountering an issue with jQuery functionality on a mobile device. function send() { $.post("scripts/post.php", { username: $("input[name=username]").val(), password: $("input[name=password]").val() }, function(data) { if ($(".data div" ...

The keyboard automatically disappeared upon clicking the select2 input

Whenever I select the select2 input, the keyboard automatically closes $('select').on('select2:open', function(e) { $('.select2-search input').prop('focus',false); }); Feel free to watch this video for more i ...

Understanding the differences between jquery's addClass method and the .css()

After creating a function to set a background on a click event, I encountered an issue. I attempted two different methods, expecting both to be successful. However, only the .css() version worked while the addClass method failed. Why is this happening? fu ...