Resolving Discrepancies in SVG Rendering on MacOS between iOS and Chrome

I am trying to create a title that adjusts its size based on the screen width without breaking into multiple lines. I am currently using an SVG technique to achieve this effect.

Here is the code snippet:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>StackOverflowExample</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
        type="text/css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
        integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Muli" rel="stylesheet">
    <script src="https://code.iconify.design/1/1.0.6/iconify.min.js"></script>

</head>

<style>
text {
  font-family: 'Muli';
  font-weight: 600;
  fill: white;
}

svg {
  width: 100%;
}
a {
  color: white;
}
body {
  background-image: linear-gradient(180deg, rgba(35, 50, 64, 0.91) 61.95%, rgba(0, 0, 0, 0.51) 94.56%),
  /* height: 100vh; */
  width: 100vw;
  background-color: black;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  font-family: 'Muli';
  color: #ffffff;

  min-height: 100vh;
  display: flex;
  align-items: center;
}
</style>

<body class="text-center">
    <div class="container">

        <div class="row">
            <div class="col-12">
                <svg viewBox="0 0 167 20">
                    <text x="0" y="15">This is a Test Of This T</text>
                </svg>
            </div>

        </div>

    </div>
</body>
</html>

The title resizing works perfectly in Chrome, but it cuts off the last letter on iOS. See screenshots below:

iOS: https://i.sstatic.net/Q8QOo.png

Chrome: https://i.sstatic.net/JWbJr.png

Any suggestions on how to make it display correctly on both browsers and operating systems? The intended text is "This is a test of This T". Despite adjusting the viewbox parameters, I can't find a solution that caters to both platforms.

Answer №1

Finally figured it out! Just a heads up for anyone facing the same issue in the future...

To solve the problem, simply add textLength="167px", where 167 corresponds to your viewbox size, and that should resolve the disparity in spacing rendering between iOS and MacOS systems. By defining a fixed text length, it ensures a more consistent rendering, ultimately resolving the issue.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>StackOverflowExample</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
        type="text/css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
        integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Muli" rel="stylesheet">
    <script src="https://code.iconify.design/1/1.0.6/iconify.min.js"></script>

</head>

<style>
text {
  font-family: 'Muli';
  font-weight: 600;
  fill: white;
}

svg {
  width: 100%;
}
a {
  color: white;
}
body {
  background-image: linear-gradient(180deg, rgba(35, 50, 64, 0.91) 61.95%, rgba(0, 0, 0, 0.51) 94.56%),
  /* height: 100vh; */
  width: 100vw;
  background-color: black;
  background-position: center;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  font-family: 'Muli';
  color: #ffffff;

  min-height: 100vh;
  display: flex;
  align-items: center;
}
</style>

<body class="text-center">
    <div class="container">

        <div class="row">
            <div class="col-12">
                <svg viewBox="0 0 167 20">
                    <text x="0" y="15" textLength="167px">This is a Test Of This T</text>
                </svg>
            </div>

        </div>

    </div>
</body>
</html>

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

Flexbox not achieving equal height

Having trouble making flexbox work with Susy? Here's what I've tried so far. I've experimented with various solutions found here, but couldn't get it to work consistently across different screen sizes. The heights of text containers an ...

Function for triggering character or camera movement upon the pressing of a button

Just starting out here with web coding and I'm trying to create a function that moves my game character when a button is pressed. The idea is to change a boolean value to "true" when the button is pressed down so that the character moves. I've at ...

What is the specific character code assigned to the "Enter" key on a

Check out this code snippet: http://jsfiddle.net/YttKb/ In my javascript, I am trying to add a new line of text using utf-8 coding. Which character should I use to make a new line? It seems like \n only creates a line break, not a new line of text. ...

Is it possible to trigger a submit button to perform a POST request and an AJAX call simultaneously

I have a form that sends a POST request to show_aht2.php, but I also need it to trigger an AJAX call as shown in the code below. How can I achieve this without redirecting the user to another page? I want the user to remain on map.php. Thank you in advanc ...

Server unable to start and error message shown on command prompt

I am having trouble opening the webpage from the code hosted on Github. When I try to run the server, I encounter errors that are displayed in the command prompt as shown below: Code link: https://github.com/mschwarzmueller/nodejs-basics-tutorial/tree/mas ...

Issue with PHP Form data not syncing with MySQL Database

I have been attempting to create a form and upload it into my database, but unfortunately, it is not functioning properly. Here is the HTML code I am using: <form name="Form-Request" method="post" action ="icn/form.php"> <div> ...

Combining Applet with Microsoft Access

This is a more specific version of my original inquiry. I have successfully created an applet that should interact with my MS Access database. It runs smoothly through a compiler, but when I embed the .class file in an html page and open it, the applet run ...

Mega Dropdown Menu using CSS

I am currently working on a dynamic mega drop-down menu using only HTML and CSS. The issue I'm facing is that when I select one of the list items (LIs), it expands in size at the expense of the other LIs. I'm not sure where the problem lies, so ...

Adjusting (css styles like top, left, and width) for an external occurrence within fullcalendar

$scope.ctrlstartDragging = function(id) { var book = document.getElementById(id); var domRect = book.getBoundingClientRect(); book.style.position = 'fixed'; book.style.top = domRect.top + & ...

I require the slideshow div to smoothly move elements down as it transitions between slides

I'm facing an issue with a jquery slideshow that contains quotes of varying lengths. The problem is, the longer quotes overlap with the content below them. I'm trying to figure out how to make the longer quotes push the rest of the page down, avo ...

Exploring the world of HTML and Javascript to enhance user search functionality

When I type in the search form, JavaScript is returning an error: "Uncaught TypeError: Cannot read property 'innerText' of null". I am working on a page with Bootstrap cards and trying to filter them by name. I attempted to access the "card-titl ...

Ways to implement a personalized button in place of jquery ui buttons

Is there a way to replace the standard jQuery dialog buttons with custom images? I have created new buttons in Photoshop with a .png extension and would like to use them instead of the default dialog buttons. I think this can be done through CSS, but if y ...

Steps for activating mouse dragging in a div that supports drag and drop functionality

I have a div containing multiple elements, and I need the ability to drag and drop the entire div with the attribute draggable=true. However, one of the elements in the div is a bar graph that allows users to select a specific range by dragging their mouse ...

What is the best way to align div elements in HTML5?

I've spent countless hours trying to properly display and align multiple divs. Despite extensive research, I just can't seem to get it right. What I'm aiming for is to have the title of a section in the top left corner, an info box to the l ...

Steps for Embedding an HTML Page into a Tab using jQuery

Within the tab labeled class=plots-tabs-heatmap, I am attempting to insert a new page using the code below. However, instead of seeing tmpdata/page2.html displayed on the tab, nothing appears. $('#plots-tabs-heatmap').html("tmpdata/page2.html"); ...

The ng-repeat directive in my Angular app's div element is being displayed as a comment

After spending several days searching, I have yet to find a solution for my issue. It seems to be specific to the code I'm working with in Angular 1.6. I apologize for the format of my post, as this is my first time seeking help on stack overflow ...

Steps for positioning the navigation bar beneath header 1

In my HTML code, here is a link to an image: https://i.sstatic.net/zhj7o.jpg I have successfully completed the sections associated with this image: https://i.sstatic.net/wIE6N.png However, I'm facing an issue now. I am unable t ...

Unlocking two features with just a single tap

I am currently working on a website for a kiosk, where the site transitions like a photoslide between each section. To achieve this effect, I have added a layover/mask on the initial page. The layover/mask is removed using a mouse click function. This is ...

Dynamic gallery with customizable features (HTML/CSS)

Seeking guidance on creating a seamless html/css gallery without any spacing between each gallery element. All elements are identical in size, housed as list items within a ul inside a div. Media queries have been established to adjust site and image siz ...

HTML5/CSS breadcrumb libraries

Can anyone recommend a library that offers custom breadcrumbs like the ones shown in this image: https://i.sstatic.net/aJAoN.png I'm looking for something that can replicate the styling of the image provided. Any suggestions? ...