How to create hamburger menu icon consisting from single SVG path - html
The SVG code of Material design Hamburger menu icon:
<svg style="width:24px;height:24px" viewBox="0 0 24 24">
<path fill="currentColor" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
</svg>
However it always could be some reason I can not use the Material Design icon and need to create my own one. But how I can reach such simple code? One path.
Tried to draw the similar icon in AbodeXD. The output SVG code was:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="26" height="18" viewBox="0 0 26 18">
<defs>
<clipPath id="clip-アートボード_1">
<rect width="26" height="18"/>
</clipPath>
</defs>
<g id="アートボード_1" data-name="アートボード – 1" clip-path="url(#clip-アートボード_1)">
<line id="線_1" data-name="線 1" x2="26" transform="translate(0 0.5)" fill="none" stroke="#000" stroke-width="1"/>
<line id="線_2" data-name="線 2" x2="26" transform="translate(0 17.5)" fill="none" stroke="#000" stroke-width="1"/>
<line id="線_3" data-name="線 3" x2="26" transform="translate(0 9)" fill="none" stroke="#000" stroke-width="1"/>
</g>
</svg>
The SVG optimization reduced above code to:
<svg xmlns="http://www.w3.org/2000/svg" width="26" height="18">
<defs>
<clipPath id="a">
<path d="M0 0h26v18H0z"/>
</clipPath>
</defs>
<g data-name="アートボード – 1" clip-path="url(#a)" fill="none" stroke="#000">
<path data-name="線 1" d="M0 .5h26"/>
<path data-name="線 2" d="M0 17.5h26"/>
<path data-name="線 3" d="M0 9h26"/>
</g>
</svg>
But it a more complicated than Material Design SVG. Also, we can't change the icon color by like fill: red as many other icons.
Path syntax is easy to understand - let's break it down:
<path fill="currentColor" d="M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z" />
M3,6 - Move the drawing point to coordinates [3,6]
H21 - draw a Horizontal line to coordinates [21,Current Y Coordinate (6)]
V8 - draw a Vertical line to coordinates [Current X Coordinate (21), 8]
H3 - draw a Horizontal line to coordinates [3,Current Y Coordinate (8)]
V6 - etc.
M3,11 - Move the drawing point to coordinates [3,11]
... etc
Z - Draw a line to the start of the current subpath (the coordinates of the last MoveTo - which in this case, doesn't do anything, because we're already at those coordinates)
So if you want the hamburger menu to be in a smaller viewBox, you can edit the path by hand like so:
<svg style="width:20px;height:20px" viewBox="0 0 20 20">
<path fill="currentColor" d="M1,4 H18 V6 H1 V4 M1,9 H18 V11 H1 V7 M3,14 H18 V16 H1 V14" />
</svg>
Please Use stroke="red" rather than using Fill="red"
Please find the Below updated code:
<svg xmlns="http://www.w3.org/2000/svg" width="26" height="18">
<defs>
<clipPath id="a">
<path d="M0 0h26v18H0z"/>
</clipPath>
</defs>
<g data-name="アートボード – 1" clip-path="url(#a)" fill="none" stroke="red">
<path data-name="線 1" d="M0 .5h26"/>
<path data-name="線 2" d="M0 17.5h26"/>
<path data-name="線 3" d="M0 9h26"/>
</g>
</svg>
Related
SVG Isometric Box, overlapping lines
This is my first attempt at creating .svg images. I created an isometric view of a plate, but I noticed that when the image scales up, the lines do not intersect cleanly - they overlap (see image). What am I doing wrong here? <svg viewBox="0 0 100 60" xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient id="greyGrad" gradientUnits="userSpaceOnUse"> <stop stop-color="#ddd" offset="0%"/> <stop stop-color="#999" offset="85%"/> </linearGradient> </defs> <g> <polygon stroke="#333" points="0,0 8,14 11,14 3,0" fill="url(#greyGrad)"/> <polygon stroke="#333" points="8,14 11,14 11,58 8,58" fill="url(#greyGrad)"/> <polygon stroke="#333" points="0,0 8,14 8,58 0,45" fill="url(#greyGrad)"/> </g> </svg>
The problem is that mitred corners tend to stick out a long way at acute angles. The easy fix is to add stroke-linejoin="round" to your path elements, which will round them all off with the same radius. But if you want sharp corners, you'll get better results if you draw the paths and fills separately, with the angles in the paths as large as possible. Here's an example. If you hover over the strokes, you should be able to see what's going on: path:hover { stroke:#888; } <!-- Cube consisting of three filled quads --> <svg xmlns="http://www.w3.org/2000/svg" width="200" height="180" viewBox="0 0 40 36"> <g stroke="#000" stroke-width="4"> <path d="M2,9 26,9 26,33 2,33Z" fill="orange"/> <path d="M26,9 38,3 38,27 26,33Z" fill="red"/> <path d="M2,9 14,3 38,3 26,9Z" fill="yellow"/> </g> </svg> <!-- Cube with separate strokes and fills --> <svg xmlns="http://www.w3.org/2000/svg" width="200" height="180" viewBox="0 0 40 36"> <!-- Fills (no stroke) --> <g stroke="none"> <path d="M2,9 26,9 26,33 2,33Z" fill="orange"/> <path d="M26,9 38,3 38,27 26,33Z" fill="red"/> <path d="M2,9 14,3 38,3 26,9Z" fill="yellow"/> </g> <!-- Strokes (outline first, then interior lines --> <g fill="none" stroke="#000" stroke-width="4"> <path d="M2,9 14,3 38,3 38,27 26,33 2,33Z"/> <path d="M2,9 26,9 38,3M26,9 26,33"/> </g> </svg>
Tick inside circle
I am trying to create tick Inside filled circle. I did following but, doesn't looks perfect. <svg height=10 viewBox="0 0 10 10" width=10> <g fill="none" stroke="#22AE73" stroke-width="1"></g> <circle cx=5 cy=5 fill='#29AB87' r=5 /> <polyline stroke="#ffffff" stroke-width="2" points="2.5,5.8 4.7,7.9 9.2,2.4 " /> </svg> Any help would be greatly appreciated.
Your points are reaching the 10 10 part of your viewbox, hence it doesn't fit. You could change your points to lower values. Alternatively, here's an svg that might work for you that is path based <svg width="10px" height="10px" viewBox="0 0 10 10" > <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="tick"> <circle id="Oval" fill="#349006" cx="5" cy="5" r="5"></circle> <path d="M7.26241838,2.25 L8.35843389,3.34601551 L3.9390165,7.76543289 L3.937,7.763 L3.93041937,7.77093389 L1.65,5.49051452 L2.74601551,4.39449901 L3.932,5.58 L7.26241838,2.25 Z" id="Combined-Shape" fill="#FFFFFF"></path> </g> </g> </svg>
Why is the mask on SVG path not masking correctly?
I have an SVG with a path that I am trying to mask out. I have a circle tag with an id of startCircle and a path with an id of startOrder. The circle one is working, the path is not, but I'm not sure why. <svg id="wawa" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 337.32 386.57"> <style> .st0 { fill: #fff } .st5 { fill: #c32034 } </style> <defs> <mask id="button-mask" maskUnits="userSpaceOnUse" maskContentUnits="userSpaceOnUse"> <path d="M51.24 372.52V52.27c0-15.4 12.6-28 28-28h180.79c15.4 0 28 12.6 28 28v320.25" fill="#fff" /> </mask> </defs> <path id="endScreen" class="st0" d="M51.24 372.52V52.27c0-15.4 12.6-28 28-28h180.79c15.4 0 28 12.6 28 28v320.25"/> <path id="base" fill="none" stroke="#c1a88b" stroke-width="4" stroke-linecap="round" stroke-miterlimit="10" d="M6 374.88h326.27" /> <path id="phoneOutline" d="M302.12 372.43V55.31c0-25.15-21.05-45.73-46.78-45.73H82.26c-25.73 0-46.78 20.58-46.78 45.73v317.13" fill="none" stroke="#c1a88b" stroke-width="7.358" stroke-linecap="round" stroke-miterlimit="10" /> <path id="startOrder" class="st5" d="M236.62 337.2H99.44c-6.6 0-12-5.4-12-12v-20.48c0-6.6 5.4-12 12-12h137.17c6.6 0 12 5.4 12 12v20.48c.01 6.6-5.39 12-11.99 12z" mask="url(#button-mask)" /> <circle id="startCircle" cx="110" cy="110" r="100" fill="#9c6" mask="url(#button-mask)" /> </svg> I set up a pen to show what I am talking about codepen
The answer is in the TweenMax library you are including: TweenMax.set( '#startOrder',{x:"+=100"}); This moves the #startOrder 100 px to the right by setting a transform="matrix(1,0,0,1,100,0)" Transforms are applied after masks (they are always the last operation), and before the translation the path lies completely within the mask shape. You can solve this by moving the path inside a group and applying the mask to the group: <g mask="url(#button-mask)"> <path id="startOrder" ... /> </g>
Overlay a svg with a transparent background pattern
Question How can I overlay a transparent image pattern (PNG) over a SVG, while keeping the overlaid image pattern within the SVG's bounds, and keeping the SVG's fill visible? Kind of like how in CSS you can define both background-color and backgroud-image. Eg. background: red url(noise.png) top left repeat; Image Example of what I am looking for In this image, the balloon on the left is the SVG I currently have. What I'm trying to achieve is how the right balloon looks with noise applied to it. Code Example: Here's a code example of what I've tried so far: FULL DEMO: http://staging.kassandrapoon.com/tests/svg/ (Sorry for the non-jsfiddle or code pen example. The background pattern wasn't loading cross domain) SVG with my pattern attempt: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="143px" height="214px" viewBox="0 0 143 214" enable-background="new 0 0 143 214" xml:space="preserve"> <defs> <!-- noise.png --> <style type="text/css"> <![CDATA[ .filtered{ filter: url(#filter); } ]]> </style> <filter id="filter" filterUnits="userSpaceOnUse"> <feImage xlink:href="noise.png" x="0" y="0" width="198" height="193" result="IMAGEFILL"/> <feTile in="IMAGEFILL" result="TILEPATTERN"/> <feComposite operator="in" in="TILEPATTERN" in2="SourceAlpha"/> </filter> </defs> <g> <g class="filtered"> <polygon fill-rule="evenodd" clip-rule="evenodd" fill="#DE3F18" points="90.8,214 53.2,214 47.3,175.9 98.1,175.9 "/> <path fill-rule="evenodd" clip-rule="evenodd" fill="#DE3F18" d="M143,72.6c0-39.5-32-71.7-71.5-71.7S0,33.2,0,72.7 C0,79.1,0.9,86,2.4,91.6c0,0,1.3,4.4,2,6.2C4.6,98.2,5,98.6,5.1,99c0.5,1.3,1.2,2.7,1.8,4c0.3,0.6,0.6,1.1,0.9,1.6 c0.6,1.1,1.2,2.3,1.8,3.4c0.3,0.6,0.7,1.1,1,1.7c0.7,1.1,1.3,2.1,2,3.1c0.4,0.5,0.8,1.1,1.1,1.6c0.7,1,1.5,2,2.3,3 c0.4,0.5,0.8,1,1.2,1.4c0.8,1,1.7,1.9,2.6,2.9c0.4,0.4,0.8,0.8,1.2,1.3c1,1,2,1.9,3,2.8c0.4,0.3,0.8,0.7,1.2,1 c0.3,0.2,0.5,0.5,0.8,0.7L46.4,158h2.8h44.5h2.8l20.3-30.6c0.3-0.2,0.5-0.5,0.8-0.7c0.4-0.3,0.8-0.7,1.2-1c1-0.9,2-1.8,3-2.8 c0.4-0.4,0.8-0.8,1.2-1.3c0.9-0.9,1.8-1.9,2.6-2.9c0.4-0.5,0.8-1,1.2-1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" fill="#DE3F18" d="M91.9,57.1c0,43.5-21.6,101-21.6,101s-21.6-57.5-21.6-101 S58.9,0.7,70.4,0.7C79.1,0.7,91.9,13.6,91.9,57.1z"/> <polyline fill="none" stroke="#FC611F" stroke-width="1.8927" stroke-miterlimit="10" points="47.9,175.9 27.8,130 70.6,130 115.2,130.1 96.5,175.9 "/> <line fill="none" stroke="#FC611F" stroke-width="1.8927" stroke-miterlimit="10" x1="73.2" y1="175.9" x2="72.3" y2="130"/> <g> <polygon fill="#DE3F18" points="46.4,158 49.3,158 93.7,158 96.6,158 115.3,130 27.7,130 "/> </g> </g> <g> <g> <path fill="#F9F9EF" d="M102.6,188.6c0,5.5-2.3,7.4-5.1,7.4c-2.8,0-5.1-1.9-5.1-7.4s5.1-12.6,5.1-12.6S102.6,183,102.6,188.6z"/> <path fill="#F9F9EF" d="M77.6,188.6c0,5.5-2.3,7.4-5.1,7.4c-2.8,0-5.1-1.9-5.1-7.4s5.1-12.6,5.1-12.6S77.6,183,77.6,188.6z"/> <path fill="#F9F9EF" d="M52.6,188.6c0,5.5-2.3,7.4-5.1,7.4c-2.8,0-5.1-1.9-5.1-7.4s5.1-12.6,5.1-12.6S52.6,183,52.6,188.6z"/> </g> </g> </g> </svg> I've tried defining a pattern in the SVG like here, but that replaces the existing fill color which I want to keep.
how to create rounded corners in svg
I'd like to create rounder corners for my svg path but I can't make it work. Is there a good way to accomplish this? here is my code: <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%"> <clipPath id="svgClip"> <path id="svgPath" d="M3,474 L957,471 942,24 40,1 z" /> </clipPath> <path id="svgMask" d="M3,474 L957,471 942,24 40,1 z" /> </svg> Thanks!
You can use stroke-linejoin="round" and pick a suitable stroke-width. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="300" height="300" viewBox="-100 -100 1200 1000"> <path id="svgMask" d="M3,474 L957,471 942,24 40,1 z" stroke-linejoin="round" stroke="black" stroke-width="80"/> </svg>
This may depend on compatibility but stroke-linecap works in Chromium browsers. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%"> <clipPath id="svgClip"> <path id="svgPath" d="M3,474 L957,471 942,24 40,1 z" stroke-linecap="round"/> </clipPath> <path id="svgMask" d="M3,474 L957,471 942,24 40,1 z" stroke-linecap="round"/> </svg>
There is no automatic or easy way to do this for paths. You can supply an r (radius) attribute to<rect> elements, but there is no equivalent for <path>. You would need to calculate and add cubic bezier path commands (C or c) at the appropriate places in your path.