The SVG element seems to be invisible on the screen, but it is clearly visible when added in the

Having an issue with the visibility of an SVG code. The SVG element with id "nestedsvg" is being appended in the HTML and can be seen in the console, but it's not showing on the screen. Tried adjusting z-index to 99 but still no luck. Any ideas on what might be causing this?

<svg data="BusinessRoleFigure" x="144" y="95" 
width="128" height="66" id="outer" style="position: relative;">

<rect x="0" y="0" width="100%" height="100%" 
stroke="rgb(178,178,126)" stroke-width="1" fill="rgb(255,255,181)"
style="position: relative;"></rect>

<svg id="nestedsvg" x="100%" height="100" width="50">
<rect x="-50" rx="5" ry="5" width="20" height="10" stroke="black"
stroke-width="1" fill="black" z-index="99"></rect>
 </svg>

 <circle cx="118" cy="13" r="5" fill="none" 
stroke-linejoin="round" stroke="black" 
z-index="1" stroke-width="1"></circle>

 </svg>

Jsfiddle: http://jsfiddle.net/MxHPq/145/

Answer №1

The reason for this issue is that the rectangle being drawn is outside of the nested SVG viewport.

The SVG has a width and height of 100x50, while the rectangle being drawn is 20x10 at (-50,0). This means the rectangle covers the area from (-50,0) to (-30,10), making it invisible as objects outside the nested SVG viewport are not visible by default.

There are two ways to resolve this:

  1. Make objects outside the viewport visible by setting overflow="visible" on the nested SVG element.

<svg data="BusinessRoleFigure" x="144" y="95" width="128" height="66" id="outer">
  <rect x="0" y="0" width="100%" height="100%" stroke="rgb(178,178,126)" stroke-width="1" fill="rgb(255,255,181)"></rect>
  <svg id="nestedsvg" x="100%" height="100" width="50" overflow="visible">
    <rect x="-50" rx="5" ry="5" width="20" height="10" stroke="black" stroke-width="1" fill="black"></rect>
  </svg>
  <circle cx="118" cy="13" r="5" fill="none" stroke-linejoin="round" stroke="black" stroke-width="1"></circle>
</svg>

  1. Reposition the rectangle inside the SVG viewport and adjust the SVG position accordingly.

    If you choose this solution, you'll need to change the x="100%" value of the nested SVG element.

<svg data="BusinessRoleFigure" width="128" height="66" id="outer">
  <rect x="0" y="0" width="100%" height="100%" stroke="rgb(178,178,126)" stroke-width="1" fill="rgb(255,255,181)"></rect>
  <svg id="nestedsvg" x="78" height="100" width="50">
    <rect x="0" rx="5" ry="5" width="20" height="10" stroke="black" stroke-width="1" fill="black"></rect>
  </svg>
  <circle cx="118" cy="13" r="5" fill="none" stroke-linejoin="round" stroke="black" stroke-width="1"></circle>
</svg>

Additional points regarding your original SVG:

  1. The x and y coordinates on the root <svg> element do not have any impact.
  2. Currently, z-index does not hold significance in SVGs, but this might change with the upcoming SVG2 standard.
  3. The use of position: relative has no effect on SVG elements.

I have eliminated these components from the revised examples provided.

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

Looking for assistance in implementing Chart.js within a modal popup

Here's a Chart-generated diagram: <div class="diagram"> <canvas id="pie" class="chart chart-pie" width="150" height="150" data="ModalObj.FunctionalTest" labels="labels" colours="Colours"> </canvas> This is a directive: .directive( ...

Why is the appsecret_proof invalid?

Currently, I am in the process of developing a new application. I am utilizing the Javascript API for logging in (v2.4) and the latest version of the PHP API (v5). To test the functionality of my app, I have created a Test App. With the Javascript API, I h ...

Sending an attribute to the Treeselect Vue component from a Laravel view

I want to encapsulate Vue-Treeselect link: within its own custom vue component. This way, I can easily use something like <tree-select></tree-select> in a Laravel view file where needed. However, the challenge I'm facing is figuring out ...

Edit in bulk: Execute a JavaScript function to remove a row, then delete based on a specific condition

Assignment on developing an Asp.net web page application. Check out the demo here Click to add a new record The "Delete" link will show up in the new row - it would be great if there is an X icon for consistency I need to click the "Delete" link, trigg ...

Highlighting table rows when hovering in IE with JQuery - compatibility across all versions

I have a table on my jsp page with multiple rows and columns. I want to ensure that visitors can easily follow along when they interact with the table - by highlighting the row or column they hover over with a different background color. Although the **hov ...

Learn the effective way to customize the primary button text color in Bootstrap 4 using SCSS styling

Looking to customize the .btn-primary text color. I attempted to modify the background color in _variables.scss by adding the following line: $primary: #a1c1b6; However, I was unable to change the text color despite trying various options. // not working ...

The checkbox saves all options collectively into the database, rather than individually storing each one

At the moment, my checkbox values are saved as ["A","B","C"] in the database even when I only select one option (e.g. C). I also have a question - is there a way to store it as ABC instead? $(document).ready(function() { "use strict"; var role; }); ...

.submit fails to function when the bound object has been updated via an ajax call

I managed to implement an AJAX commenting system where, upon clicking the Post Comment button, an ajax call is made instead of submitting the form traditionally. Everything was working smoothly until I tried refreshing the page with the comment submit butt ...

What is the best way to display items using Typeahead.js in combination with the Bloodhound engine?

I am struggling to showcase a collection of items using typeahead with a JSON file as the data source. Unfortunately, none of my information is appearing on the screen. My objective is to list the names and utilize the other attributes for different purpo ...

javascript conceal other sections upon hovering

There are 4 list items (<li>) that I want to use as triggers for linked images. In this project, I am using vanilla JavaScript as jQuery is not allowed. Below is the code snippet: var children = document.querySelectorAll('#resistorContent > ...

Is it possible to use both material-ui@next and the previous version concurrently?

I need some advice on a project I am working on that utilizes material-ui@next (v1). While I appreciate the new features in the latest autocomplete, I find it too complex for my needs. Instead, I would like to revert back to the older version of the autoco ...

Having trouble rendering retrieved data on the webpage using React JS

I am facing an issue with displaying fetched data on my page. I have implemented ReactJS for the frontend and NodeJS for the backend, with data storage being handled by blockchain technology (specifically hyperledger fabric). Frontend: ReactJS, import Rea ...

Presenting the user's city in their browser by utilizing the freegeoip.net API with jQuery, through the seamless combination of AJAX and JSONP

I am uncertain about fully grasping the question, which reads as follows: Your task is to use JavaScript or jQuery, along with AJAX and JSONP, to display the user's city in their web browser by utilizing the freegeoip.net API. Hint: Utilize the endpo ...

Looking for assistance with positioning elements in CSS?

Just starting out with CSS design and looking to create a page similar to the example below. I've managed to separate the images using a span attribute, but I'm struggling with aligning the text and button in a single row. This is what I have s ...

Tips for making content vanish or remain concealed behind a see-through header during page scrolling

I made a JavaScript fiddle http://jsfiddle.net/claireC/8SUmn/ showcasing a fixed transparent header. As I scroll, the text scrolls up behind it. How can I make the text disappear or be hidden behind the transparent div when scrolling? Edit: I should also ...

Utilizing Firebase Cloud Firestore: A guide to programmatically handling indexes

Transitioning from Firebase Realtime Database to Cloud Firestore has presented some challenges in implementing "complex" queries across collections. Despite this, I am determined to make it work. My current setup involves using Express JS and Firebase Adm ...

organize a data set using react's hook system

Trying to sort an array using react hooks but the state is not updating. Any help on what could be going wrong? import React, { useState } from "react"; import ReactDOM from "react-dom"; import "./styles.css"; const dogs = [{ name: "fido", age: 22 }, ...

Using jQuery to redirect a page based on the IP address of the visitor

I am looking to implement Jquery code on the index page of www.propertyhere.com The aim is to redirect visitors based on their geographical IP location to specific pages: if the user's IP is from AU: http://www.propertyhere.com/Country/AU/search-t ...

Pythonanywhere is throwing a NOREVERSEMATCH error when accessing /blog, whereas the localhost is functioning flawlessly

PythonAnywhere is encountering an issue with NOREVERSEMATCH at the /blog location, but it functions perfectly fine on localhost. I have taken the steps to resave the project, committed it to GitHub again, and pulled it on PythonAnywhere. Despite these eff ...

The alignment of floating elements will be off

I am looking to ensure that each element is the same size and properly aligned. Currently, elements with fewer total weeks appear lower due to spacing issues as shown in the image below. https://i.sstatic.net/EytLu.png While I can add phantom rows to fix ...