<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Leonardo</title>
    <description>The latest articles on DEV Community by Leonardo (@cavera).</description>
    <link>https://dev.to/cavera</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1129546%2Fd7d4ddf0-8990-40fb-9a6e-7c59b3de3e8b.jpeg</url>
      <title>DEV Community: Leonardo</title>
      <link>https://dev.to/cavera</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cavera"/>
    <language>en</language>
    <item>
      <title>How I see SVG (Part 1)</title>
      <dc:creator>Leonardo</dc:creator>
      <pubDate>Mon, 09 Oct 2023 18:06:17 +0000</pubDate>
      <link>https://dev.to/cavera/how-i-see-svg-part-1-172g</link>
      <guid>https://dev.to/cavera/how-i-see-svg-part-1-172g</guid>
      <description>&lt;p&gt;If there's a format that can exist between the development and design worlds, it's named SVG.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SVG (Scalable Vector Graphics) is an XML-based format to describe vector graphics.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That means:&lt;/p&gt;

&lt;p&gt;For developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Markup language, like HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can be edited in a text editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is one of the oldest formats that is still relevant today.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For designers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Can be previewed everywhere.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be edited or exported from a lot of apps like Illustrator, Figma, or Inkscape (there are a lot of apps online too).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nowadays, this format is used a lot; e.g., all the icons used in any app or website you're using right now may be SVG files.&lt;/p&gt;

&lt;h1&gt;
  
  
  SVG Explanation
&lt;/h1&gt;

&lt;p&gt;Now, let's watch an example of an SVG code and its preview.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/cavera/embed/RwEEqOb?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's explain what you can see here:&lt;/p&gt;

&lt;p&gt;The code seems like HTML. It has tags and attributes, and those tags can have IDs too! All the elements are wrapped in an SVG tag, with a series of attributes, the majority of which are self-explanatory (width, height, fill) and others like &lt;code&gt;xmlns&lt;/code&gt; that I never cared what meant (it's mandatory only if it's not embedded into the HTML code).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;👆🏼 For the designers: Let's imagine that the units of the values you will see are pixels. Later, we'll cover the relativity of the units in this format.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The viewBox attribute
&lt;/h2&gt;

&lt;p&gt;For this example, let's remove the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; attributes to better understand what we can do with this attribute:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/cavera/embed/wvRRQOW?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In the code, please look for the couple of attributes that are named &lt;code&gt;viewBox&lt;/code&gt;. This attribute has four numeric values in order: X, Y, Width, and Height.&lt;/p&gt;

&lt;p&gt;In the first example: X:0, Y:0 Width:200 Height:200.&lt;/p&gt;

&lt;p&gt;In the second example, X:50 Y:70 Width:150 Height:100&lt;/p&gt;

&lt;p&gt;This is a graphic explanation of the second example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QSvYSeEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xp2nap68azwa6wsoo4o1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QSvYSeEY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xp2nap68azwa6wsoo4o1.png" alt="Coordinates explanation of the viewBox tag in an SVG file" width="200" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;viewBox&lt;/code&gt; tag acts as a camera viewport for the graphics in the file, and those numbers act like the coordinates to locate the camera and its dimensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "g" tag
&lt;/h2&gt;

&lt;p&gt;Like in many vector graphics apps, we can group elements. This is where the group tag comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "primitives" tags
&lt;/h2&gt;

&lt;p&gt;Many tags are called primitives; those are the basis of many graphic representations like &lt;code&gt;rect&lt;/code&gt;, &lt;code&gt;circle&lt;/code&gt; or &lt;code&gt;ellipse&lt;/code&gt;; there are a lot more, but in this example, we just use the first two. In the &lt;code&gt;rect&lt;/code&gt; and &lt;code&gt;circle&lt;/code&gt; tags, we can see new attributes related to their position or origin, but they are self-explanatory too. To clarify, the &lt;code&gt;cx&lt;/code&gt;, &lt;code&gt;cy&lt;/code&gt; and &lt;code&gt;r&lt;/code&gt; attributes are circle X origin, circle Y origin, and radius, respectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can I do with all of this?
&lt;/h2&gt;

&lt;p&gt;I think SVG code is like HTML code, so I treat it the same. The tags can have IDs or classes, so I can access those elements via CSS or JavaScript because those elements are part of the DOM when they are embedded.&lt;/p&gt;

&lt;p&gt;Please see this example and hover over the different elements:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/cavera/embed/OJrdPGx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let's break this example into parts:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The SVG has a group with three elements: two rectangles and one circle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The group has an ID: &lt;code&gt;svggroup&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One rectangle has ID: &lt;code&gt;my_rect&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The circle has its own ID, &lt;code&gt;my_ellipse&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We assigned dimensions to the SVG.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The elements with IDs now have a transform-origin, a transform-box (delete it and see what it changes), and a transition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each of those elements has a hover state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The transform and the opacity are modified in their hover state.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this case, we didn't manipulate any of the attributes, but we used CSS to animate them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Only that?
&lt;/h2&gt;

&lt;p&gt;No. We can do more. The sky is the limit, and by exploring every tag, attribute, and reference, we can make a lot of things.&lt;/p&gt;

&lt;p&gt;This is an example with CSS and just a little of JavaScript. Just click the buttons to see the animations:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/cavera/embed/JmrMVJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The buttons just gave classes to the group with ID mira. The rest is CSS.&lt;/p&gt;

&lt;p&gt;In the next articles, we'll see more detailed aspects of how we can take advantage of this format.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;p&gt;If you wanna dig more about every tag and what can you do with this, these are two excellent links to learn everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Interactive SVG Reference: &lt;a href="https://fffuel.co/sssvg/"&gt;https://fffuel.co/sssvg/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MDN SVG Reference: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/SVG"&gt;https://developer.mozilla.org/en-US/docs/Web/SVG&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>svg</category>
      <category>css</category>
      <category>design</category>
      <category>development</category>
    </item>
    <item>
      <title>Codepen Showcase</title>
      <dc:creator>Leonardo</dc:creator>
      <pubDate>Sun, 30 Jul 2023 18:24:29 +0000</pubDate>
      <link>https://dev.to/cavera/codepen-showcase-11m1</link>
      <guid>https://dev.to/cavera/codepen-showcase-11m1</guid>
      <description>&lt;p&gt;This is the outcome of using Codepen as a testing ground for a quick concept, a CSS feature, or a JS library before integrating it into a project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/collection/xKJNYR"&gt;https://codepen.io/collection/xKJNYR&lt;/a&gt;&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>gsap</category>
      <category>css</category>
    </item>
  </channel>
</rss>
