Perfectly Positioned Overlay and Text on Top of an Inline SVG Element

Within my inline SVG code, there are circular icons representing different user progress stages, each customized with CSS styling. The SVG contains 5 stages of progress in total and is utilized within an Angular app.

For any active stage, a corresponding circular overlay with some opacity is applied to the respective icon in the SVG along with additional text indicating the stage name. This creates a dynamic effect based on the user's current stage (e.g., stage 3).

The challenge lies in positioning this circular overlay and text accurately regardless of browser resizing. Attempts using <foreignObject> caused proportional issues.

To apply the active stage styles, I pass the current stage value to ng-class in the Angular Directive:

 <customtag ng-class="{
  'stage-one-active': stage_value === 1,
  'stage-two-active': stage_value === 2,
  'stage-three-active': stage_value === 3,
  'stage-four-active': stage_value === 4,
  'stage-five-active': stage_value === 5
  }">
</customtag>

The customtag embeds the inline SVG, triggering the circular overlay and accompanying text for the active stage.

I seek suggestions on effectively layering an overlay and text atop portions of an inline SVG image that retains its position across various screen sizes.

Your valuable input is always appreciated. Thank you.

<svg version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    xml:space="preserve" 
    viewBox="0 0 1120 940">

    <!-- Single Icon Example, with multiples like this -->
    <g class="program-modeling-stage">
        <!-- Overlay and text attempt causing mispositioning -->
        <foreignObject width="200" height="200" requiredExtensions="http://www.w3.org/1999/xhtml">

            <div class="active-stage-overlay"><!-- Circular overlay over entire icon image -->
                <div class="active-stage-text">Current Stage</div><!-- The associated text -->
            </div>
        </foreignObject>
       <!-- End of issue... -->
        <text class="stage-label" x="45" y="290">Business</text>
        <text class="stage-label" x="40" y="320">Development</text>

        <circle class="stage-diagram" cx="92" cy="432" r="87.5" />
        <g>
            <path class="stage-diagram-growth-background" d="M89.4,365,60.82,414.5h62.35L94.6,365A3,3,0,0,0,89.4,365Z" transform="translate(0 -1)" />
            <path class="stage-diagram-program-background" d="M60.82,414.5,32.24,464a3,3,0,0,0,2.6,4.5H149.16a3,3,0,0,0,2.6-4.5l-28.58-49.5Z" transform="translate(0 -1)" />
        </g>
        <path class="stage-diagram-growth-line" d="M92.9,409h18.05a1,1,0,0,0,.82-1.42l-8.21-14.21" transform="translate(0 -1)" />
        <line class="stage-diagram-program-line" x1="42.86" y1="460.48" x2="82.86" y2="460.48" />
        <g>
            <path class="stage-diagram-collective-on" d="M182.5,425.83A90.8,90.8,0,0,0,99.17,342.5" transform="translate(0 -1)" />
            <path class="stage-diagram-collective-on" d="M99.17,523.5a90.57,90.57,0,0,0,83.33-83.09" transform="translate(0 -1)" />
            <path class="stage-diagram-collective-on" d="M1.5,440.17A90.57,90.57,0,0,0,84.59,523.5" transform="translate(0 -1)" />
            <path class="stage-diagram-collective-on" d="M84.59,342.74A90.34,90.34,0,0,0,1.5,425.83" transform="translate(0 -1)" />
        </g>
        
    </g>
</svg>

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

Answer №1

The solution to this issue turned out to be quite straightforward and not as problematic as initially thought (sigh).

By providing a fixed width to the SVG element and utilizing the foreignObject, I managed to maintain consistent positioning by applying CSS classes to the enclosed DIVs with absolute positioning.

The only drawback is that adjustments need to be made for screen sizes below the established fixed width.

#progression-diagram {
  svg {
    width: 600px;
  }
  
  .active-stage-overlay {
    position: absolute;
    width: 110px;
    height: 110px;
    background-color: transparentize($primary-color, 1);
    transition: background-color 700ms ease-in-out;
    border-radius: 50%;
  }

  .active-stage-label {
    fill: $primary-color;
    font-weight: 700;
  }
  
}
<foreignObject x="279" y="566" width="200" height="200">
  <div class="active-stage-overlay">
    <div class="active-stage-label">Current Stage</div>
  </div>
</foreignObject>

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

Is there a way to extract all the `<select>` elements from a table and store them in an array?

I'm having some trouble with the order of my code and the array output. Everything seems to be a bit jumbled up right now and I can't figure out how to add all the rows correctly. $('#clicker').on('click', function(e) { v ...

Securing Your WordPress Custom Form with Captcha

I have a unique form on my WordPress website that tracks IP addresses, checks referer pages, and validates email addresses. Despite these measures, I am still receiving spam subscriptions. I have tried implementing both Bestwebsoft CAPTCHA and really sim ...

The Javascript function call from the <img src="myFunction()"> is malfunctioning

I am looking to dynamically pass the URL of an image using a JavaScript function. <head> <script> function myFunction() { var str1 = "somepictureurl.png"; return str1; } </script> </head> <body> <img src="myFu ...

Can you explain the distinction between data-ng and ng?

I recently came across a discussion about the distinction between ng-* and data-ng-* in AngularJS. Apparently, using data-ng-* ensures that the HTML remains valid. But I can't help but wonder, why is this necessary when I can simply declare the ang ...

Resolving label overlapping issue in Chart.js version 2

I am currently utilizing Chart.js 2 for a project of mine. I've successfully customized the style, but there's one persistent issue that I can't seem to resolve and it's becoming quite frustrating. Occasionally, the last label on the x ...

Transforming the appearance of web elements using jQuery (graphic)

While there are numerous resources on changing CSS with jQuery, I seem to be having trouble getting my image to hide initially and show up when a menu tab is clicked. Any help would be greatly appreciated! ;) h1 { text-align: center; } .Menu { widt ...

Angular front-end rendering with Rails backend integration

Currently, I am working on a medium-sized Rails application and my latest endeavor is to integrate Angular into the system. After reviewing several tutorials, it appears that the most common method for fetching initial data and displaying the first view in ...

Sort with AngularJS: orderBy multiple fields, with just one in reverse

Currently, I am faced with the challenge of filtering data based on two variables: score and name (score first, followed by name). This task involves various games, some of which have scores in reverse order (like golf) while others maintain a normal scor ...

How to dynamically alter a PHP variable using a JavaScript button click on the existing webpage

I've spent the last hour scouring stackoverflow for answers to my problem, but trying out solutions has only resulted in errors - perhaps because I'm attempting to implement it on the same page. I've experimented with saving the value to a ...

Showcase Pictures from a Document

Is there a way to upload an image via an input field and display it? I want to showcase a profile picture that can be saved in a database. The process should be simple for the user, with the ability to easily upload and view the image. function Save() { ...

Strategies for effectively handling browser history in a dynamically loaded JavaScript application

I recently developed a website with two dynamic sidebars - one on the left and one on the right. Both sidebars are configured to load content asynchronously using the .load() function (from leftside.html and rightside.html). The left sidebar contains a m ...

The provider of $modalInstance is currently unknown, leading to an error in the MainController

I'm currently facing an issue with my app's modals when trying to call them using $modalInstance. Despite following the advice from other similar questions I found, such as avoiding the use of ng-controller, my modal still isn't functioning ...

Is there a way to identify the ID of a button using Javascript specifically in Internet Explorer and Safari browsers?

Within my code, there lies a directive that contains the attribute on-blur = blurFunc($event). Imagine this scenario: I interact with a button bearing the id "myButton" located outside of the directive. How can I determine which specific button was clicke ...

Angular: Reacting to events with SVG attributes

Is there a way to access the attribute (e.g. fill) of an SVG object using an Angular event (e.g. mouseenter)? I attempted these different variations but had no success. <rect #rrr [attr.fill]="'green'" (mouseenter)="rrr.fill=&a ...

Integrating a footer into the enhanced search tab slider

I'm struggling to create a sticky footer like the one on w3schools. Even though I used the same code in my material UI demo, it's not functioning properly. I tried debugging by changing the position from fixed to absolute, but it still isn&apos ...

Transfer information to a different html page and store it

Seeking guidance on transferring the entire content of input.html to approve.html for validation and database storage. Any tips or advice would be greatly appreciated as I am new to this and have been struggling with this issue for a week. <form action= ...

Cleaning up HTML5 video content

I have been on the search for a solution that would allow me to "scrub" through HTML5 video. So far, I have not come across one and was considering developing my own. However, before diving into that process, I wanted to seek advice from the community here ...

Error during Heroku deployment: Module './errors/cast' not found

After utilizing the yeoman angular-fullstack generator to create my app, I customized it to suit my needs. The dist folder was built for deployment on Heroku using the command yo angular-fullstack:deploy heroku. This process sets up a new Heroku app for me ...

Using HTML in jQuery or JavaScript: A Step-by-Step Guide

Here's the deal - I've got a bunch of buttons. What I want is, when the 4th button is clicked, to trigger a select menu option like this: The outcome I'm aiming for after clicking the button is I need some guidance on how to incorporate t ...

Conceal elements on smaller screens using the Bootstrap 5 grid system

I'm facing a design issue with my layout - it looks perfect on larger screens but when viewed on mobile devices, the columns stack vertically instead of horizontally. Essentially, I want to hide the first and second last column on small screens and r ...