Tips for adjusting the size of an SVG using percentages

I have multiple tables with data in them, each sized using percentage and resizable. I want to add SVG images to each table without affecting the table size. When I tried setting the sizing like this:

<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="23.8345mm" height="100%" version="1.1" 
     style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; 
     fill-rule:evenodd; clip-rule:evenodd" viewBox="0 0 100% 100%" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="Layer_x0020_1">
        <metadata id="CorelCorpID_0Corel-Layer"/>
        <rect class="fil0 str0" x="5%" y="5%" width="100%" height="100%"/>
        <rect class="fil0 str0" x="5%" y="5%" width="100%" height="100%"/>
    </g>
</svg>

Although it made the SVG smaller, it was not resizable along with the table. I need the SVG to change size when the user resizes the table.

Here is the fiddle link for reference: https://jsfiddle.net/vaxobasilidze/1oe8w8wm/12/

The SVG should remain a fixed size while allowing the table to resize. The desired outcome can be seen in the second table of the fiddle. How can I correctly set the percentage?

EDIT: Here is another fiddle demonstrating the issue: https://jsfiddle.net/vaxobasilidze/qu20vxcx/3/. What am I doing wrong?

.channels {
  /*border-collapse: collapse;*/
  border-spacing: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-weight: bold;
  border: 1px solid rgba(30, 30, 30, 1);
  border-radius: 4px;
  overflow: hidden;
  background: url(images/comment-bg3.png) repeat;
  resize: both;
}

.channels td {
  border-left: 1px solid rgba(30, 30, 30, 1);
}

... (CSS code continues, too lengthy to display here)

</table>

Answer №1

The dimensions of your SVG are currently determined by the width and height attributes.

width="23.8345mm" height="216.59mm"

If you want the SVG to scale according to its parent container, consider removing the width and height attributes or setting them both to "100%" using CSS.

By doing this, the size of the SVG will be limited by the width of the table cell, which is 2/7 (from colspans) of 476px.

<table style="width: 476px;..." />

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

What is the best way to adjust the placement of this object so it is anchored to the left side?

https://i.sstatic.net/k8aF1.png I'm struggling to position one of my divs more to the left within a flex container. No matter what I try, changing the class of the div doesn't seem to have any effect. Here's the code snippet: import React f ...

Rotation feature is not functioning on Three.js Trackball zoom, however zoom is working

As the title suggests, I am having trouble with trackerballcontrols. I am expecting it to work similar to this example, where I can rotate the camera but for some reason, I can only zoom in and out. Of course, I would like to be able to rotate the camera. ...

Error in MongooseJS Route Error: Strange Casting Issue

I'm currently working on the backend and facing an issue with a specific route intended to return an array of IDs from the database for lazy loading purposes. The route is set up as follows: router.get('/list', (req, res) => { Inside ...

Verification - enter a unique key for each ajax call

As I develop a new app, I am aiming to separate the HTML/JS layer from the PHP layer in order to prepare for a potential phonegap version in the future. One major concern I have is regarding authentication. Since I won't be able to rely on session va ...

Encountering issues with website optimization on Google Page Speed Insights and facing compatibility problems on a specific website I designed

I attempted to analyze the performance of my website using Google Page Speed Insights and encountered an error message. I have tried looking for a solution without success. Interestingly, when I tested other websites that I manage, everything worked just ...

Using VueJS to dynamically manipulate URL parameters with v-model

Hello, I am new to coding. I am working on calling an API where I need to adjust parts of the querystring for different results. To explain briefly: <template> <div> <input type="text" v-model="param" /> ...

Can node.js be used to extract slides from PowerPoint and convert them into images?

We are currently in the process of creating a new application that utilizes sailsjs (node + mongo) as its backend system. Our client has requested a specific feature where users can upload *.ppt files and potentially extract all slides to save them as ima ...

Is it acceptable to include the bundled main.js file in the gitignore for a HUGO project?

Is it possible to exclude the bundled main.js file from a HUGO project by adding it to .gitignore? ...

Ways to choose an identifier larger than

Currently, I am in the process of creating a news system for a website. For this project, I referred to a tutorial on building a news system which can be found here: To showcase the news articles, I have implemented the following code snippet: if(!$_GET[ ...

What is the best way to ensure that two objects collide with one another?

Issue Description I am currently working on implementing collision detection for two objects. The goal is to determine if the objects are intersecting by calculating their bounding boxes with Box3 and using the .intersectsBox() function to obtain a boolea ...

The React useState hook is not functioning as anticipated

I am having an issue with my useState hook that manages the state of selected checkboxes. The selected checkboxes should be instantly displayed in the UI within my filter, but currently they are only shown when the filter component is closed and reopened. ...

access the content of a div element by its class attribute

Within the div element, a value has been set and I am attempting to retrieve this value using its class. However, the code below does not return the desired value. What mistake am I making here? How can I resolve this issue? <div title="Find on Amazo ...

Unable to locate the required conditional template for the 'mdRadioButton' directive due to the absence of the 'mdRadioGroup' controller

I am currently working on developing a custom directive that will help me display questions within a survey. Given the multiple types of questions I have, I decided to create a single directive and dynamically change its template based on the type of quest ...

Execute the function when the element comes into view

Is there a way to create a function that will automatically attach itself to an element when it comes into view? I have multiple elements on my page - element1, element2, and element3. Instead of using a large if statement, I would like to write a functio ...

Progress Circles on Canvas in FireFox

Currently, I am experimenting with this codepen demo that utilizes canvas to generate progress circles: The functionality functions perfectly in Chrome and Safari; however, it only displays black circles in FireFox. My knowledge of canvas is limited, so I ...

Menu is not functioning properly as it is not staying fixed in place

I am trying to create a fixed menu that sticks to the browser window as it scrolls. However, I am encountering an issue where the transition from sticky to fixed is not smooth when I remove position: relative; from navbar__box. window.onscroll = functio ...

Adjust alterations in a Vue Component to apply to separate routes

I have a Filter tab component that I use in various routes. When I click on a tab, it becomes active. After clicking on one tab, I want it to remain active in other routes as well. How can I achieve this? Any suggestions or articles would be greatly apprec ...

Placing a div over a JavaScript element

Is it feasible to overlay a div(1) with a background image on top of another div(2) that contains JavaScript (like Google maps API v3)? I have experimented with z-index without success, and I am unable to utilize absolute positioning because I depend on t ...

Limit the character input in AngularJS/Ionic to a specific number

I have a text input field that needs to restrict the user from entering more than a specific number of characters. Let's say I only want the user to type 10 characters, and if they try to enter more, the text field should not accept it. It should stop ...

How to transform a nested string into a JSON object using JavaScript

I am trying to manipulate a nested query string in JavaScript. The string looks like this: var str = "( ( Sentence starts with any of null AND Sentence starts with any of null ) AND Sentence starts with any of null )" I want to split the string at the &a ...