Guide to modifying the desktop background image using @media

I'm facing an issue with background images on my website. They display fine on mobile, but desktop is proving to be a challenge when attempting to use an @media query for modification.

Here's my current CSS:

body.page-id-6166 { 
  background-image: url(https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_22042019_085055.png);    
  background-repeat: repeat;
  background-size: cover;
}

This setup works for both mobile and desktop, as expected.

However, when I introduce the following code:

@media (max-width: 1920px) and (min-width: 768px) {
  body.page-id-6166 { 
    background-image: url(https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_22042019_085055.png);  
    background-repeat: repeat;
  }
}

Nothing changes as intended.

I even attempted using important, but that didn't work either.

To provide further clarification, although both mobile and desktop versions are the same image, the desktop version only displays a portion of it due to various factors such as landscape orientation. The image also gets enlarged automatically on desktop. On mobile, the original full image is displayed at double size. This is why I need the @media query. You can see this in action on or . The image remains consistent, but on desktop, only a part is selected and appears to be magnified.

Answer №1

The issue lies in the duplication of code on your website, specifically at .

You currently have:

@media (max-width: 1920px) and (min-width: 768px) {
  body.page-id-6166 { 
    background-image: url('https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_22042019_085055.png');       
    background-repeat: repeat;
    background-size: cover;
   }
}

Additionally, you have the same code outside of the media query, rendering the previous code ineffective.

body.page-id-6166 { 
    background-image: url(https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_22042019_085055.png);  
    background-repeat: repeat;
    background-size: cover;
}

Answer №2

Your code is functioning correctly, make sure to test it on screen sizes ranging from 768px to 1920px:

@media (max-width: 1920px) and (min-width: 768px) {
  body.page-id-6166 { 
    background-image:  url('https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_22042019_085055.png');       
    background-repeat: repeat;
    background-size: cover;
   }
}
<body class="page-id-6166">

</body>

Answer №3

After including background-size: contain;

@media (max-width: 1920px) and (min-width: 786px) {body.page-id-1645 {
background-image: url( https://adsler.co.uk/wp-content/uploads/2019/04/FlyerMaker_24042019_164029.png);
background-repeat: repeat;
background-size: contain;}}

This adjustment enhances the visual appeal, especially in conjunction with background-repeat: repeat

(considering my unique style)

The display is still not exactly as desired on mobile devices, but it's an improvement...

A big thank you to everyone for their contributions.

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

Tips for efficiently removing a user as an administrator

Whenever a user logs in or registers, I save their session and cookie information and also add certain details to the database. Login/Register Module (login/register.php) $_SESSION['userid'] = $userid; $selector = base64_encode(random_bytes(9)) ...

Tips on positioning an image to align with a paragraph on the right side

[customized scrollspy example] After removing the padding in the 'about us' section, I am facing an issue where the scrollspy is not aligning properly with the 'about us' content. I need assistance in fixing the scrollspy while ensurin ...

Enhancing the performance of jquery selection speed

I am currently working on a code that manipulates the HTML code of an asp.net treeview. Since this code runs frequently, I need to ensure that it executes with maximum speed. I am interested in expanding my knowledge on jQuery selectors and optimizing th ...

modify the content of a select box using jQuery

Recently, I encountered an issue with a jQuery modal that is retrieving content dynamically through an onClick event and utilizing the data attributes. My goal is to update the text inside a <select></select> element to display a dynamic email ...

How about implementing a 'thumbs up' feature on every post?

I'm relatively new to SQL and PHP and have successfully set up a database where I can input entries through an HTML form. However, I am struggling with implementing a 'like button' feature that will increment a counter for each specific post ...

Consider also scaling in relation to the vertical aspect

.container { width: 250px; height: 250px; resize: both; overflow: auto; border: 1px dashed black; } .child { position: relative; max-width: 300px; max-height: 150px; background-color: blue; color: red; aspect-ratio: 2 / 1; } <div ...

Move the dropdown selection above all DIV elements

Check out this link: Make sure to select an option from the dropdown menu. Also, some of the options are hidden behind other elements. I noticed that if I target .join-form and remove overflow: hidden, the layout of the page becomes distorted. Can anyon ...

Unable to apply inset box-shadow to image

I've added a box-shadow to my image. box-shadow: 0 0 10px RED inset However, the shadow is not showing up on the image. When I use Firebug to change the image path, I can see that the shadow is behind the image. How can I apply the shadow directly ...

Obtain the final segment using PHP from a web address

My URL is: http://domain/fotografo/admin/gallery_bg.php and I am trying to extract only the last part of the URL: gallery_bg.php However, I am looking for a dynamic solution, where the last part of the URL is obtained for each page I visit. ...

How can you determine the current endpoint and sub-endpoint in WooCommerce?

Suppose the URL is: https://example.com/my-account/edit-address/billing https://example.com/my-account/edit-address/shipping I am attempting to determine if the current displayed endpoint is billing or shipping using the is_wc_endpoint_url function. Ho ...

What is the best method for incorporating dynamic page transitions when navigating between individual pages?

Let's say I have the following pages: red.html blue.html green.html My goal is to create links from red.html to blue.html and red.html to green.html. When attempting to use page anchors and iframes, I encountered an issue where scrolling from red.h ...

What is the proper way to invoke the bold feature in AngularJS?

I am looking to update the font properties (bold or italic) within a Textarea using AngularJS. Here is the code snippet for your review. Can anyone guide me on how to implement the bold property in my script? HTML: <div ng-app='myNoteApp' ng ...

CSS: Floating navigation bar that becomes fixed upon reaching the top of the page

Looking for a creative approach to achieve the following: An innovative navigation bar that initially appears on a page regularly but then becomes fixed at the top as I scroll down. An alternative perspective: imagine a navigation bar that starts off unf ...

What is the best way to align a div horizontally within a bootstrap container without sacrificing responsive design principles?

I have been struggling to align the content with the existing container above. The challenge arises as the container is positioned in a row, and I specifically wanted the file directory div on the left side, which naturally pushes the container to the righ ...

What is the method to retrieve the color of a linearGradient in an SVG at a particular

I am working on a unique progress bar that uses a linear gradient and a small ellipse to indicate the completion percentage. The AngularJS binding updates the completion percentage and a function is called. My challenge is to change the color of the ellip ...

Turn off automatic HTML correction in Google Chrome

I'm currently developing a NODE.js app that utilizes Nunjucks as its view engine. To ensure the validity of the HTML being generated, I've implemented tests to check if all tags are properly closed. My approach involves spinning up the applicatio ...

Ways to decrease font size and insert a line break within a constrained input space?

I am facing an issue where the input box remains static with old numbers when it overflows, and newly typed numbers do not appear at all. <!DOCTYPE html> <html> <body> <input type="text" id="output-area" placehold ...

What is the best way to ensure that text moves to the next line if it exceeds the boundaries of the parent div in either CSS or

I am looking to have the "remaining books count" and "remaining pens count text" automatically move to the next line below the numbers when they exceed two digits, causing an overflow in their parent div. Here is the code snippet I currently have: functi ...

Problem with the icon and toggle button in Bootstrap navbar

While working on the collapsible navbar, I encountered an issue with the logo image not being responsive. To address this, I implemented a media query to resize it. However, upon shrinking the screen, I noticed that the toggle button shifted down and the i ...

I need clarification on the following: content:''

I have a question regarding this particular code snippet .store { display: block; position: relative; } .store:before, .store:after { display: block; position:absolute; content:''; } .store:before { background: url(store-before.png); ...