Safari seems to be disregarding the CSS transform-origin property, and setting `transform-box: fill-box` is not

Currently, I am using transform: scale(0.8, 1) to adjust the width of two-digit numbers on a clock face. However, without implementing transform-origin, the numbers do not stay in their correct positions.

The transform-origin that I have set works perfectly on Chrome and Firefox, but unfortunately has no effect on Safari. The desired outcome is shown here:

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

This is how it appears on Safari:

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

I have come across information suggesting that using transform-box: fill-box can resolve this issue with Safari, but in my case it does not seem to make any difference. Some older recommendations involve using the -webkit- prefix, however, this does not help either and should only be relevant for much earlier versions of Safari.

The styling is added via JavaScript since these elements are generated dynamically:

        text2.setAttribute('x', x2.toString());
        text2.setAttribute('y', y2.toString());
        text2.setAttribute('dy', '3.5');
        text2.classList.add('clock-face');
        text2.textContent = h.toString();

        if (h > 9) {
          text2.style.transformBox = 'fill-box';
          text2.style.transform = 'scale(0.8, 1)';
          text2.style.transformOrigin = [10, 19, 28][h - 10] + '%';
        }

I have also attempted to address the issue through stylesheet enforcement, but have had no success:

.clock-face {
  font-family: $clock-face-font;
  font-size: 10px;
  letter-spacing: -0.05em;
  text-anchor: middle;
  fill: white;
  transform-box: fill-box !important;
  user-select: none;
}

All other styles are being applied correctly, so it does not seem like CSS is completely disregarded. The Web Inspector confirms that transform-box has been implemented:

https://i.sstatic.net/5QI05.png

If anyone has suggestions on how to resolve this issue, they would be greatly appreciated.

Answer №1

While it may not be the most optimal solution, I found a workaround for the issue with transform-origin. Instead, I decided to use the dx attribute and it ended up working seamlessly with Safari and all other major browsers.

        if (h > 9) {
          text2.style.transform = 'scale(0.8, 1)';
          text2.setAttribute('dx', ['4', '8', '12.5'][h - 10]);
        }

Answer №2

At this moment, while crafting this response, the ongoing problem persists with Safari version 16.1. Despite functioning adequately on Chrome and Firefox, transform-box: fill-box fails to be implemented on Safari. It seems that the user-agent is overriding these styles for me. One potential workaround could involve utilizing transform-origin, but it may seem a bit excessive.

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

Modify the div class depending on the date

I am in the process of creating a simple webpage where I can keep track of all my pending assignments for college. Take a look at the code snippet below: <div class="assignment"> <div class="itemt green">DUE: 28/03/2014</div> </d ...

Can a JavaScript function be used with images to operate across multiple elements?

How can I make a function work on multiple elements? let image = document.getElementById("opacityLink"); image.onmouseover = function() { image.style = "opacity:0.9"; }; image.onmouseout = function() { image.style = "opacity:1"; }; <div class=" ...

Using JSON in HTML pages

As a novice in JSON and JQuery languages, I am looking to incorporate the currency rates API into my HTML code. Can anyone offer assistance? I have been working on this project for over a week now without any progress. The API link is: ...

Interact with a modal element using puppeteer

I'm having trouble clicking on the email login button inside a modal using Puppeteer for automation. The code is not able to find the modal element. Can someone assist me in debugging this issue? const puppeteer = require('puppeteer'); ( ...

How come the variable is not being passed to the HTML article within the function?

I'm struggling to pass a variable from a function to an article. Despite successfully displaying the variable in an alert box, I can't seem to get it to show up in the article content. What am I missing? After confirming that "a" contains the co ...

Prevent sticky div from overlapping with footer

I currently have a social link menu that is fixed to the left side of my page, structured like this: <footer id="colophon"></footer> <div> <nav> <ul id="social"> <li>Link1</li> ...

Is there a way to add a border around a div that extends beyond the div, similar to what

I'm attempting to create a border around this section, as seen in the image. However, I'm unsure of how to move it a few pixels outside of the main box. Here is what I've tried so far, but it's not quite achieving the desired result. H ...

Ways to display an HTML code by utilizing the onclick() function through PHP?

I have a button that looks like this: <input type="submit" name="submit5" class="btn" value="Add Date" onclick="create_date_field()" /> Every time the button is clicked, I want to append the following code inside the <tr> tags. It should be po ...

What is the best way to acquire an ID that is generated dynamically?

Being new to javascript and ajax, I am facing a challenge. I have a while loop with 2 buttons, both of which seem to function correctly, except for one small issue... The product-id is only being passed for the first or last element in the loop. How can I ...

Adjust the position of the hover background and font downwards

I am experiencing an issue with the hover effect on my navigation bar. When I hover over the different elements in the nav bar, the text and background appear to be moved up slightly and are not aligned with the nav bar. Here is a screenshot: https://i.s ...

Having an issue with my Typescript code that is throwing a "Uncaught ReferenceError: angular is not defined" error

I am currently in the early stages of learning typescript with angularjs through online video tutorials. I have encountered an issue while attempting to include the angular module in my "app.ts" file, which serves as the main file in the backend. Below is ...

Searching the JSON file by its value using Waterline

I am struggling with locating model instances based on the nested address attribute in one of my models. attributes: { address: { type: 'json' } } I have attempted various queries to find model instances located in the same city: Model ...

Looking for assistance with automatically restructuring the HTML code of Facebook messages?

Looking for assistance in sorting messages within Facebook Messenger HTML by date in descending order. Can anyone provide guidance on writing the necessary JavaScript for this task? Providing a dummy version of the Facebook message HTML as I cannot share ...

Creating a div overlay triggered by the addition of a child tag

Using the Paypal zoid feature, I have a button that opens an iframe in the parent div when clicked. However, the iframe causes the other contents of the website to shift around, making it look messy. I'm wondering if there is a way to make the parent ...

Initiating an AJAX request to communicate with a Node.js server

Recently, I started exploring NodeJS and decided to utilize the npm spotcrime package for retrieving crime data based on user input location through an ajax call triggered by a button click. The npm documentation provides the following code snippet for usi ...

Making Bootstrap Carousel images slide seamlessly

Can someone help me with implementing Bootstrap carousel slides that display gif short clips when transitioning to the next page? I've searched through Bootstrap documentation and Stack Overflow for solutions, but I can't seem to get the slide to ...

Tips for styling Ajax.ActionLink elements with CSS

Hi there, I'm trying to style a navigation bar using CSS. I'm pulling the navigation bar values from a database using Ajax.ActionLink. I attempted to use JavaScript but encountered an error stating "jQuery is not defined", Here's the cod ...

A guide on successfully handling errors while utilizing S3.getsignedurlpromise() in node.js

I am faced with a challenge in my project involving a node.js server that downloads images from an s3 bucket and serves them to a React client. The issue arises when the wrong file key is sent to the S3 client, as I want to handle this error gracefully by ...

NextJS is like the master of ceremonies in the world of backend

As I was searching for the top JS backend frameworks, I came across NextJS which is considered to be one of the best. Initially, I thought NextJS was just a simplified version of CRA and still required Node.js as the backend. This brought me back to my c ...

Stop Bootstrap Modal from Showing on Mobile Devices

I am struggling to find a solution to prevent the Bootstrap modal from appearing on mobile and tablet devices. Currently, the modal only shows up for IE9 and below as a way to alert users about limitations when using such outdated browsers. Despite attemp ...