As I scroll, the background color of my body vanishes

Seeking assistance with a CSS issue. I have set the height property of my body to 100%, which works well when all content is visible on screen. However, when I need to scroll due to window size changes, the body color disappears and only the HTML background color remains visible. Does anyone have a solution to this problem?

html {
  background-color: #07ade0;
}

body {
  background-color: #7968ae;
  width: 900px;
  margin-left: auto;
  margin-right: auto;
  font: 20px verdana, "sans serif", tahoma;
}

Answer №1

If you have set your body to height: 100%, it will match the height of the window, which may not be ideal as longer pages could cut off the background, as you pointed out. Removing the height property should resolve this issue.

Another approach is to set height: 100% for both html and body, then create a container within the body. Transfer the styles from html to body, and the styles from body to the new container. This method is preferred over setting a pixel width on the body.

HTML

<body>
  <div id="container">Your valuable content goes here.</div>
</body>

CSS

html, body {
  height: 100%;
}
body {
  background: #07ade0;
}
#container {
  background: #7968ae;
  width: 900px;
  margin-left: auto;
  margin-right: auto;   
  font: 20px verdana, "sans serif", tahoma;
  overflow: hidden;
}

View the DEMO.

Answer №2

If you switch height to min-height on your body element, it will ensure that the body element takes up 100% of the screen if the content is not enough to fill the entire page. Additionally, it will allow the body element to expand when the content exceeds the size of the browser window.

Answer №3

The solution provided did not address the issue of a column being invisible when there is no content on the page.

In order to resolve this, I introduced a wrapper and applied display: table; which finally worked.

My approach ensures that the column has a background color even when there is no content present.

http://jsfiddle.net/h83gtmbc/6/

html, body {
    height: 100%;
}
body {
    background: #07ade0;
    padding: 0;
    margin: 0;
}

#wrapper {
height: 100%;  
}

#container {
    background: #7968ae;
    width: 900px;
    margin-left: auto;
    margin-right: auto; 
    font: 20px verdana, "sans serif", tahoma;
    
    overflow: hidden;
    height: 100%;
    display: table;
}
<div id="wrapper">
<div id="container">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquam malesuada lectus in ornare....;

Even if the contents are removed, the column will maintain its full-height appearance.

Answer №4

It appears that there is a specific issue plaguing Mac computers when using Chrome as the browser. Interestingly, all other browsers do not seem to encounter this problem. My hypothesis is that it may be related to the window size, as during testing, adjusting the inspection window size briefly reveals the background color before it disappears again when the site is at full width.

While I'm not entirely certain if this is the optimal solution, you could try adding the following code snippet to the container or div causing the issue. This approach worked for me in resolving the problem:

.full_width {
position: relative;
}

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

The hyperlinks in the navigation bar are leading me to incorrect destinations

I am currently developing an authentication app and facing an issue with the navbar links for register and login. They are not redirecting me to the correct destination. These links work perfectly on the landing index page, but not on any other page. site ...

Implementing Update and Delete Features for Database Rows in Repeater

I have a repeater set up to extract and display data from a SQL Server database. Each row in the database has corresponding buttons added to it. Below is the code used to populate the repeater: SqlConnection connR; string connectionStringR = Configu ...

In order to show the responses underneath, we must first identify the parent comment

Currently, I have two different forms for comments - one is the "parent" comment form and the other is a response form. I am looking for ways to: Capture which response corresponds to which parent comment in the script Maintain the hierarchy of response ...

Is there a way to create a dropdown selection for font families with vue js?

Here is a select element with font families that I want to apply to my texts: <select v-model="focused_font"> <option value="" disabled selected>Font</option> <option v-for="font in available_fonts" ...

Use either Jquery or CSS3 to hide a div if one of its inner divs is empty

I have multiple data sets to display in divs with the same class name. Each div contains two inner divs. <div class="div1"> <div class="div2">Abc</div> <div class="div3"><?php echo $row['SOME VALUE']; ?>< ...

My HTML files are not getting bundled by Webpack

Despite including dependencies for HTML loaders in my Angular 2 application, webpack is not bundling my HTML files along with the rest of the files it generates. I have tried using both "html-loader" and "html-webpack-plugin," but to no avail. My webpack ...

Rearranging anchor tag order with the power of JQuery

Imagine I have five anchor tags <a id = "A" class = "Home">Home</a> <a id = "B" class = "Maps">Maps</a> <a id = "C" class = "Plans">Plans</a> <a id = "D" class = "Community">Community</a> <a id = "E" clas ...

Utilize a component's CSS styles by inheriting them and applying them to another component

I have created custom styles for an object as shown below: form#sign_in{ position:relative; margin:85px auto 50px auto; width:455px; background:#fff; border:#dfdfdf 1px solid; border-radius:5px; -moz-border-radius:5px; -web ...

Combining CSS sprite sheets with optimized HTTP requests makes for faster loading

Quick query about CSS: I have a sprite sheet that I'm trying to utilize from two different classes. The CSS code I am using is as follows: .buttons, .expand:before { background-image: url('images/spriteSheet2.png'); } Later on, I adjus ...

Initiating an audio call exclusively via SimpleWebRTC

I'm currently utilizing a jQuery plugin for WebRTC found here. My goal is to initiate an audio call only, but I am struggling to find a function within the plugin that allows for this. The code snippet I am using with autoRequestMedia set to false is ...

Can solid grid lines be shown using CSS instead of the default dashed grid lines?

Is there a method to achieve consistent and solid grid lines in C3 using CSS without specifying exact line values? For instance, consider C3's basic Grid Line example: var chart = c3.generate({ data: { columns: [ ['sampl ...

What's preventing my link from opening?

I've written this code for two tabs: <li> <a href="#gallery_place" role="tab" data-toggle="tab"> <i class="fa fa-picture-o"></i> <?php _e("Gallery", ET_DOMAIN); ?> </a> </li> <li> <a href ...

The HTMLInputElemet type does not include a Property Rows

Hey there, I'm just starting to dive into Angular and TypeScript. My current challenge is figuring out how to check if a table is empty or not so that I can show or hide a specific div accordingly. I've attempted the following: var rows = docume ...

Tips for generating dynamic scope variables in AngularJS?

I would like to create a screen with select dropdowns and input fields that do not affect each other. Currently, if I select a company, it shows as selected in the next set, which should not happen. How can I implement this? 'use strict'; ang ...

Converting a data type into a CSS format

Currently, I am in the process of creating a table and would like to implement a 4-color scheme randomly selected from a pool of 10 schemes. Below is my CSS/PHP code: <?php header('Content-type: text/css'); // 0 grey $color00 = '#95 ...

Step-by-step guide for making a CSS triangle design that is compatible across different browsers

Here's a common CSS code for creating a CSS triangle: display: inline-block; vertical-align: middle; content: " "; border-right: 4px solid transparent; border-left: 4px solid transparent; border-top: 6px solid black; width: 0; height: 0; Click here ...

Having trouble integrating RGraph into my HTML page with AJAX

As I work on developing a simple webpage layout with both a static header and footer, I'm encountering some challenges in updating content dynamically. The left side menu triggers an ajax request when clicked, which should update the text on the right ...

Ways to include a link/href in HTML using a global constants file

I have a constants file with a links node that I need to integrate into my HTML or TypeScript file. Constants File export const GlobalConstants = { links: { classicAO: '../MicroUIs/' } } I created a public method called backToClassicAO ...

What fate befalls CSS rules left untouched?

Within my style.css file, I have applied rules to almost every component on the website. However, there are exceptions such as the main template and sections displaying requested pages which may contain unique parts not found in other pages, utilizing the ...

Using AngularJS to bind events on key presses

Currently, I am working on an SVG application using AngularJS. We are in the process of making a few adjustments to fully support our internal browser, but so far everything seems to be functioning properly. Feel free to check out my demo: http://jsfiddle ...