The benefits of utilizing "native tags" instead of foreignObject in an SVG

As the creator of the stackoverflow-readme-profile project, I dedicated extensive time and effort to crafting a personalized Stackoverflow profile in the form of an SVG image. Utilizing "native svg tags," I meticulously constructed elements such as:

<svg version="1.1" baseProfile="full" width="300" height="86" viewBox="0 0 300 86" preserveAspectRatio="xMinYMin meet" xmlns="http://www.w3.org/2000/svg" style="overflow: visible;">
  <rect width="300" height="80" rx="5" ry="5" fill="orange"></rect> 
  <rect width="140" height="40" x="10" y="20" fill="yellow"></rect> 
  <rect width="140" height="40" x="150" y="20" fill="blue"></rect> 
</svg>

JSFiddle

Additionally, by incorporating the <foreignObject> tag, I explored the use of convenient CSS properties such as flexbox for alignment:

<svg version="1.1" baseProfile="full" width="300" height="86" viewBox="0 0 300 86" preserveAspectRatio="xMinYMin meet" xmlns="http://www.w3.org/2000/svg" style="overflow: visible;">
  <foreignObject width="300" height="80">
    <div style="width: 100%; height:100%; border-radius: 5px; background: orange; display: flex; padding: 20px 10px; box-sizing: border-box;">
      <div style="width: 100%; background: yellow;"></div>
      <div style="width: 100%; background: blue;"></div>
    </div>
  </foreignObject>
</svg>

JSFiddle

This raises the question: is there a significant advantage to using "native" SVG, or was my time investment ultimately misplaced?

Answer №1

Why not make use of both options when needed? For situations where text needs to be placed freely like tooltips, the foreignObject is the way to go. However, when it comes to aligning text with shapes and paths in SVG for graphic labels and legends, using foreignObject may not be the best approach.

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

Issues encountered when trying to implement a Navbar drop-down menu using Angular in conjunction with Bootstrap 4

I'm currently working on a web application using Angular 5 and Bootstrap 4, and I've encountered issues with the navigation menu bar dropdowns. Despite following the guidelines provided in the official documentation here, I can't seem to get ...

How can I position two bootstrap tables side by side based on their columns

Currently, I am utilizing bootstrap and Laravel form control to generate the table structures below. The one issue I am encountering is figuring out how to align the delete and edit buttons from two separate tables. Here is a snapshot of the current layout ...

What is the process for resetting a JQueryUI effect animation?

I'm facing an issue with two timer bars that each wind down over a 5-second period. When I try to stop and reset the first timer, it simply continues from where it left off instead of resetting. The desired behavior is as follows: Timer1 starts User ...

When you hover over an image, both the image's opacity and the color of the title beneath it change. However, if the title expands to two lines, it messes up

I am currently working on a project where I have an image and a title displayed below the image. My goal is to change the color of the text when hovering over the image, as well as adjust the opacity of the image. Additionally, when hovering over the title ...

New and improved Bootstrap 5 menu bar

I am seeking to customize my navigation bar by adding a black background that spans its entire length. I do not want to rearrange the links or logo; just apply a background color. Another issue arises during SASS compilation: I am trying to change the col ...

The presence of a Bootstrap addon is resulting in horizontal scrolling on mobile devices within the webpage

I am encountering a peculiar issue with an input-group in my cshtml file which features a Bootstrap addon. The problem arises on mobile devices, where upon focusing on the input field, the page scrolls horizontally to the right, revealing the right margin ...

Incorporate a dropdown menu based on the selection made in another dropdown menu

I have a scenario on my website where I want to dynamically add select boxes based on the value selected in the previous one. Here is the code snippet: <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"> </script> & ...

Customizing existing Mui classes through the use of makeStyles

Recently, I made a small change in my approach to styling by moving CSS directly into my component files using styled components, emotion, and make styles. This decision was driven by the benefits of easier management and improved development experience. A ...

Tips for designing a horseshoe-inspired meter using CSS

  I want to create a horseshoe-shaped gauge using CSS that resembles the image below:     My attempt involved creating a circle and cutting off the bottom, similar to the technique demonstrated in this fiddle: http://jsfiddle.net/Fz3Ln/12/   Here& ...

Exclude the HTML attribute prior to displaying

Is there a way to prevent the src attribute from being used for each img tag until after a certain action is completed? I am trying to modify how images are fetched. Here's what I tried: $('img').each(function() { var elem = $(this); ...

Discovering and interacting with an SVG class using Selenium in Python

I am facing difficulties in finding the svg class element that allows me to navigate to the next page on the website and create a list of all the pages. Despite my efforts, the element seems too complex for me to locate. I have tried using XPATH and follow ...

Resize the shape of an image's polygon

Is there a way to independently scale a specific polygon of an image on hover? For example, I have a world map and I would like to enlarge a country when hovering over it, then return it to its original size when no longer hovering. I am familiar with us ...

Tips for maintaining the nested collapsible table row within the main table row in a React MUI table

I am working on implementing a Material UI (MUI) table that includes collapsible table rows. The challenge I am facing is maintaining consistent border and background colors across all the rows, even when some are collapsed. Currently, the separate rows ar ...

Avoiding the occurrence of extra space due to the p tag for paragraphs

I'm currently using the following <p> tag but it's creating a gap between the tick mark and the text that follows after the closing </p> <p class="tick">✓</p> Post messages to friends all over the world. CSS: .tick { ...

Issues with implementing Bootstrap tabs in Vue application

Currently, I am in the process of developing an application using vue, vue-router, and bootstrap. My goal is to integrate tags in bootstrap as shown below: <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a class="nav-l ...

Modifying the TITLE dynamically post header insertion: A guide

Is there a way to dynamically change the title of an HTML page based on the content included below the header section using PHP? For example: <html> <header><title>I would like to change</title></header> <!--CONTENT--> ...

Utilizing CSS filters to add a blur effect to specific elements within an SVG

I've been attempting to use the CSS filter blur on certain elements, but for some reason it's not working as expected. Check out this example in a jsfiddle: http://jsfiddle.net/kuyraypj/ Even though I have applied the following CSS, my '.b ...

Include a border around the entire tooltip

I'm having trouble adding a border to my tooltip that follows the outer lines of the entire tooltip. Currently, I've only been able to add a border to the upper part of the tooltip, which overlaps with the arrow section and isn't the desired ...

Identifying text within clicked divs using identical ids

$(document).ready(function(){ $('#peoplelayer').click(function(){ $(this).fadeOut(500); var str = $(this).text(); alert(str); }); }); This is code where I use the same id "#peoplelayer" for all the divs. When on ...

The PDF file cannot be displayed due to the dynamic loading of the path and filename

Currently, I am working on an AngularJS and Java application. The following HTML code is utilized to open a PDF file in the browser. However, there seems to be an issue where the PDF does not open when dynamically passing the value for the data attribute. ...