Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 810171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:50:33+00:00 2026-05-15T00:50:33+00:00

I’m having an issue where I’m trying to update the background gradient of an

  • 0

I’m having an issue where I’m trying to update the background gradient of an element with JavaScript based on values I specify.

I tried this route:

elem.style.backgroundImage = '-webkit-gradient(radial, '+x+' '+y+', 0, '+x+' '+y+', 800, from(#ccc), to(#333)), -moz-radial-gradient('+x+'px '+y+'px, circle cover, #ccc 0, #333 100%)';

Since Webkit and Gecko have two different syntaxes for CSS3 gradients, I need to specify both. However, the above code doesn’t work. It works if I only have just the Gecko syntax or just the Webkit syntax, not both.

I think you can check for CSS gradient support, but my question is, is there a way to check which syntax needs to be used without browser sniffing? Keep in mind that I need to set my gradients this way since the x and y coordinates of the gradient change dynamically.

Hope this makes sense, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:50:33+00:00Added an answer on May 15, 2026 at 12:50 am

    Edit The below is useful for other reasons, but in fact, I don’t think it helps with the OP’s problem of knowing whether to use the WebKit or Firefox symtax! (Doh) It helps with knowing whether the gradients can be used at all.

    Edit again But! Looking at the Modernizr source shows us how to do it with a feature test (they’re clever, those folks). You can probably figure it out by looking at the source yourself, but here’s a quickly hacked-together example:

    function testGradientSyntax() {
        var element;
    
        element = document.createElement("testsyntax");
        element.style.cssText =
            "background: -webkit-gradient(radial, 45 45, 10, 52 50, 30, from(#A7D30C), to(rgba(1,159,98,0)), color-stop(90%, #019F62))";
        if (element.style.background.indexOf("-webkit") >= 0) {
            // It's WebKit syntax
            log("This supports WebKit syntax");
        }
        else {
            // It's not WebKit syntax
            log("This doesn't support WebKit syntax");
        }
    }
    

    You might want to use Modernizr for this. It detects the relevant syntax and provides a way for you to use a single CSS file with both syntaxes.

    Sample gradient code from the docs:

    button.glossy {
       background: #ccc url(gloss.png) 50% 50% repeat-x;
    }
    .cssgradients button.glossy {
       background: #ccc -webkit-gradient(linear, left top, left bottom, 
             from(rgba(255,255,255, .4)), 
             color-stop(0.5, rgba(255,255,255, .7)), 
             color-stop(0.5, rgba(0,0,0, .2)), 
             to(rgba(0,0,0, .1)));
    }
    .cssgradients button.glossy:hover {
       background-color: #fff;
    }
    

    (Edit In the above, I’ve removed a line from the end of the .cssgradients button.glossy rule that looked to me like an error in the docs.)

    See that .cssgradients class? When you run Modernizr, it detects whether that’s the relevant syntax and if so adds the class to your html element, which turns on the descendant selector .cssgradients button.glossy so that rule gets applied.

    This is, sadly, all dependent on the browser having Javascript enabled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.