When the browser is dragged, the background image starts to overlap the following section

I am currently working on making my webpage mobile-friendly, or what is commonly referred to as mobile-compatible. One issue I am facing with my page is that it appears fine at a specific size, but when I resize the browser window, the background image overlaps the "Services" title within the <section> element.

If you want to take a look at the jsFiddle for this issue, you can access it here: http://jsfiddle.net/eg18dfy0/4/. Please note that due to limitations, local files are not included in this link.

Normal view:

After resizing:

Here is an excerpt from my code:

HTML snippet that matters:

<header>
  <div class="background_image">
  </div>
  <div class="welcome-text-container">
    <div class="row">
      <div class="welcome-text1">Welcome!</div>
      <div class="welcome-text2">BE GOOFY, TAKE A PICTURE!</div>
      <div class="btn-row">
        <a href="#services" class="welcome-btn btn-lg">TELL ME MORE</a>
      </div>
    </div>
  </div>
</header>

<!-- services -->
<section id="services">
  <div class="container">
    <div class="service-title">Services</div>
    <div class="service-caption">What we'll do for you</div>
  </div>
</section>

CSS:

.background_image {
    background-image: image-url("header-bg.jpg");
    background-size: contain;
    background-repeat: no-repeat;
    width: 100%;
    height: 0;
    padding-top: 66.64%; 
    position: absolute;
    /* (img-height / img-width * width) */
    /* (853 / 1280 * 100) */
}

/* Services */

#services {
    padding-top: 110px;
    margin-top: 75px;
}

.service-title {
    text-align: center;
    font-size: 55px;
    font-weight: 700;
}

.service-caption {
    text-align: center;
    font-size: 20px;
}

Answer №1

If you're facing a similar issue, this solution might help:

Check out this Fiddle for the fix

The problem arises when setting a background image in a div that has a higher stacking priority due to document flow, causing it to overlap other divs.

To resolve this, I included the following CSS code:

.container > div.background-image {
    z-index: 1;
}

.container > div {
    position: relative;
    z-index: 2;
}

While there are more efficient ways to address this issue (such as avoiding a separate div for the background image), implementing these changes should fix your problem without needing major alterations to the document structure.

I must credit for providing the placeholder image used in this context. It's incredibly useful for tackling CSS challenges on platforms like StackOverflow.

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

Searching for the value of a JavaScript variable in a PHP DOMDocument

How can I retrieve a JavaScript value in PHP using the DOM? $dom = new DOMDocument(); $html ='<html> <body>Hello <b id="test">Hello World</b>.</body> <script> document.getElementById('test').innerHTML = ...

How can we ensure that the width of the td element matches the width of the input element using only CSS or

I have attempted to inquire about this question before but did not receive any helpful responses, so I am trying again in the hopes that someone can assist me. My desired outcome is as follows: The table should stretch to 100% The first input element sh ...

Retrieve the student ID from the URL parameters and display all records with the matching ID

I am trying to display all rows with the same id using $_GET['student_id'], but I am encountering an error with Datatables. Here is my code. When I get the id from the URL, for example: example.com/example.php?=2222 All rows with the id 2222 wil ...

Invoking a function without specifying its parent function when nested within another function

I need to execute an anonymous function within another function without actually calling the parent function, as it will lead to errors. Here is the parent function: function onloadCallback() { grecaptcha.render("recaptchaHolder", { "size": "invisi ...

How to incorporate a routing file within another routing file in Node.js

I have structured my routes as follows: / /business /business/stuff1 /business/stuff2 /business/admin For /business, I am using a separate file for the routing and functions. And similarly, for /business/admin, I also want to use a separate file f ...

Using async/await with recursion in NodeJS for handling express requests

My code contains a function named GetAllData() that triggers the GetPurchaseData function, which in turn calls itself recursively until all the data is loaded. async function GetAllData(){ console.log("starting loading purchase data"); await G ...

The issue arises with the Google Map marker failing to function correctly when pulling data

I've recently started learning Google Maps. It's interesting that markers work and are displayed when statically declared, but not when retrieved from a database. // var markers = [[15.054419, 120.664785, 'Device1'], [15.048203, 120.69 ...

Displaying the chosen array in a Material UI Table within a React application does not show the desired checkboxes

After days of hard work and research, I finally figured out how to achieve what I needed. In my React App, I have a Material UI table that I want to load with pre-rendered checks in the DOM based on entries in a selected array. The selected array contains ...

Discovering the total of elements within any given JavaScript array

I have a complex array structure and I am looking for a way to calculate the sum of all numbers without using Array.isArray method: let arr = [[1, 2, 3, [4, 5, [6, 7]]], [8, [9, 10]]]; An ideal solution would transform the array like this: let arr = [[1, ...

What is the best way to execute a function based on the width of the screen?

Two functions need to be called based on the screen width. Here is one attempt: var winWidth = $(window).width(); var sections = function() { $('.image').each(function(){ var $this = $(this), x = $this.find('img'). ...

Encase the event handler within JQuery

Here's an example of inputs with OnBlur event handlers: <input name="abc" tabIndex="5" class="datetime" onblur="if (CheckMode(this))__doPostBack('abc',''); else return false;" /> Now, in JQuery Form ready function, I want ...

What is the best way to deactivate buttons with AngularJS?

I have a situation where I need to disable the save button in one function and permanently disable both the save as draft and save buttons in another function using AngularJS. How can I accomplish this task with the disable functionality in AngularJS? Her ...

Develop a hierarchical structure component in React for organizing directories

I've been delving into creating a music player with electron and decided to experiment with react, but I'm encountering difficulties when it comes to generating a directory tree. Currently, I am utilizing readdirp to retrieve directories recursi ...

The authentication method "discord" is not recognized

Currently, I am working on implementing discord authentication using passport. Originally, everything was functioning correctly, but now it seems to have encountered an issue which I cannot identify. auth.js const express = require('express') co ...

Unable to utilize relative path in CSS

I currently have a CSS file located at /opt/ion/node/service/public. The file, cc.css, needs to be relocated to /opt/ion/node/service/views/pages. However, I am facing issues with this relocation process. Whenever I hit the server, it continues to point t ...

Style your list items with custom CSS for paragraph links

It's strange because the last time I tried to apply the same styling, it worked perfectly. However, now it's not working. Here is a snippet of my HTML: <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" ...

Retrieve all checkboxes that have been altered using jQuery

There are numerous checkboxes on my page, each in a separate cell. My goal is to retrieve the checkboxes that have been altered from their original state. The original value is stored in an attribute named "data-original-value" within a span that encloses ...

Rotating a Three.js sphere to a custom position

With the use of Three.js, I have a globe with attached sprites representing volcano points. When I rotate the globe, the sprites remain in their designated positions because they are grouped with the sphere. Now, I am looking to implement a feature where ...

Discovering the position of digits within a string using Javascript

Could someone help me find the positions of the numbers (1994 and 27) within this string? I attempted to split the string but I'm unsure about how to proceed from there. let str = 'year of birth: 1994, and i'm 27 yo' ...

Utilizing variables in Angular service to make API calls

Currently, I am working on accessing the Google Books API. Initially, I was able to directly access it in my controller but now I want to follow best practices by moving the business logic into a directive. HTML <form ng-submit="search(data)"> < ...