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 8438157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:37:51+00:00 2026-06-10T07:37:51+00:00

I am using Raphael and I want to create a rect and control the

  • 0

I am using Raphael and I want to create a rect and control the fill property through a CSS.

Everything works fine when I set the fill attr in the classical way:

    space = paper.rect(0,0,1000,500).attr({fill: "url('img/cell_background.png')"});

In fact, with this approach I get the correct filling. If inspect the elements I can see that in the rect element the fill attribute is specified and it refers to a pattern defined in the svg‘s defs.

<svg>
   ...
   <defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); ">
        <pattern style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); " 
         id="E6992022-9B75-4D1E-9D44-6EC45CE420A1" x="0" y="0" 
         patternUnits="userSpaceOnUse" height="5" width="9" 
         patternTransform="matrix(1,0,0,1,0,0) translate(0,0)">
           <image style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); " 
                      x="0" y="0" 
                  href="img/cell_background.png" width="9" height="5">
               </image>
        
            </pattern>
      </defs>
      <rect style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0); " 
        x="0" y="0" width="1000" height="500" r="0" rx="0" ry="0" 
    fill="url(#E6992022-9B75-4D1E-9D44-6EC45CE420A1)" stroke="#000" 
    class="space">
      </rect>
    ...
</svg>

If I instead create the rect with the following code:

space = paper.rect(0,0,1000,500);
space.node.setAttribute("class","space");

And then in the .css I define:

.space {
fill: url('img/cell_background.png');
stroke: #ff0000;
}

Then the inspected html shows a fill='none' as rect attribute, the rectangle is correctly rendered with a red border, but it is filled with a solid black.

Some further observations:

  1. js are in the js/ folder, css in css/ folder, and images in img/ folder. I tried with ‘../img’, ‘./img’ and ‘img’ but I have the same behaviour;
  2. if I don’t put fill I obtain a white filling as expected;
  3. if I put fill: foobar I obtain a white background;
  4. if I put fill: #ff0000 I get the expected red background;
  5. I obtain the same black background if I use a fake filename;
  6. the behaviour is consistent with Chrome and with Firefox.

From the fourth and fifth point it looks like the file cannot be found, but I think to have exhausted the combination of paths that I should have checked (the css finds other images in the same folder using the ‘../img’ path). I reckon that the problem is somewhere else.

Does anybody had a similar experience?

  • 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-06-10T07:37:53+00:00Added an answer on June 10, 2026 at 7:37 am

    In SVG you can’t just specify a bitmap background url for an element as you do with HTML elements. The standard way of doing this in SVG is through pattern definitions. Raphael abstracts this messiness from you with a simple fill: url(...).

    You could load the pattern with your CSS stylesheet with something like…

    .space {
      fill: url('img/cell_background.svg#bitmap');
      stroke: #ff0000;
    }
    

    But of course, cell_background.svg#bitmap still needs to look like…

    <svg xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink">
       <defs>
            <pattern id="bitmap" x="0" y="0" patternUnits="userSpaceOnUse" height="5" width="9">
               <image x="0" y="0" xlink:href="img/cell_background.png" width="9" height="5">
               </image>
             </pattern>
        </defs>
    </svg>
    

    But of course this only makes matters more complex.

    The reason why your rect is showing up black is because the engine is trying to load a missing fill definition (gradient or pattern), which defaults to black.

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

Sidebar

Related Questions

I am using Raphael to create a vector shape and fill it with a
I'm trying to create an image animation using Raphael JS. I want the effect
So I have been using raphael to create a user interface and want it
I don't understand the way Raphael or SVG works. I want to create a
I'm using the Raphael library to create SVG objects. To initialise the SVG shape
I'm using the Raphaël—JavaScript Library to create some pie chart graphics, but I want
I have a situation (using the Raphael library) where I have this: rect.click(doSomething); And
I want to create a sphere in Raphael which should look like I am
I am using Raphael graphics and animations which is a javascript library. I want
I'm creating some circles using Raphael. When a user clicks a button, I want

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.