Ways to make a background stretch infinitely in the x-axis

Currently, my header has a grey background with a width of 100% and a maximum width of 1000px. To extend the grey background beyond the 1000px limit, I have a separate div with an absolute position behind the header div. The issue arises when the user scrolls horizontally, causing the grey background to only extend as wide as the browser window, leaving the rest of the area with a white background. Is there a way to make the grey background span the full width of the screen, even with horizontal scrolling?

For a visual representation of the issue, please refer to this JSFiddle: https://jsfiddle.net/mb1brnma/1/

The content within the fiddle may appear disorganized, but it mirrors the problem of the background not extending fully to the right when scrolling.

Update:

HTML:

    <div id="footerTopBG"></div>
    <div id="footerBG"></div>

<body>
<div id="footer-container">
    <div id="footer-holder">
        <footer>  
            <section id="mid">
                <div align=left class="box">
                    <h5>Customer Care</h5>
                    <ul>
                        <li><a href="/pages/Return-Policy.html">Return Policy</a></li>
                       ...

CSS:

    footer {
    width: 100%;
    max-width:900px;
    min-width:770px;
    float: left;
    height:310px;
    background: linear-gradient(to bottom, #9b9b9b 61.2%,#414141 61.2%); 
}
...

Answer №1

Upon reviewing your fiddle, it appears that the issue is not with the background color not extending to 100% of the page width, but rather that the elements in your footer collectively exceed 100% width. To resolve this, you have two options: A) assign the background color to a parent element that encompasses all its children, or B) make the element with the background color wider than the page width to extend beyond its bounds.

Option 1: You can set the background color on the wrapper element and ensure that its min-width encompasses all contents with minimal scrolling. Adjust the min-width value based on your design considerations.

#footer-container {
  background-color: #9b9b9b;
  min-width: 900px;
  overflow-x: auto;
}

Option 2: Another approach is to create a pseudo-element behind the footer that extends beyond the right edge, effectively making the background wider than 100%.

#footer-container {
  background-color: #9b9b9b;
}
#footer-container::after {
  content: '';
  display: block;
  background-color: #9b9b9b;
  width: 793px; /* Adjust based on design */
  height: 492px; /* Adjust based on design */
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
}

Option 3: For a responsive design approach, consider eliminating unnecessary styles, positioning rules, and implementing media queries for better adaptability across different screen sizes.

footer {
  width: 100%;
  max-width: 900px;
}
footer #mid {
  width: 96%;
  margin: 2%;
  max-width: 900px;
}
footer #mid .box {
  float: left;
  width: 25%;
}
#footer-container {
  background-color: #9b9b9b;
}
@media all and (max-width: 620px) {
  footer #mid .box:nth-child(odd) {
    clear: left;
  }  
  footer #mid .box {
    width: 48%;
  }
}

These options provide solutions to ensure the background color extends to the full width of the page based on different approaches. Adjustments may be needed based on your specific design requirements. Feel free to explore the provided fiddle link for a live demonstration of the concepts.

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 is the best way to incorporate one Div within another Div using JavaScript?

I have a single main div with an id, and I am looking to insert 4 additional child divs inside it. Each of these child divs will then contain 5 more divs each. The code snippet that I currently have is as follows: $( document ).ready(function() { for( ...

What is the best method for verifying that audio has not been loaded correctly?

After creating a script to scrape for mp3 audio file URLs and load them into my HTML audio element's src, I encountered an issue where some of the URLs were not functioning properly. As a result, the audio was unable to execute the load() method since ...

Tips for merging two classes in CSS

Within my code, I have two classes named classA and classB. I am looking to have classB inherit the style of classA while still only using classB. .classA{ width:100px;} .classB{ height:100px;} <div class="classB"></div> ...

What is the rationale behind placing the CSS outside of the React function components, near the imports?

Recently, I encountered an issue with loading CSS inside a React function component using Material UI. Even though I managed to resolve it, I am still intrigued by the underlying reason. Initially, I had something like this setup where I placed both makeSt ...

Extract the text content from an HTML file while ignoring the tags to get the substring

Hello, I am a newcomer to the world of Web Development. I have an HTML document that serves as my resume, formatted in HTML. For example: html <p>Mobile: 12345678891 E-mail: <a href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Tips for preventing elements from wrapping in a lengthy list and using scrollbars in Firefox

When dealing with a lengthy flex list, the items (buttons) should wrap when there is not enough space available (using flex-wrap). However, an issue arises in Firefox where the items are wrapped once a scrollbar appears, even if there is ample space. In c ...

Guide to swapping images on button click in HTML with dynamically changing image URLs retrieved from the server

I am a beginner in client-side scripting and new to Stack Overflow. I am looking for guidance on how to change an image within a div element upon clicking a button or anchor tag. Here is the code snippet I have written to achieve this: $scope.captchaCha ...

Creating a Striking Multi-Layered CSS Header

Can someone help me figure out how to add horizontal lines behind the words in this header? Here is what I have so far: https://i.sstatic.net/dN7s4.jpg. However, I want to achieve something similar to this design: https://i.sstatic.net/FZoSF.jpg. You can v ...

Update email address depending on the option chosen from the dropdown menu

My contact form includes the following fields: Name Email Number Department Message The "Department" field is a drop-down selection with seven options: Audio Engineering Graphic Design Music Production Photography Videography Web Development Other I ...

Adjusting the grid for various mobile screen sizes

I am currently working on designing a user interface (UI) for mobile screens that includes a header, grid, and buttons. I want the UI to look consistent across all mobile devices. Here are screenshots from various mobile screens: Samsung S5 Pixel 2 XL I ...

What is preventing my h1 styles from being applied to an h1 element within a <section> tag?

I have a headline in my header and in another part of the content. I've been told that this can impact SEO, but I'm just starting out by copying other people's pages and trying to replicate their styles without looking at their code. The st ...

Is there a way to synchronize breakpoint values across different media queries?

Currently utilizing Next.js version 9.53. Utilizing the built-in CSS module support provided by Next.js without the use of CSS pre-processors (less, sass, etc.) or CSS-in-JS (styled-components, etc.). Presently, my approach involves writing CSS in a mobi ...

Issues with Adding Dynamic Rows to MySQL

Struggling with adding dynamic rows and posting to MySQL. The variables seem off, but the script works fine. Need help with MYSQL posting specifically. As a beginner, I seek your forgiveness... The Script is running smoothly! <script type='text/ ...

Difficulty arises with z-index when hover effects are applied to clip-path shapes

I'm encountering an issue where I am attempting to make two clip path polygons overlap each other when hovered over by the mouse. I have been using z-index values and trying to adjust them based on which overlay is being hovered over, but unfortunatel ...

Exploring the wonders of Html5 Canvas with base64 encoded images

I have a base64 encoded image that looks like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCA...... Is there a way to draw this on a canvas using the encoded image provided above? Does anyone have an example of how to do this? Updated: ...

Show content based on information from an array using JavaScript

I am currently working on developing a user-friendly step-by-step form using AngularJS and UI-router to navigate through different sections. The data collected from each form is stored in a JavaScript array, and I am trying to dynamically show or hide a di ...

Modify the div's visibility based on selected option in the dropdown menu

In my PHP file, I have the following codes: <section id="placeOrder"> <h2>Place order</h2> Your details Customer Type: <select name="customerType"> <option value="">Customer Type?</option> <option value="ret ...

Designing Interactive Circular Dates on Website

Currently, I am working on a webpage using HTML, CSS, JavaScript, and PHP. The goal is to design a page that features 7 circles representing the current date and the next 6 days. Users should be able to click an arrow to navigate to the following 7 days. ...

Submitting form based on HTML select input issue

I am facing an issue with a select form where the value resets to "10" every time I send the form. Is there a way to keep the selected option, for example "20", after submitting the form? Below is the code snippet: <form method='get' name=&a ...

Do designers often manually adjust elements using media queries when working with Bootstrap?

Is it common practice to directly invoke media queries in order to manually adjust the layout of elements when using Bootstrap? In other words, if I have a custom element that I need to display or position in a specific way, is it acceptable to call the m ...