I'm puzzled as to why the background isn't fully covering all of the content on the page

As an IT student, I have been diligently working on creating a website for my assignment. However, I am facing an issue with the background not adjusting properly based on the content placed within it. While one page includes all the sub-divs as intended, another page does not.

.mainContent {
    font-family: "Arial", Helvetica, sans-serif;
    font-size: 2em;
    background-color: lightgrey;
    padding: 30px 30px;
    height: auto;
}
<div class="mainContent">
    <h1>Featured Artist - Monarchy</h1>
    <h4 class="fontChange">Artist Biography:</h4>
    <p class="fontChange">
        Monarchy are a British rock band made up of Fred Venus, Bryan June, 
        Roger Cobbler and Jon Vicars. They formed in Preston in 1970 after 
        Bryan & Roger left their previous band 'Cheesy Grin'. They achieved 
        moderate chart success and have played to large stadiums such as 
        the Globe Arena, Deepdale Stadium & Gigg Lane. Their first album 
        'Monarchy' reached a high point of 164 in the album charts in 1974, 
        while their 1075 album 'Night at the Guilhall' brought them international 
        success and was the top selling album that year in Liechtenstein.
        That album featured the single 'Slavic Symphony', which stayed at 
        number one in the UK for nine seconds.
    </p>
    <h5 class="fontChange">
        Albums
    </h5>
    <div id="albumOne">
        <img class="imgBorder" src="Assets/Images/monarchy-album.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumTwo">
        <img class="imgBorder" src="Assets/Images/monarchy-DE.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumThree">
        <img class="imgBorder" src="Assets/Images/monarchy-ES.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumFour">
        <img class="imgBorder" src="Assets/Images/monarchy-ludo.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumFive">
        <img class="imgBorder" src="Assets/Images/monarchy-album.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumSix">
        <img class="imgBorder" src="Assets/Images/monarchy-DE.jpg">
        </img>
        <span class="caption">Text below the image</span>
    </div>
</div>

The grey background should encompass the following divs.

I apologize for the imperfect formatting in this post as it's my first attempt.

An example where it works on the first page is shown above

An example where it doesn't work on the second page is also seen here

Answer №1

By default, the html body has a margin of 8px. To remove this margin, you need to set the body margin to 0px.

html body {
    margin: 0;
}
.mainContent {
    font-family: "Arial", Helvetica, sans-serif;
    font-size: 2em;
    background-color: lightgrey;
    height: auto;
    width:100%
}
.title{
    margin-top: 0px;
}
<div class="mainContent">
    <h1 class="title">Featured Artist - Monarchy</h1>
    <h4 class="fontChange">Artist Biography:</h4>
    <p class="fontChange">
        Monarchy are a British rock band made up of Fred Venus, Bryan June, 
        Roger Cobbler and Jon Vicars. They formed in Preston in 1970 after 
        Bryan & Roger left their previous band 'Cheesy Grin'. They achieved 
        moderate chart success and have played to large stadiums such as 
        the Globe Arena, Deepdale Stadium & Gigg Lane. Their first album 
        'Monarchy' reached a high point of 164 in the album charts in 1974, 
        while their 1075 album 'Night at the Guilhall' brought them international 
        success and was the top selling album that year in Liechtenstein.
        That album featured the single 'Slavic Symphony', which stayed at 
        number one in the UK for nine seconds.
    </p>
    <h5 class="fontChange">
        Albums
    </h5>
    <div id="albumOne">
        <img class="imgBorder" src="Assets/Images/monarchy-album.jpg">
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumTwo">
        <img class="imgBorder" src="Assets/Images/monarchy-DE.jpg">
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumThree">
        <img class="imgBorder" src="Assets/Images/monarchy-ES.jpg">
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumFour">
        <img class="imgBorder" src="Assets/Images/monarchy-ludo.jpg">
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumFive">
        <img class="imgBorder" src="Assets/Images/monarchy-album.jpg">
        <span class="caption">Text below the image</span>
    </div>
    <div id="albumSix">
        <img class="imgBorder" src="Assets/Images/monarchy-DE.jpg">
        <span class="caption">Text below the image</span>
    </div>
</div>

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

Ways to implement material-ui button design on an HTML-native button

I am using pure-react-carousel which provides me an unstyled HTML button (ButtonBack). I would like to customize its style using material-ui. Trying to nest buttons within buttons is considered not allowed. An approach that works is manually assigning th ...

Django causing CSS issues following the utilization of an if statement

I have been working on adding a dropdown list to my navbar, which I created using Bootstrap. However, whenever I place the dropdown menu inside an if statement for looping categories into a list, it seems to be breaking the CSS. Check out the navbar witho ...

Troubleshooting problem with AngularJS and jQuery plugin when using links with # navigation

I have integrated a specific jquery plugin into my angularjs single page application. The primary block can be found in the following menu: http://localhost:81/website/#/portfolio This menu contains the following code block: <li> <a href=" ...

Deactivate options in the dropdown selection

Is there a way to disable specific values in a dropdown list? While exploring a solution here, I discovered that adding a disabled style to <a> should disable the element. However, when I tried this method on dropdown element B, it did not work as e ...

Tips for avoiding the display of the overall scrollbar while utilizing grid with an overflow:

In my react-redux application, I am utilizing the material ui Grid component for layout design. The structure of my code is as follows: <div> <Grid container direction="row" spacing={1}> <Grid item xs={3}> ...

Is there an easy method for customizing scrollbars?

I'm looking to include an "overflow:scroll" in a navigation div, but the default scrollbar on windows is unattractive. Is there a simple way to customize the scrollbar without having to download extra JavaScript libraries, APIs, and so on? ...

Tips for implementing HTML5 validation followed by automatic redirection to a different page

I'm new to web development and struggling with how to make a button both validate inputs and redirect to another page. Using the onclick = "" function, I can validate inputs like emails and telephone numbers, but I'm having trouble making it so t ...

Responsive design is key in ensuring that Bootstrap columns adjust accordingly

I am attempting to create a responsive block in the center of my webpage with the help of Bootstrap. However, I am having trouble getting the columns to respond correctly to my bootstrap setup. Can anyone point out what I might be doing wrong? <lin ...

The image will only display upon receiving a link, not a path

Having some trouble displaying an image on my website, despite having successfully done so in the past for other projects. The image is located in the same folder as my HTML file. Here's what I've tried: <img src="reddit.png"/> <img s ...

If the content within a <div> element exceeds the available width, a horizontal scrollbar will be displayed

I have a scenario where I am using an absolute div to overlap another div. The div that overlaps is the absolute one (.content), and if the overlapped div (.left) doesn't fit the screen width, a horizontal scroll bar does not appear. How can I automat ...

Having trouble installing $ npm i mini-css-extract-plugin. Any ideas on what might be causing the issue?

There seems to be an error in my setup. I am using Visual Studio Code with gitBash. $ npm i mini-css-extract-plugin npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-p ...

A step-by-step guide to invoking a function upon submitting a form with an external JavaScript file

How can I execute a function when the user submits a form using an external JavaScript file? index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>example</title> ...

The button in the flex container is not wide enough due to center alignment

For my project, I implemented a CSS grid layout consisting of 20 rows and 20 columns (5% of screen for each cell). One particular page includes a button that initially fit within grid columns 5-8 and rows 6-9 without any issues. However, I wanted to center ...

What is the method to convert Javascript values from pixels to percentages?

Is it possible to change the scrolltop value dynamically based on a percentage of the user's screen size? I've been trying to achieve this using JS but haven't had any luck. Here is a link to a codepen that showcases the issue: [link] (http ...

Various Overlay Shapes in Bootstrap Using CSS

So I'm in the process of styling my landing page with CSS based on a design I have in Figma. The page is using Bootstrap 5 as its framework, though I'm not sure if that detail matters in this case. I believe it's definitely doable, but I&apo ...

Error: Disappearing textarea textContent in HTML/TS occurs when creating a new textarea or clicking a button

I've encountered an issue with my HTML page that consists of several textareas. I have a function in place to dynamically add additional textareas using document.getElementById("textAreas").innerHTML += '<textarea class="textArea"></text ...

The concept of columns nested within columns

My goal is to create three new columns within the center column on my webpage. However, when I attempt to nest them, they end up stacking at the bottom of the center column instead of staying inside it. Is there a way for the center column to act as a back ...

Extracting information from an ENORMOUS Array

Let's start with my code snippet, featuring an array: var UserProfiles = [{ userProfileID: 1, firstName: 'Austin', lastName: 'Hunter', email: 'test', token: '', platform: 'android ...

Tips for eliminating the bottom border on a nav-tab in Bootstrap 4

When a vertical navigation menu item is selected, a border appears below the item. How can I remove this border? .nav-tabs li, .nav-tabs li a { border-bottom: none; } Here is a picture of the border: ...

Steps to utilize a PHP include for displaying HTML content corresponding to the URL file name

I am currently working on a PHP script that utilizes PHP include to insert HTML content based on the filename from the URL. For instance, with the use of PHP include: - if the filename in the URL is dog.html, it will display dog within the HTML document. ...