Inconsistencies with text centering in SVG between Firefox and Chrome

Upon inspection, I discovered the following SVG content:

<svg height="64" width="64" class="ng-star-inserted">
  <rect rx="10" ry="10" style="fill:silver;stroke:black;stroke-width:5;opacity:0.5" x="0" y="0" height="64" width="64">
  </rect>
  <text alignment-baseline="middle" text-anchor="middle" x="50%" y="50%">
 missing 
  </text>
</svg>

This code essentially creates a grey box with some centered text. However, when placed in a Bootstrap 4 structure next to an input field of type file, the centering of the text within the SVG seems to vary across different browsers.

The complete code snippet is as follows:

<li class="media">
  <div class="mr-3">
    <svg height="64" width="64" class="ng-star-inserted">
      <rect rx="10" ry="10" style="fill:silver;stroke:black;stroke-width:5;opacity:0.5" x="0" y="0" height="64" width="64">
      </rect>
      <text alignment-baseline="middle" text-anchor="middle" x="50%" y="50%">
     missing 
      </text>
    </svg>
  </div>
  <div class="media-body">
    <h5 class="mt-0 mb-1">{{getLabel()}}</h5>
    <input class="form-control-file" type="file" type="file" >
  </div>
</li>

It appears that the text "missing" is not perfectly centered - it is slightly offset to the left (in Firefox) just above the expected center. Adjusting the alignment from 50% to 32px works better for Chrome but in Firefox, ideally, it should be set at 34px. It seems like Firefox calculates the position based on the entire row height rather than the starting point of the image.

Referring to the screenshot provided https://i.sstatic.net/LDwNn.png,

Changing the alignment-baseline="middle" to center, hanging, or baseline did not resolve the issue either.

Is there a way to resolve this discrepancy so that the rendering is consistent across both browsers?

Answer №1

To improve your code, include the attribute dominant-baseline="middle" as shown below:

 <text alignment-baseline="middle" dominant-baseline="middle" text- 
    anchor="middle" x="50%" y="50%">
     missing 
 </text>

For more information, check out the documentation.

Feel free to view the original source on CodePen, where it was tested on both Chrome and Firefox.

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

"Enhance Your Website with Custom jQuery Preloaders

Currently, I am facing a challenge while developing a website. Specifically, I am struggling with resolving the issue of a blank page being displayed. The website that I am working on involves functionality where swiping right triggers data insertion into ...

Having trouble with the login form that utilizes PHP and MySQL?

After spending a few hours on it, I am struggling to make this code work. Essentially, I have a bookings page where users enter their details. I set the account password as the phone number for simplicity. After booking, their details are added to a table ...

Expanding an element to cover all columns in a grid with automatically generated columns

I am working on a CSS grid layout with automatic columns and 2 rows. All elements are normally placed in the first row except for one special element that should span both rows while filling all available column space. My current code looks like this: ...

Is there a way to remove characters from a textbox one at a time?

When collecting user input, such as a telephone number, the HTML code would look something like this: HTML: <input id="number_input" type="text" size="12" maxlength="19" /> To handle this input using JavaScript: var i = 0; var phone_number = []; ...

Unable to eliminate the unwanted space at the top of the division

I am encountering an issue where I have a div containing a label, but there seems to be some unwanted space above the div that I can't seem to remove. It's puzzling me as to why this space is appearing. Query: What could be causing the space ab ...

Create a design where the logo seems to be suspended from the navigation bar using bootstrap

My goal is to achieve a navigation bar similar to the one shown in this image: Using Bootstrap 3, the code below is what I have implemented for my navigation: <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <di ...

Embracing right-to-left (RTL) languages

I am looking to create a website that can support both left-to-right (LTR) and right-to-left (RTL) languages seamlessly. My goal is to have the text direction switch automatically to RTL if the content is in an RTL language. Additionally, I want the input ...

Implementing universal styles to injected HTML (v-html)

I am facing an issue while injecting HTML content from my database using Vue. The problem is that although I can successfully inject the HTML, the framework stylesheet (Vuetify) does not seem to be applied to the injected content. The rest of the page ha ...

Responsive HTML table with full width of 100%

I am attempting to make an HTML table responsive by setting the two td elements to occupy 100% width on smaller screens. This is what I have so far... .test1{ background:teal; text-align:center; padding:20px; } .test2 { background:tan; paddin ...

Get the QR code canvas image with a customized background by downloading it

I am having trouble with downloading a QR code canvas image with a background. The download works fine, but my device is unable to scan the code properly due to an incomplete border. I need to add a white background behind it to make it larger. Current im ...

Firefox does not support responsive tables, while Chrome does

Firstly, let's take a look at this Fiddle by resizing in Firefox and Chrome. I also attempted to troubleshoot the issue mentioned here: Why do Firefox and Opera ignore max-width inside of display: table-cell?, but unfortunately had no success. table ...

The vertical overflow feature does not seem to be functioning correctly with the

In the following HTML setup: <div id="container"> <header></header> <div id="content"> <div class="something"></div> <div class="lateralInfo"> <div class="menu"></div> < ...

Managing and authenticating HTML checkboxes using Spring MVC controller

Currently working with Spring MVC and designing a user registration page. I want to provide users with the choice to opt-in for email notifications and agree to Terms of Service before signing up. Due to using Thymeleaf as my templating engine, I am facing ...

Troubleshooting: Twitter Bootstrap dropdown feature experiencing issues within navigation bar

I am facing an issue with getting the bootstrap dropdown to function properly. I have tested it on my mobile device and noticed that the menu does not drop down as expected. Here is a DEMO Below is the code snippet: <nav class="navbar navbar-inverse ...

Can you tell me what is creating the space between the elements in this form?

For an example, take a look at this link: I am puzzled by the gap between the form-group and the button, as well as between the different form-groups. When using Bootstrap 4 with flexbox activated, all my elements (inputs and buttons) collapse without any ...

HTML tags are appearing in the content edit section on Drupal 7

I recently used a tutorial from a Drupal book to develop a custom compound field. However, when I try to edit content with this field, the HTML tags defined in the module for the custom field are visible. Here is the code: And here is the output: I woul ...

Generate a responsive list with a pop-up feature under each item (using Vue.js)

Currently, I believe that Vue may not be necessary since most tasks can be done using JavaScript and CSS. I am attempting to design a list layout as follows: [A] [B] [C] [D] When an item is clicked, the information about that specific item should ...

Implementing a Bootstrap 4 modal in Webpack 2

Utilizing only the bootstrap modal functionality, I manually included the required libs (modal.js & util.js) in the vendor section of webpack.config.js If I directly add the vendor.js file, everything works fine. However, since it is bundled, I prefer ...

Essential Flex Layout - Bottom Section and Main Content?

I am trying to create a layout that includes content and a footer using flexbox. The goal is to have the content fill up any remaining space, while the footer remains a fixed height of 60px. What would be the most effective approach to achieve this? < ...

jQuery AJAX - Unauthorized Access Error Code 403 Caused by CORS Issues

Attempting to replicate the following function, which is sourced from immowelt.de. The js-file can be found at . Replicated Function: a.ajax({ type: "POST", url: IwAG.Vars.acSource ? IwAG.Vars.acSource : j, contentType: "appl ...