Changing the CSS property in an external SVG image to customize its appearance

I currently have an assortment of html and svg files that include:

home.html

<html>
<head>
  <style>
   span {
    filter: invert(100%)
   }
  </style
</head>
<body>
  <span><img src="my.svg" /></span>
  <div><img src="my.svg" /></div>
</body>
</html>

my.svg

<svg version="1.1"
 baseProfile="full"
 width="36" height="36"
 xmlns="http://www.w3.org/2000/svg">

  <rect width="100%" height="100%" fill="red" />

</svg>

Currently, the two rectangles are displaying as one light blue and one red as expected. Is there a way to maintain the red color of both images by only updating the .svg code? Unfortunately, I am restricted from making changes to the code within the hosting html page for my image.

Answer №1

It is not possible to achieve your desired outcome without making changes to the HTML code.

Once the SVG has been loaded and displayed, it lacks the ability to influence any CSS effects that may be added to it by the webpage.

Answer №2

It's a mysterious phenomenon - give red, get cyan; give cyan, get red. Who knew colors could be so unpredictable?

<svg version="1.1"
baseProfile="full"
width="36" height="36"
xmlns="http://www.w3.org/2000/svg">

<rect width="100%" height="100%" fill="#00FFFF" />

</svg>

Answer №3

The issue seems to be related to the style tag provided in home.html. Try updating it to look like this...

<html>
<head>

</head>
<body>
  <span><img src="my.svg" /></span>
  <div><img src="my.svg" /></div>
</body>
</html>

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

Show the components of an associative array with a click of a button

I have a total of four div elements and array elements. My goal is to link these two components together effectively. Specifically, when a user clicks on the first div element with the class .news, I want to display the values of the first element in the ...

Extend the center of the image horizontally

Is there a way to horizontally stretch only the middle section of an image? Let's say I have this specific image: https://i.sstatic.net/pty5A.jpg (source: lawrenceinspections.com) I need the rounded corners to remain unchanged, so simply stretchi ...

is it possible to adjust the height of a tableRow in mui?

I recently created a table component using Mui. I've been attempting to adjust the height of the tableRows, but so far I haven't had any success. Below is my code snippet: import React, { memo } from "react"; import { ActionItemType, ...

Exploring the Contrasts: AppBar vs Toolbar in MUI v5

Can you explain the variations between AppBar and Toolbar in MUI? I know that AppBar defaults to 'column' flex direction, while Toolbar defaults to 'row'. Are there any other distinctions? Additionally, why do MUI docs show examples of ...

Why is the defaultDate property not functioning properly in Material-UI's <DatePicker/> component with ReactJS?

I recently implemented the <DatePicker/> component from Material-UI ( http://www.material-ui.com/#/components/date-picker ) in my project. I encountered an issue while trying to set the defaultDate property to the current date on my computer, as it r ...

Unable to insert HTML code into a div upon clicking an image button

I am in the process of developing a website dedicated to radio streams, and I was advised to utilize Jquery and AJAX for loading HTML files into a div upon button click. This way, users wouldn't have to load an entirely new page for each radio stream. ...

Using JQuery to modify several background images in unison

I have a CSS code that uses 8 images to create a frame: background-image: url(images/blue/tl.png), url(images/blue/tr.png), url(images/blue/bl.png), url(images/blue/br.png), url(images/blue/t.png),url(images/blue/b.png),url(images/blue/l.png),url(images/b ...

Design HTML dropdown menu

I have a sleek menu design with rounded buttons, and I am looking to extend the same style to the dropdown list. I have experimented with various approaches but there are two specific issues that I need assistance with: 1. Achieving rounded corners simil ...

Efficiently shrink column width in Material-UI's <TableRow/> using ReactJS and Material-UI

At the moment, I am utilizing ReactJS along with Material-UI. One issue I am encountering is that when using Material-UI's <Table>, the columns' width are automatically set based on content which results in all columns having equal width. H ...

Styling with CSS to show an image and text on the same line

I would like to show text and image on the same line, with the image slightly above the text. View Demo html img.del { display: inline-block; float: right; cursor: pointer; margin-right: 74% } .astext { text-align: left; margin-le ...

When there is no value in the input, the function will not be triggered

I need some assistance with my website development project. I want to implement a feature where, if the user enters input but doesn't submit anything, instead of triggering the function togglePopup(), a different function called togglePopup2() will be ...

Emphasize the designated drop zone in Dragula

Incorporating the Dragula package into my Angular 2 project has greatly enhanced the drag-and-drop functionality. Bundling this feature has been a seamless experience. Visit the ng2-dragula GitHub page for more information. Although the drag-and-drop fun ...

Tips for eliminating white frames or borders on the Mapbox canvas map

In my current project using Angular 10, I have integrated Mapbox to display path routes. Following the standard Angular practice of splitting components, I separated the map rendering component and called it into the main map component. However, I encounte ...

Enhance the size of the arrow in React Material-UI tooltip

Is there a way to make the tooltip arrow bigger in Material UI v4? I came across a workaround for the react-tooltip library that involves using the border-width css property. Any suggestions for achieving a similar result with MUI tooltips? ...

How can I create the effect of text changing color automatically after a specified time period has elapsed

I am currently dealing with a timer that is functioning properly, but I have a specific CSS inquiry. Essentially, what I would like to achieve is when the timer hits 30 seconds, I want the numbers to change to red color. $(function () { var $startTimer = ...

Issue with scrollspy causing navigation items to not highlight correctly

If you want to track my progress, you can view it here - . Although clicking on the links in the navigation bar scrolls the page to the correct location, the link itself is not being highlighted. To address this, I had to incorporate an offset. var offset ...

Guide on breaking a th tag as a line in a table using CSS

I'm attempting to achieve jQuery datatable-style responsiveness in an Angular table child component. I managed to separate the td and th separately using absolute and relative positions but encountered an issue where the th tag is not breaking at the ...

The CSS modifications are only visible in my browser after I delete the browsing data

After setting up a landing page with simple text in the center of the screen using flex, I encountered an issue. Whenever I made changes to the CSS, they would not reflect in my browser unless I cleared the browsing data (history, cookies, etc). This probl ...

The video controls cannot be seen

I'm encountering an issue while trying to incorporate controls into a full-width HTML5 video. Despite following this example: https://jsfiddle.net/nfouvpe5/, the controls remain invisible. Below is the code snippet I am using: <div class="overlay" ...

An element featuring a background color is vertically aligned in the middle of its parent container

Struggling to achieve a seemingly simple task, but coming up short on finding a solution. The goal is to have a background-color that aligns vertically in the middle of the first and last images in a stack of images. It may sound more complicated than it a ...