The background-size property behaves differently on Safari compared to Chrome - it breaks in Safari but

I am currently working on an app that is temporarily hosted here.

After testing in Chrome, everything seems to be functioning correctly. However, when I switch to Safari, the background image fails to display.

The relevant code looks fairly simple:

<html>
  <head>
    <link rel="apple-touch-icon" href="_images/favicon.png">
    <script type="text/javascript" src="arc.js"></script>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/javascript" src="bundle.js"></script>
    <style>
      body{
        background-image: url('_images/background.png');
        background-size: cover;
      }
    </style>
  </body>
</html> 

It seems like a straightforward property according to the documentation found here:

https://css-tricks.com/almanac/properties/b/background-size/

I have managed to get Safari to work by removing the line:

background-size: cover;

However, this does not provide me with the desired effect of covering the background entirely.

Further testing indicates that using the value "contain" also causes issues.

Even setting a specific value like 400px results in the same problem. It appears that Safari may not accept any values for this property.

Answer №1

It seems like the issue may not be related to background-size:cover, as this property is fully supported on Safari according to Mozilla Developer Network. Rather, it appears to be a problem with your web server sending images with an incorrect content-type. In my console, all images are displayed as txt, which differs from other websites.

https://i.sstatic.net/RGux0.png

For reference, I am using a similar setup with a Macbook Air, Safari, and macOS High Sierra 10.13.6.

Answer №2

Give this code a shot: background-size: 100% 100%;. Keep in mind that it may cause the background image to appear distorted on certain browsers such as Chrome.

If you're still having trouble, consider using a workaround by identifying the user agent through server-side scripting and creating CSS specifically for this issue within the <head> section of your website.

Answer №3

I encountered a similar problem, but after several attempts to resolve it from both sides, I decided to utilize the calc() property.

Here's how you can do it: Begin by obtaining the image dimensions in your Chrome browser through inspection with the devTool or if you have preset the width and height of the image, follow these steps:

Initially, set the height: ;, then define the width using the calc() property as follows: width: calc(675px + (730.16 - 675) * (100vw - 1200px) / (1365 - 1200));

The initial width of 675px will be calculated leading up to the final width of 730.5px.

Specify the starting screen width of 1200px where you want the image to scale, and the end width of 1365px for the desired scaling.

Essentially, this setup is akin to utilizing @media (min-width: 1200px) and (max-width: 1365px). Remember to stick with one unit throughout, as demonstrated here.

In this case, I suggest sticking to px when working with calc(). If you've used a different unit like %, simply inspect that dimension and incorporate it into the calc() function.

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

Make sure the div can grow in height as needed, but if it reaches the limit of its container, it

UPDATE: I've created a JSFiddle for testing purposes. Below is an example of what I aspire to achieve (with Bootstrap 4 rows and columns): https://i.sstatic.net/hfXno.png The page should only display scrollbars if the second row is fully compress ...

Modify the background position in CSS several times

Hi there! I'm looking to create a hover effect where the thumbnail of a video file is previewed, similar to how it's done on www.megavideo.com. However, I'd like to achieve this using a sprite file instead. For example, my thumbnail image is ...

Is it normal not to see </head> and <body> tags in the page source code?

Looking at the source code of the page, you'll find something like this: <link rel="stylesheet" href="http://..."> <!-- analytics --> <script> ... Make sure the closing </head> tag and the opening <body> tag are positio ...

Tips for effectively showcasing div elements

https://jsfiddle.net/qz8hL574/1/ for (var key in table) { if (table.hasOwnProperty(key)) { $('<div class="element"></div>').appendTo('#list'); document.getElementsByClassName("element")[key].innerHTML = ...

What is the reason for this only functioning with the "!important" declaration?

Can anyone help me troubleshoot this code? It seems to only work with the !important rule, which I prefer not to use. I believe there must be a way to achieve the desired outcome without relying on it. What's intriguing is that the CSS line in questi ...

"Navigating back to the previous screen in Ionic 2 - A step-by-step guide

When using Ionic q, we can go back to the previous screen with $ionichistory.goback(). However, in Ionic 2, how can we achieve the same functionality? I have tried using a button with a click event to print a console message but it is not working. <ion ...

Initial space in model variable not being displayed

Hey there, I am working with a model variable called "name" that is linked to a span element like this: <input type="text" ng-model="name"> <span ng-bind="name"></span> My goal is to display the text entered in the input field without r ...

Does the height of the rendered font adjust based on the length of words in Japanese formatting?

I can't figure out why this strange issue is occurring... It seems that the font "size" (or rather, the height it occupies) changes depending on the length of a word. I tried to reproduce this in English without success, but it consistently happens w ...

Issue with PHP incorrectly encoding JSON when writing to a file

I encountered a problem while working on this task. I used preg_split in PHP to create an array. However, my challenge now is converting it into JSON format. Despite trying several methods, the resulting code appears poorly written and does not seem to be ...

Prevent certain images from loading by blocking them

I am trying to create an extension that blocks two specific images from loading. Initially, I attempted to achieve this by using the following code in the content.js file: $("#rated-image").remove(); //id of one image $(".blur-mask").remove(); //class of ...

Using JQuery to nest a header tag within a div element

Having trouble adding a header to a div element. The h1 tag just shows 'loading' and I'm not sure why. <div data-role="page" id="addviewtask"> <div id="header" data-role="header" data-theme="a" data-position="fixed"> ...

Is there a way to tally the checked mat-radio-buttons in Angular?

I am seeking a way to determine the number of radio buttons checked in a form so I can save that number and transfer it to a progress bar. <mat-radio-group name="clientID" [(ngModel)]="model.clientID"> <mat-radio-button *ngFor="let n of CONST ...

Retrieve the price of a span element based on the selected radio button using jQuery

I have a span with the class .amount, and now I want to extract the price from that span. $('.dimension-layer-dimension').click(function() { // Here is my JavaScript attempt var price4 = $(this).find('radio:checked').data(&apo ...

Django Template Syntax error: Unable to pass the remaining part

I recently started working on a Django project and I'm still learning the ins and outs of the Django framework. Upon running the application with python3 manage.py runserver, an error has popped up showing django.template.exceptions.TemplateSyntaxErro ...

Oops! Looks like there was an error: weight is not defined when trying to calculate BMI with the HTMLButtonElement

I'm currently working on a project to create a BMI calculator following specific instructions. I've managed to follow all the guidelines except one regarding the letsCalculateBMI function. The instruction states: letsCalculateBMI should extrac ...

The jQuery scroll functionality is malfunctioning

Could you please assist me in resolving an issue with my scroll effects not working? I have been unable to pinpoint the problem. The code snippet I am using is based on Bootstrap 4. Below is the code snippet in question: //SCROLL EFFECT $(".nav-link" ...

Customize images using React JS to add an overlay on top of an HTML img

I'm looking to achieve a similar effect to Facebook where hovering over an image tag triggers a little overlay asking if you want to edit the photo. I have the hover functionality working, but I'm unsure how to implement the overlay. The image is ...

How can I show a dropdown menu in React.js?

I am currently developing an application using reactjs and incorporating the reactstrap css framework from Bootstrap. My goal is to create a navbar with menu and sub-menu functionality, restricted to just one level of sub-menus. View Working Demo My aim ...

Issue with margin-top not meeting set expectations

To assist in providing assistance, I have put together a quick jsfiddle project. I am curious why the use of margin-top for #container causes the entire body to be pushed down from html, rather than just pushing #container away from #containerWrapper. Th ...

Tips on displaying text inside an icon

As a self-taught newcomer to web development, I apologize if this is a basic question. I'm trying to figure out how to display text inside an icon, like putting a number inside a heart. Would using a webfont icon not be suitable for this purpose? Is ...