The stop-color property is not functioning as expected in CSS/SVG

Here is the code I am currently working with:

<?xml version="1.0" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" width="360" height="240">
<style>stop{stop-opacity:1}circle{fill:url(#r)}</style>
<defs>
<radialGradient id="r" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:#ce1126"/>
<stop offset="17%" style="stop-color:#e5911d"/>
<stop offset="33%" style="stop-color:#fcd116"/>
<stop offset="50%" style="stop-color:#18c063"/>
<stop offset="67%" style="stop-color:#75aadb"/>
<stop offset="83%" style="stop-color:#803ac5"/>
<stop offset="100%" style="stop-color:#00335b"/>
</radialGradient>
</defs>
<circle cx="150" cy="300" r="55"/>
</svg>

Curiously, when I tried to add stop-color:attr(c) to the CSS of the stops and adjust them accordingly (style="stop-color:=>c="), it did not work as expected in Safari/iOS9. Can anyone explain why this might be happening?

Answer №1

It's intriguing to note that Safari doesn't seem to support this particular feature. In Firefox, however, the following code appears to be functional:

<svg xmlns="http://www.w3.org/2000/svg" width="360" height="240">
  <style>
    stop {
      stop-opacity: 1
    }
    circle {
      fill: url(#r)
    }
  </style>
  <defs>
    <radialGradient id="r" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
      <stop offset="0%" style="stop-color:#ce1126" />
      <stop offset="17%" style="stop-color:#e5911d" />
      <stop offset="33%" style="stop-color:#fcd116" />
      <stop offset="50%" style="stop-color:#18c063" />
      <stop offset="67%" style="stop-color:#75aadb" />
      <stop offset="83%" style="stop-color:#803ac5" />
      <stop offset="100%" style="stop-color:#00335b" />
    </radialGradient>
  </defs>
  <circle cx="60" cy="100" r="55" fill="url(#r)" />
</svg>

In my opinion, I wouldn't recommend using that method. The more universally supported approach would be:

  • Include stop-color as an attribute
  • Assign a class or id to the stop element and apply stop-color using CSS.

Answer №2

This is a simple method that will function correctly on all types of web browsers.

<stop offset="0%"  style={{ stopColor: '#ce1126' }}/>
<stop offset="17%" style={{ stopColor: '#e5911d' }}/>
<stop offset="33%" style={{ stopColor: '#fcd116' }}/>
<stop offset="50%" style={{ stopColor: '#18c063' }}/>
<stop offset="67%" style={{ stopColor: '#75aadb' }}/>
<stop offset="83%" style={{ stopColor: '#803ac5' }}/>
<stop offset="100%" style={{ stopColor: '#00335b' }}/>

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

The Bootstrap modal simply fades away without ever making an appearance

My bootstrap modal is not displaying on desktop, only showing a faded screen. It works fine on mobile and tablet devices. Any ideas why this might be happening? Here is the code: <button type="button" class="btn btn-primary" data-to ...

Struggling to align Social Media Share Buttons in inline format for a website

I'm having trouble aligning these social media share buttons with my inline list. I tried using vertical-align: top; on the <li> element, but it didn't work in Chrome. You can view the page here: Here is the full HTML/CSS code: <!DOCT ...

How to conditionally set the active class in a React component

I am new to using React and I am encountering some issues. My goal is to add an active class when any of these components are opened. I have attempted a solution but it isn't working as expected. I need assistance in adding a background color to the d ...

Strategies for smoothly navigating the page to a specific div every time

Currently, I am working on a form that requires submitting multiple child forms. To enhance user experience, I have incorporated jQuery functionality to display a message at the top of the page upon each submission. Now, my goal is to implement a feature w ...

What steps are needed to successfully integrate bootstrap.js, jquery, and popper.js into a project by using NPM to add Bootstrap?

I've successfully set up a project and incorporated Bootstrap via npm. However, I'm facing challenges in loading the necessary javascript files for Bootstrap components. It's important to note that I am utilizing a Vagrant Box (virtual machi ...

Modify section background color for every iteration in an image carousel

Is it possible to dynamically change the background color of the cd-hero section each time a new image is loaded in a simple slider on the home page? Can this be achieved by storing predefined colors in an array so that different images trigger different b ...

Using image paths in CSS for styling purposes

As I develop an Asp.net website, I've encountered a surprising issue. Here is my folder structure: - Styles - master.css - Images -webPages -scripts When trying to access an image in the Images folder from the CSS file, I receive a ...

What is the best way to position an image beside a jquery dialog box?

Apologies for not finding a suitable topic to discuss. Is it possible to place an image next to a jQuery dialog, similar to the following example? If so, how can this be achieved? ...

What could be causing my modal to not animate from the center of the screen?

I am aiming to have my .modal div class smoothly scale from 0 to 1 right in the center of the screen instead of starting at the bottom right and then moving to the center before settling in its final position. I have checked various resources like MDN docu ...

Stop Scrolling on Web Pages with HTML5

I need assistance in preventing all forms of page scrolling within my HTML5 application. Despite searching on popular platforms like SO and Google, I have been unable to find a comprehensive solution for disabling all scrolling mechanisms entirely. Existin ...

I developed a website and also created a mobile.html version, with the desire to seamlessly switch between the two based on screen

I have two files, home.html and mobilehome.html, and I am trying to switch between them when the screen width goes below a certain size. if (screen.width <= 600) { document.location = "HomeMobile.html"; } This approach works well in Respon ...

Stop an animation while it is in the hover state

Currently experimenting with CSS3 Animations to create a Panoramic view using only CSS and no JavaScript. I have managed to create a somewhat working demo: http://www.example.com/images/panoramic/ The concept is simple: when the user hovers over the blac ...

Having trouble with Tailwind CSS not functioning correctly once the font is imported?

I am currently working on a next.js project and utilizing tailwind for styling. I have noticed an odd behavior when importing a custom font into my globals.css file. page.jsx "use client"; import React from "react"; const page = () = ...

Modifying the Vue page background directly from a page: a step-by-step guide

UPDATE: I recently discovered that I need to modify the body background-color, but I am unsure of how to accomplish this from within the style of this page based on the wrapper's class. The class is determined by the data values. I aim to change the ...

Arranging blocks within blocks? Placing additional text underneath a block

Looking to append some text at the end of a block called .label. Inside this block, there is a sub-element called .label_title, and below that is a picture/link enclosed in another block. Under the picture/link, I wish to include a short description while ...

jQuery will envelop the HTML elements in an inconsequential div

Imagine a website that is visually complex, with various styles and images positioned in different ways. What if we wanted to add a small overlay icon above each image? At first, the solution might seem simple - just use absolute positioning for a span el ...

Rearrange information when the textarea is adjusted in size

One issue I am facing is that when I resize the textarea in my form, the content below the textarea does not move along with it. How can I ensure that the content moves accordingly when resizing the textarea? <form name="contactform" method="post" ...

Height of the liquid division

I'm encountering an issue with my CSS layout. I have a container containing two columns, each styled with the following CSS: #project-desc{ float: left; width: 500px; } #project-images{ float: right; width: 300px; } I've use ...

How can you ensure a line stays fixed to the bottom of a box regardless of the text size in SCSS and HTML?

I have a CSS rule that displays a line within a div only when the div is active. The specific SCSS class I am using is: .active-tab:after { content: ''; display: inline-block; height: 4px; width: 100px; right: -7px; background-color: ...

Which CSS 3 transition prefixes are recommended for optimal performance?

I'm curious about the CSS vendor prefixes needed for transitions. One source mentions that "you need to use all the usual prefixes to make this work in all browsers (-o-, -webkit-, -moz-, -ms-)". Another page only displays the -webkit- and -moz- pre ...