What is preventing this code from setting the background color of the main content all the way to the bottom of the

I designed this webpage using HTML and CSS.

...

#contents
{
    margin: 0px;
    padding: 0px;
    width: 100%;
    background-color: white;
    color: black;
    border-top: 3px solid black;
    background-image: url(img/CloverImage.png);
    background-size: 300px 400px;
    background-repeat: no-repeat;
}

#content
{
    margin: auto;
    padding: 50px;
    width: 860px;
    height: auto;
    color: black;
}

...

<div id="contents">
<div id="content">
<p id="title">What are we making?</p>
<div id="mainapp">
    <h1>Pegasus</h1>
    Pegasus is very useful wordpress poster application.<br>
    This app can input html tags easily.<br>
    We're making it to open to the public.
</div>
<div id="subapp1">
    <h1>A to Z</h1>
    HAHAHAHA
</div>
<div id="subapp2">
    <h1>A to Z</h1>
    HEHEHEHE
</div>
</div>
</div>

...

I am trying to change the background color of the main contents section downwards.

However, this code snippet does not seem to accomplish that. Can you help me solve this issue?

You can visit the site at:

Please provide a solution if you have one. Thanks!

Answer №1

If you're dealing with floated elements, consider using a clearfix or clear class to manage their behavior

Clear class

HTML

<div id="content">
    <p id="title">What are we creating?</p>
    <div id="mainapp"> 
        <h1>Pegasus</h1>
        Pegasus is an incredibly helpful WordPress posting application.<br>
        This app simplifies inputting HTML tags and will soon be available to the public.
    </div>
    <div id="subapp1">
        <h1>A to Z</h1>
        HAHAHAHA
    </div>
    <div id="subapp2">
        <h1>A to Z</h1>
        HEHEHEHE
    </div>
    <div class="cb"></div>
</div>

CSS

.cb{
    clear:both;
}

Alternatively, use the clearfix class (based on the HTML5 boilerplate)

HTML

<div id="content" class="clearfix">
    <p id="title">What are we creating?</p>

CSS

.clearfix:before,
.clearfix:after{
    content: " ";
    display: table;
}
clearfix:after{
    clear: both;
}
/* * For IE 6/7 only * Include this rule to trigger hasLayout and contain floats. */
.clearfix {
    *zoom: 1;
}

There are various methods to clear floats, but I hope you grasp the concept.

You can learn more about floats and clearing them from these resources:

Mozilla Developer Network https://developer.mozilla.org/en-US/docs/Web/CSS/float

WebPlatform

Micro clearfix [HTML5 boilerplate uses it]

Answer №2

When you analyze the <div id="contents"> element using Chrome devtools, you'll notice that its size doesn't adjust properly with its content. This usually happens when it contains floating elements without proper clearing by the parent.

There are several solutions available to fix this issue.

The simplest method is to apply overflow: hidden to the CSS of the #contents element.

CSS

#contents { overflow: hidden; }

For a more advanced and versatile solution that can be used across your template, consider using the micro-clearfix technique introduced by Nicolas Gallagher. This approach involves adding a clearfix class to the HTML markup.

CSS

.clearfix:before,
.clearfix:after {
  content: '';
  display: table;
}

.clearfix:after {
  clear: both;
}

.clearfix {
  *zoom: 1;
}

Although I have only tested these fixes in Chrome, they should also work effectively in other browsers.

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

What causes a span with absolute positioning to not be correctly positioned within a span with relative positioning in Firefox, unless it is displayed as inline-block or similar?

Can you explain why the code below doesn't display correctly in Firefox unless the parent span is set to display as inline-block? When inspecting the layout of the absolutely positioned span, it shows the number 184 instead of 197 on the right side. A ...

How can we apply CSS to all pages except for one containing the "howto" placeholder?

Hey, we're dealing with multiple pages that require CSS styling. .cms-index-noroute .col-main .std {font-weight: bold} .cms-index-list .col-main .std {font-weight: bold} .cms-index-view .col-main .std {font-weight: bold} We'd prefer to simplify ...

Using jQuery to clear a textarea when a select input is changed

Currently, I am in the process of developing a small text editor that enables users to edit files and create new ones. Here is how I have set up my select menu. <select name="reportname" id="reportname" class="form-control"> <option value="zr ...

How can I create off-center underlined text?

I am looking to create a unique text effect where the underline is off-centered and overlaps the text. However, I am unsure of how to achieve this. Can someone guide me on the best way to replicate the following effect? Current Code: ...

The issue I'm facing is that the style loader is failing to load the CSS within the <head

I am currently facing an issue with importing my CSS into my webpack bundle for our Angular 1 application. Initially, everything was working fine as we bundled our application using Webpack. The HTML included the bundle and vendor scripts, additional Java ...

`I noticed that the CSS appears differently when viewed in Mozilla compared to Chrome``

Why do the images with the same CSS property appear different in Chrome and Mozilla? I want them all to float left with equal margins between them, covering the complete area horizontally despite having varying image widths. I'm unsure why there is a ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

Expansive picture within a Bootstrap container

How can I create a wide image within a Bootstrap container? <div class="container-fluid"> <div class="container"> <img data-layout="wide" src="big-image.jpg" alt="Big image" class="embedded_image"> </div> </div& ...

What could be causing my Bootstrap datepicker to malfunction?

A while ago, my Bootstrap datetimepicker component was functioning perfectly in my code. However, it has suddenly stopped working and I am seeking assistance to get it running smoothly again. Below is the HTML code snippet: <script src="https://cd ...

Determine the specific value of an HTML table cell by specifying the column name for a specific row

One challenge I am facing is dynamically creating a table using JSON without knowing in advance the number of columns and/or rows that will be generated. I have successfully added a clicked event for the row that gets selected. In every table, there will ...

Steps for transforming a matplotlib animation into an HTML5 `<video>` element

Here is the code for a matplotlib animation graph and you can find instructions on how to save it here. from IPython.display import HTML import matplotlib.pyplot as plt import matplotlib.animation import numpy as np t = np.linspace(0,2*np.pi) x = np.sin ...

Can one utilize HTML's .querySelector() method to target elements by xlink attribute within an SVG document?

Here is the scenario: <body> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <a xlink:href="url"></a> </svg> </body> Now, can you utilize the HTML DOM's .querySe ...

What is the best way to create a border with an inside radius?

Looking to design a div with an inner circle in the corner similar to the image below. Seeking assistance to find a solution for this issue. ...

What is the method for activating -webkit-animation/transition-property for :before and :after pseudo elements?

Is there a way to activate the -webkit-animation for :before and :after pseudo elements? It seems that in this demo http://jsfiddle.net/4rnsx/, the animation is not working for :before and :after elements. I am attempting to make it work using Mootools ...

Using Angular directives to pre-select a default option

I am currently working on a select HTML tag with two options, and I want to set the first option as the default choice. My select element includes Angular directives like ng-change and ng-model. I have attempted to achieve this by adding selected = "select ...

What could be causing my modal to not animate from the center of the screen?

I am aiming to have my .modal div class smoothly scale from 0 to 1 right in the center of the screen instead of starting at the bottom right and then moving to the center before settling in its final position. I have checked various resources like MDN docu ...

Every time I hover, my jQuery code keeps repeating the hover effect

I am currently facing an issue that has me stumped on finding a solution. The problem arises when I hover over the .div multiple times, the animation just doesn't stop and keeps running continuously. What I aim for is to have the .hidden element fad ...

When a user clicks on an image, I would like to dynamically resize it using a combination of PHP

Although I have a good understanding of CSS and HTML, my knowledge of Javascript is limited. I am looking to add an interactive element to my website where an image enlarges gradually when clicked and smoothly moves to the center of the screen in one con ...

What is the reason for the columns being divided on the xs-viewport in Bootstrap?

Attempting to grasp the concepts of Bootstrap has left me puzzled, as I cannot comprehend why the col-xs-11 is not aligning correctly with the col-xs-1. Despite having a total of 12 columns, the layout seems off. CSS: [class^="col-"] { height: 20px; ...

Is there a way to move my icon to the next row once it is added?

Can anyone suggest a style, bootstrap, or code solution for my issue? Currently, when I add an item, it is placed at the end of the row, but I want them to shift to the next row. Below are two images showing my current implementation: pic1 pic2 <div cl ...