CSS for Mobile Devices: How to Properly Position Backgrounds

My website has an image named background.jpg that displays correctly on desktop but looks odd on mobile screen sizes. How can I modify my stylesheet.css to reduce the size of the image so it appears similar to how it does on desktop?

Current code:

#services-top-desktop {
    background: #fff url(../img/background.jpg) fixed no-repeat center;
    background-size: cover;
}

#services-top-mobile {
    background: #fff url(../img/background.jpg) no-repeat center;
}

Answer №1

Your website's styling currently employs separate classes for desktop and mobile views. Consider utilizing a universal body class in your CSS file instead.

body {
  background-image: url('../img/background.jpg');
  background-repeat: no-repeat;
  background-size: cover;
}

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

CSS: The height of floating divs is set to 0

I'm attempting to align 2 divs next to each other within another div, creating 2 columns of text with the outer div forming a border around both: HTML <div id="outer"> <div id="left"> ... <div id="right"> </div& ...

What are the best ways to customize exported and slotted components in Svelte?

Is there a similarity between Svelte slots and vanilla-js/dom functionality (I'm having trouble with it). In html/js, I can achieve the following: <style> body {color: red;} /* style exposed part from outside */ my-element::par ...

Enhance npm package by implementing custom functionality with React Component

I have designed an app that bears a striking resemblance to the following code: class MyCustomApp extends React.Component { constructor (props) { super(props) this.state = { tags: [ { id: 1, name: "Oranges" }, { id: 2, ...

Serialization appears to be disabled when utilizing jQuery's load function

One example of loading a div with content from another page is: $("#content").load("<?php echo Config::get('URL'); ?>employment/new_employment" + " #inner_main_content"); The form serialize data is stored in the footer, which is included ...

What prevents me from changing the component's state while inside a useEffect callback?

I have been working on creating a timer that starts running when the app is in the background, and then checks if it has been 15 minutes (for testing purposes, I am using 15 seconds). If the time limit is crossed, the app logs the user out, otherwise, the ...

What is the best way to pass a single object from an array of objects to zingchart?

Imagine I have an array filled with objects structured like this: var sampleArray = [ {difference: "0.000", totalItems: 3}, {difference: "0.001", totalItems: 3}, {difference: "0.002", totalItems: 4}, {difference: "0.003", totalItems: 2}, {difference: "0. ...

Combine JavaScript and CSS in an ASP.NET website, not a web application

I have the following set up: There is a Class named BundleConfig located in the App_Code Folder Imports System.Web.Optimization Public Class BundleConfig Public Shared Sub RegisterBundles(bundles As BundleCollection) bundles.Add(New ScriptBundle( ...

I am experiencing an issue where my React component fails to update properly when viewed in Safari

Everything seemed to be going smoothly. Functioning perfectly in Chrome, FF, Edge, and even IE 11! The main component holds all the state. I send the bets object to the child component which calculates a count to pass to the grandchild component for displ ...

What is the best way to retrieve data from the state in react components?

After fetching data from my API using a getAll call, I stored all the values in this.state. However, I am struggling with extracting the arrays or objects from my state. Specifically, I am interested in retrieving the 'id' field from: 0: {id: 1, ...

The attempt to execute 'removeChild' on 'Node' was unsuccessful because parameter 1 is not the correct type. Although it did remove the elements from the DOM, it only did so once

It's quite a challenge I'm facing!!! Although there have been similar questions asked before, they were all for specific scenarios. I am currently developing a tictactoe game using the module design pattern. The function below helps me create tw ...

Submitting multiple choices and various forms using PHP step-by-step guide

Looking for some guidance on optimizing my HTML/PHP form setup. Here's a breakdown of what I currently have: Form 1: Apple options: -big -medium -small Submit button Form 2: Orange options: -big -medium -small Submit button Ta ...

Determine whether the server request originated from an Ionic mobile application

Currently, we are in the final stages of completing an Ionic project with a PHP backend. To enhance the security of our backend and protect it from external influences, we aim to restrict access to the backend only from within the Ionic project (native app ...

Is it possible for me to utilize the webAudio API in Chrome to connect to the local audio output stream?

Currently, I am working on audio analysis for a visualizer application running on my computer. I am wondering if there is a way to directly access the output audio data stream from the browser? For this project, I am using JavaScript along with the three ...

What is the impact of hash urls on SEO?

Looking for back button support options? Check out some recommended plugins here. However, considering that the page loads via JavaScript based on hash tags, can this impact search indexing by Yahoo/Google/Bing? I am contemplating using HTML5 state push fo ...

Arranging objects in an array based on their specific property

My DataBase collection looks like this: var items = [{ 'Name':'Michael', 'TypeId':1 } { 'Name':'Max', 'TypeId':1 } { 'Name':'Andre', 'TypeId':1 } ...

Experience an endless array of objects

This demonstration showcases the ability to navigate within a group of spheres within specific boundaries. My goal is to explore infinitely among them. What steps should I take to achieve this? ...

What could be causing my Squarespace animation to function properly in Chrome but not in Safari?

I successfully implemented a typewriter animation on my Squarespace website using a Code Block and HTML code. It seems to be functioning well on Google Chrome but is not working on Safari. I recall reading that 'transform' may require additional ...

preventing further executions by halting a function after the initial click

I've come across this function: function display() { $.ajax({ url: "new.php", type: "POST", data: { textval: $("#hil").val(), }, success: function(data) { ...

Creating a mat-grid-list using Angular Material involves adding the necessary dependencies and components

I am encountering an issue while attempting to set up a mat-grid-list with Angular Material. Unfortunately, nothing is displaying on my page. Here is the component info-section : <div class="mat-grid-list" cols="4" rowHeight="1 ...

Utilizing jQuery's .ready() method within the body section of a document to modify the onload event following the printing of the body

Recently, I took over a tabbed page that uses multiple queries to determine which tabs should be displayed. My goal is to add some PHP logic that will automatically set focus on a specific tab when the page finishes loading. I'm wondering if it&apos ...