Jump to content

Recommended Posts

Posted

I am new to Affinity, and I am trying to create a SVG for a website. This SVG will be used as paths in the website. The issue that I am encountering is the SVG does not respond to the CSS formatting. I am not sure if I am creating the SVG incorrectly, if some of the export option is generating the issue. Could someone help me with this please? I am attaching the SVG to the message. 

 

 

SVG.txt

Posted

Affinity programs don't recognise CSS. If you open the attached file in a browser you'll see the effects of css. If you open it in Affinity the colours will be gone
So you can use Affinity for your layout then finally add the css with a text editor. Also ensure that there are no clashes between Affinity inline styles and the css definitions

SVG.svg

Microsoft Windows 11 Home, Intel i7-1360P 2.20 GHz, 32 GB RAM, 1TB SSD, Intel Iris Xe
Affinity Photo - 24/05/20, Affinity Publisher - 06/12/20, KTM Superduke - 27/09/10

Posted

Take a look here in order to get an idea how to handle SVG and CSS:

Further, the difference between XML attributes and inline CSS properties. In the first example, all of the information is declared as XML attributes, while in the second example, all of the style properties are packaged as inline CSS ...

// XML-Attribute and CSS-inline Style

<circle id="example1"
  cx="50"
  cy="50"
  r="50" 
  fill="#dfac20"
  stroke="#3983ab"
  stroke-width="2" 
/>

<circle id="example2"
  style="cx:50; cy:50; r:50; fill:#dfac20; stroke:#3983ab; stroke-width:2;"
/>

Note: for the above shown (example2) that inline CSS code generally overwrites previously loaded CSS formatting in the HTML head or from external style sheets.

Placing the CSS instructions into a style element ...

<svg>
  <style type="text/css">
    <![CDATA[
      circle {
        cx: 50;
        cy: 50;
        r:  50;
        fill: #dfac20;
        stroke: #3983ab;
        stroke-width: 2;
      }
    ]]>
  </style> 
  <circle id="example3" />
</svg>

----------

Formating basic shapes (circle, triangle, rect) with CSS ...

  • The HTML/SVG part ...
    <svg viewBox="0 0 600 250">
    	<circle id="circle" cx="100" cy="100" r="70" />
    	<path id="triangle" d="M200,30 h140 l-70,140 z" />
    	<rect id="rectangle" x="380" y="30" width="140" height="140" /> </svg>

     

  • The corresponding CSS part ...
    * {
    	stroke: #306f91;
    	stroke-width: 5;
    }
    
    path {
    	fill: #c32e04;
    }
    
    #rectangle {
    	fill: #dfac20;
    	stroke-width: 10;
    	stroke-opacity: 0.5;
    }
  • The result
    result.png.7a73c6eac638af20c83b65d30f2bf170.png

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.