Extra pixels when element is inline - html
I am struggling to understand how the calculation of width/height in inline elements works. My question is very similar to this Extra pixels are being added to the span element yet slightly different.
There is a div element of size 50x50. Within the div, there is a span with padding 15px. The span contains SVG circle of size 20x20.
So there are three use cases:
Only div is a block
div - size 50x50 ✔️
span - size: 50x47 ❌ where are those three pixels?
svg - size: 20x20 ✔️
div and span is a block
div - size 50x50 ✔️
span - size: 50x54 ❌ where do these 4 pixels come from?
svg - size: 20x20 ✔️
eveything is a block
div - size 50x50 ✔️
span - size: 50x50 ✔️
svg - size: 20x20 ✔️
span {
/* display: block; */
padding: 15px;
}
div {
height: 50px;
width: 50px;
}
svg {
/* display: block; */
height: 20px;
width: 20px;
}
<div>
<span>
<svg
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
</div>
CodePen is available here.
Note: I tried it in the latest Chrome but I think it will be the same everywhere. It's probably just some fundamental thing I am missing. :)
Your second case is covered here: Image inside div has extra space below the image. Due to the default alignment you will have extra space under your SVG. This can be fixed by adding display:block like you discovered or by adding vertical-align:top which is more logical as solution:
span {
display: block;
padding: 15px;
outline:1px solid green;
}
div {
height: 50px;
width: 50px;
margin:30px;
outline:1px solid blue;
}
svg {
height: 20px;
width: 20px;
outline:1px solid red;
}
<div>
<span>
<svg
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
</div>
<div>
<span>
<svg
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg" style="vertical-align:top;"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
</div>
Your first case is a bit tricky because it has nothing to do with the SVG or the width/height you are setting. It's all about font metrics.
To simplify let's remove the div around and consider different SVG inside the same span and without padding:
span {
border: 1px solid green;
margin:0 10px;
}
svg {
outline: 1px solid red;
}
<span>
<svg
viewBox="0 0 24 24" height="20"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="30"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="50"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="200"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
Notice how the span has always the same height whataver the SVG inside due to the nature of inline element. Let's increase the font-size
span {
border: 1px solid green;
margin:0 10px;
}
svg {
outline: 1px solid red;
}
body {
font-size:40px;
}
<span>
<svg
viewBox="0 0 24 24" height="20"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="30"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="50"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
<span>
<svg
viewBox="0 0 24 24" height="200"
xmlns="http://www.w3.org/2000/svg"
>
<circle
strokeLinecap="butt"
strokeDasharray="64"
cx="12"
cy="12"
r="9"
/>
</svg>
</span>
The span are now bigger in height and the SVG are kept the same. You will also note the small gap at the bottom of the SVG due to the alignment I explained previously. Try to add font-size:0 and see the result.
As you can see the height of your span has nothing to do with the SVG. To that height, you add the vertical padding to get the final height. In your case, the height was 17px and adding the padding you will have 47px which is close to 50px but there is no relation with.
Note that you may get a different result than 47px if you test in different browsers/OS since the font will not for sure be the same and the initial height can vary.
If you check the speficiation you can read:
The 'height' property does not apply. The height of the content area should be based on the font ...
The vertical padding, border and margin of an inline, non-replaced box start at the top and bottom of the content area,
Making the span block element will change this behavior and you will have a more intuitive result as you noticed in your last example: 2*15px of padding + 20px of SVG height.
Related question with more detail in order to understand how the height of element are calculated: How to determine height of content-box of a block and inline element
Another related question: Can specific text character change the line height?
Related
How does the `a` tag behave?
Could you explain how the a tag behaves in this example? Why is it so small? a { border: 1px solid currentColor; } <li> <a href="https://facebook.com/starbucks"> <svg aria-hidden="true" class="valign-middle absoluteCenter" focusable="false" preserveAspectRatio="xMidYMid meet"> <path></path> <circle class="sb-icon-hover" cx="50%" cy="50%" fill="transparent" r="75%"></circle> </svg> </a> </li> Also, could you explain, how to fix it? And how to center it inside the block? Thank you!
The anchor element (<a>) is by default an inline element. It will have the height of the font (example 1). So, making a border around it will display the height of the font. If you set the display of the <a> to inline-block or block (example 2 and 3) the element will "contain" the child elements (except if you limit the height...). With either one you can set properties like border, background, padding, margin etc. svg { display: inline; /*default*/ height: 2em; vertical-align: bottom; } a { border: 1px solid currentColor; } ul li:nth-child(1) a { display: inline; /*default*/ } ul li:nth-child(2) a { display: inline-block; } ul li:nth-child(3) a { display: block; } li { margin: .1em; } <ul> <li> <a href="https://facebook.com/starbucks">default <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> <li> <a href="https://facebook.com/starbucks">inline-block <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> <li> <a href="https://facebook.com/starbucks">block <svg viewBox="0 0 100 100"> <circle cx="50%" cy="50%" fill="red" r="50%"/> </svg> </a> </li> </ul>
Image clipped by svg is cropped
Img bannt has its original dimensions - 1920 x 540 I need to clip it using svg and it works but about 50 px in both dimensions of the image - are missing Seems like the image is cropped, not resized I created the svg file using CorelDraw - if matters any help ? .wrapt { position: relative; } .bannt { display: block; width: 100%; margin: 0 auto; clip-path: url(#cp1); } .svg_01 { position: absolute; left: 0; top: 0; width: 100%; } <div class='wrapt'> <svg class="svg_01" xml:space="preserve" width="1920px" height="540px" version="1.1" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" viewBox="0 0 1770.365 497.915"> <defs> <clipPath id="cp1"> <path class="fil0" d="M0 0l1770.365 0 0 497.915c-73.766,0 -147.531,-27.662 -221.296,-27.662 -73.765,0 -147.53,27.662 -221.296,27.662 -73.765,0 -147.53,-27.662 -221.295,-27.662 -73.765,0 -147.53,27.662 -221.296,27.662 -73.765,0 -147.53,-27.662 -221.295,-27.662 -73.54,0 -147.079,27.49 -220.619,27.658 25.494,-29.84 30.119,-61.425 -0.516,-76.499 -69.556,-34.225 -40.441,-137.117 -168.281,-144.344 -127.841,-7.226 -197.109,67.562 -186.722,153.564 2.515,20.822 7.328,38.886 14.915,54.45l-102.664 12.833 0 -497.915z"/> </clipPath> </defs> </svg> <img class='bannt' src='bannt/plain_01.jpg' alt='img'> </div>
The clip path in CSS needs to either fit the image size exactly or be scaled so that it fits. I will suggest to insert the image into the SVG. When you set the viewBox of the SVG to the size of the clip path, the clip path will fit the inner "coordinate system" of the SVG. If you give the image the same width, it also scales to the size of the SVG. The "outer size" of the SVG is default 100%. This can be controlled using CSS. It will probably be a good idea to use display block on the SVG. svg { display: block; } <svg viewBox="0 0 1770 500"> <defs> <clipPath id="cp1"> <path d="M0 0l1770.365 0 0 497.915c-73.766,0 -147.531,-27.662 -221.296,-27.662 -73.765,0 -147.53,27.662 -221.296,27.662 -73.765,0 -147.53,-27.662 -221.295,-27.662 -73.765,0 -147.53,27.662 -221.296,27.662 -73.765,0 -147.53,-27.662 -221.295,-27.662 -73.54,0 -147.079,27.49 -220.619,27.658 25.494,-29.84 30.119,-61.425 -0.516,-76.499 -69.556,-34.225 -40.441,-137.117 -168.281,-144.344 -127.841,-7.226 -197.109,67.562 -186.722,153.564 2.515,20.822 7.328,38.886 14.915,54.45l-102.664 12.833 0 -497.915z"/> </clipPath> </defs> <image width="1770" href="https://via.placeholder.com/1920x540" clip-path="url(#cp1)" /> </svg>
As commented: clip-path is not responsive .wrapt { position: relative; } .bannt { display: block; width: 100%; height: auto; clip-path: url(#cp1); border: 1px solid red; } .clipped { width: 100%; -webkit-clip-path: url(#my-clip-path); clip-path: url(#my-clip-path); } <div class='wrapt'> <svg width="0" height="0" viewBox="0 0 1770.365 497.915"> <defs> <clipPath id="cp1"> <path class="fil0" d="M0 0h1770.4v497.9c-73.8 0-147.6-27.6-221.3-27.6s-147.6 27.6-221.3 27.6s-147.6-27.6-221.3-27.6s-147.6 27.6-221.3 27.6s-147.5-27.6-221.3-27.6c-73.6 0-147.1 27.4-220.6 27.6c25.5-29.8 30.1-61.4-0.5-76.5c-69.6-34.2-40.5-137.1-168.3-144.3s-197.1 67.5-186.8 153.5c2.6 20.9 7.4 38.9 15 54.5l-102.7 12.8v-497.9z"/> </clipPath> <clipPath id="my-clip-path" clipPathUnits="objectBoundingBox"> <path d="M0,0 l1,0,0,1 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.056,-0.125,0.056 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.056,-0.125,0.056 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.055,-0.125,0.056 c0.014,-0.06,0.017,-0.123,0,-0.154 c-0.039,-0.069,-0.023,-0.275,-0.095,-0.29 c-0.072,-0.015,-0.111,0.136,-0.105,0.308 c0.001,0.042,0.004,0.078,0.008,0.109 l-0.058,0.026,0,-1"></path> </clipPath> </defs> </svg> <img class='bannt' src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Crect x='0' y='0' width='100%' height='100%' fill='%23ccc' stroke='%23999' stroke-width='12' /%3E%3Ctext x='50%' y='50%' font-family='sans-serif' font-size='24' fill='%23999' dominant-baseline='middle' text-anchor='middle'%3E 240 %C3%97 240 %3C/text%3E%3C/svg%3E"> <img class='bannt --clipped' src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1920' height='540'%3E%3Crect x='0' y='0' width='100%' height='100%' fill='%23ccc' stroke='%23999' stroke-width='27' /%3E%3Ctext x='50%' y='50%' font-family='sans-serif' font-size='54' fill='%23999' dominant-baseline='middle' text-anchor='middle'%3E 1920 %C3%97 540 %3C/text%3E%3C/svg%3E"> </div> For a responsive clip-path you need to optimize it img{ max-width:100%; } .clipped { width: 100%; -webkit-clip-path: url(#my-clip-path); clip-path: url(#my-clip-path); } .resize{ width: 50%; height: auto; padding:1em; overflow:auto; border:1px solid green; resize:both; } <p>Clip path optimized with: https://yoksel.github.io/relative-clip-path/</p> <p>Resize me</p> <div class="resize"> <svg class="svg" width="0" height="0"> <clipPath id="my-clip-path" clipPathUnits="objectBoundingBox"> <path d="M0,0 l1,0,0,1 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.056,-0.125,0.056 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.056,-0.125,0.056 c-0.042,0,-0.083,-0.056,-0.125,-0.056 c-0.042,0,-0.083,0.055,-0.125,0.056 c0.014,-0.06,0.017,-0.123,0,-0.154 c-0.039,-0.069,-0.023,-0.275,-0.095,-0.29 c-0.072,-0.015,-0.111,0.136,-0.105,0.308 c0.001,0.042,0.004,0.078,0.008,0.109 l-0.058,0.026,0,-1"></path> </clipPath> </svg> <img class='clipped' src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1920' height='540'%3E%3Crect x='0' y='0' width='100%' height='100%' fill='%23ccc' stroke='%23999' stroke-width='27' /%3E%3Ctext x='50%' y='50%' font-family='sans-serif' font-size='54' fill='%23999' dominant-baseline='middle' text-anchor='middle'%3E 1920 %C3%97 540 %3C/text%3E%3C/svg%3E" alt='img'> </div> Further reading: About clip-path caveats and pitfalls Paul LeBeau's solution: "Complex SVG clip-path responsive" Eric Meyer: Scaling SVG Clipping Paths for CSS Use Css-tricks: Unfortunately, clip-path: path() is Still a No-Go Css-tricks: Clipping and Masking in CSS Clip path helper Yoksel's clip-path generator
CSS - inline SVG interferes with line-height?
I'm struggling to understand the the following css behavior. Maybe I'm missing something important because this actually seems like a simple scenario to me. Consider the following example: .container { background-color: lime; font-size: 20px; line-height: 20px; } <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" > <circle cx="12" cy="12" r="10"/> </svg> Text </div> Because container has line-height: 20px set, I'd expect it to be 20px high. At least this is the case if it only contains text. With the svg however it is suddenly 24px high, even though the svg is 20px high, as expected because of height=1em. Also the "Text" has a height of 23px, even though I'd expect it to be 20px. Interestingly, if I set container's line-height to something like 30px, it behaves as expected: container is now 30px high. Can you help me understand why container is not 20px high? Or is line-height simply not easily predictable once the container contains other elements than just plain text? Thank you!
There are two things going on in your demo that are affecting the height of div.container. First, line-height isn't an explicit, fixed height: it specifies the minimum height of line boxes within div.container in your case. Since line-height is a minimum, it can grow if something inside it causes it to grow. That leads to the SVG: it has a default vertical-align of baseline, which aligns it to the baseline of div.container, and, due to its height, causes the height of div.container to grow to accommodate it. By changing vertical-align of the SVG to something else so it fits within your 20px line-height, you can make it fit. I've added a few different vertical-align props to your demo so you can see how alignment affects height. In general, bottom and top align the svg to the bottom and top of the line, respectively, which, given the SVG's 20px height, keep it within the line-height. However, if you really, really need div.container to be 20px height, height or max-height are probably better bets. .container { background-color: lime; font-size: 20px; line-height: 20px; margin-bottom: 1em; } <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" > <circle cx="12" cy="12" r="10"/> </svg> Default: vertical-align: baseline (24px) </div> <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" style="vertical-align:middle"> <circle cx="12" cy="12" r="10"/> </svg> Default: vertical-align: middle (~22px) </div> <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" style="vertical-align:bottom"> <circle cx="12" cy="12" r="10"/> </svg> Default: vertical-align: bottom (20px) </div> <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" style="vertical-align:top"> <circle cx="12" cy="12" r="10"/> </svg> Default: vertical-align: top (20px) </div>
This gets all heights to 20px using flex, align-items: center; and line-height: 1rem;: .container { background-color: lime; font-size: 20px; line-height: 1rem; display: flex; align-items: center; } <div class="container"> <svg width="1em" height="1em" viewBox="0 0 24 24" > <circle cx="12" cy="12" r="10"/> </svg> Text </div>
How to change font-size to a SVG?
I'm using a svg icon on my website. here's the code I got from Adobe Illustrator: <svg id="Livello_1" data-name="Livello 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg> I've been able to change its color (in my css fill:#33453a;) but not its size (I tried with both font-size and width, but none of them worked). The reason why I'm trying to do so is that I need an icon which color and size can be changed in :hover status.
This might be a tricky question. What you are intending to do is not possible as other people pointed out, but not being possible with font-size doesn't mean it is not possible to get it working as you are expecting. If you look into a big project like react-icons you can get a glimpse of how they do it. const computedSize = size || conf.size || "1em"; let className; if (conf.className) className = conf.className; if (props.className) className = (className ? className + ' ' : '') + props.className; return ( <svg stroke="currentColor" fill="currentColor" strokeWidth="0" {...conf.attr} {...attr} {...svgProps} className={className} style={{ color: props.color || conf.color, ...conf.style, ...props.style}} height={computedSize} width={computedSize} xmlns="http://www.w3.org/2000/svg" > {title && <title>{title}</title>} {props.children} </svg> ) }; So you might have something similar like: <span style="font-size: 14px">hi <svg ...></svg></span>. The trick is to assign with and height the em unit, which stands for ephemeral unit don't be confused with rem, you can read more about his in this post What the em unit will do in your browser is to look at the closest definition of font-size and attach that one to the SVG context, that is how you get the same dimension. Solution: add width:1em and height:1em <svg height="1em" width="1em" id="Livello_1" data-name="Livello 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg>
You can not change the font size or font width because SVG is not a font. It is Scalable Vector Graphics. If you would have some text in your SVG then you could do something with the font from the text element. In your case you have to add attribute width and height for SVG. And in hover of SVG you can change it like follows: #Livello_1:hover { fill:#33453a; width:48px; height:48px } <svg id="Livello_1" width="36" height="36" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448.05 436.7"><path d="M190.5,66.9l22.2-22.2a23.9,23.9,0,0,1,33.9,0L441,239a23.9,23.9,0,0,1,0,33.9L246.6,467.3a23.9,23.9,0,0,1-33.9,0l-22.2-22.2a24,24,0,0,1,.4-34.3L311.4,296H24A23.94,23.94,0,0,1,0,272V240a23.94,23.94,0,0,1,24-24H311.4L190.9,101.2A23.85,23.85,0,0,1,190.5,66.9Z" transform="translate(0 -37.65)"/></svg> To see the effect you have to move your mouse cursor over this SVG (in snippet, wich must be runned).
Since it does not contain a text with font, the better way is to use scale to increase the size. : <style> svg { transform: scale(1.3); } </style>
I guess you need to align and scale your svg icon relative to your font size. It is kind of a 'team play' between svg and css: In css we make sure our svg has a inline-block context, a height relative to the inherited font-sizes. In svg we use seperate viewBox attributes for each icon. If you need to adjust the baseline alignment or dimensions on :hover you need to avoid layout shifts e.g vertical-align would also some kind of leading to the next line – therefore we use a relative position and bottom offset. /* just an example code to illustrate the scalability */ const fontSize= document.querySelector('.fontSize'); const layout = document.querySelector('.layout'); fontSize.addEventListener('change', function(e) { let currentSize = +e.target.value; layout.setAttribute('style', 'font-size:'+(1+currentSize)+'em'); }); /* svg will behave similarly to a character/glyph */ .svg-inline { display: inline-block; /* without a custom viewbox we have a square aspect ratio as default */ height: 1em; width: 1em; } /** * optional adjustment: * font-size: if icons are too big * vertical baseline offset **/ .svg-adjust { font-size: 0.75em; position: relative; bottom: -0.1em; transition: 0.3s; } /* set size by viewbox if present */ .svg-inline[viewBox] { width: auto; } .svg-inline-assets{ display:none } a:hover .svg-inline { fill: green; transform: scale(1.5); margin-left: 0.5em; margin-right: 0.5em; } /* example layout */ html { font-family: "Segoe UI"; font-size: calc(1vw + 1vh /2); line-height: 1.4em; } .layout { width: 50%; margin: 0 auto; font-size: 1.5em; line-height: 1.4em; } p { margin: 0; } a { text-decoration: none; color: inherit; border-bottom: 2px solid #aaa; } a .svg-inline { fill: #aaa; } .button { font-size: 1.333em; line-height: 1em; background-color: #aaa; border: 2px solid #aaa; color: #fff; cursor: pointer; margin-top: 1rem; padding: 0.3em; } .button .svg-inline { fill: #fff; } .input-range { width: 100%; } <main class="layout"> <h3>Change font Size</h3> <p> <input class="input-range fontSize" type="range" value="0" min="-0.5" max="0.5" step="0.1"> </p> <svg class="svg-inline-assets" viewBox="0 0 100 100"> <!-- every asset has it's own viewbox: this way we can place icons with different widths --> <symbol id="fa-arrow-right-asset" viewBox="0 0 100 100"> <path d="M42.5,7.8l5-5c2.1-2.1,5.5-2.1,7.5,0c0,0,0,0,0,0l43.4,43.4c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0L55,97.2c-2.1,2.1-5.5,2.1-7.5,0c0,0,0,0,0,0l-5-5c-2.1-2.1-2.1-5.5,0-7.6c0,0,0.1-0.1,0.1-0.1l26.9-25.6H5.4c-3,0-5.3-2.4-5.4-5.3c0,0,0,0,0,0v-7.1c0-3,2.4-5.3,5.3-5.4c0,0,0,0,0,0h64.1L42.6,15.5c-2.1-2-2.2-5.4-0.2-7.5C42.4,7.9,42.5,7.8,42.5,7.8z" /> </symbol> <symbol id="fa-arrow-right-long-asset" viewBox="0 0 200 100"> <path d="M141.1,7.8l5-5c2.1-2.1,5.5-2.1,7.5,0c0,0,0,0,0,0L197,46.2c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0l-43.4,43.4c-2.1,2.1-5.5,2.1-7.5,0c0,0,0,0,0,0l-5-5c-2.1-2.1-2.1-5.5,0-7.6c0,0,0.1-0.1,0.1-0.1l26.9-25.6H5.4c-3,0-5.3-2.4-5.4-5.3c0,0,0,0,0,0v-7.1c0-3,2.4-5.3,5.3-5.4c0,0,0,0,0,0h162.7l-26.9-25.6c-2.1-2-2.2-5.4-0.2-7.5C141,7.9,141,7.8,141.1,7.8z" /> </symbol> <!-- this arrow has a x offset of 200: without it's own viewbox it would be cropped --> <symbol id="fa-arrow-right-long-offset-asset" viewBox="200 0 200 100"> <path d="M341.1,7.8l5,-5c2.1,-2.1,5.5,-2.1,7.5,0c0,0,0,0,0,0l43.4,43.4c2.1,2.1,2.1,5.5,0,7.5c0,0,0,0,0,0l-43.4,43.4c-2.1,2.1,-5.5,2.1,-7.5,0c0,0,0,0,0,0l-5,-5c-2.1,-2.1,-2.1,-5.5,0,-7.6c0,0,0.1,-0.1,0.1,-0.1l26.9,-25.6h-162.7c-3,0,-5.3,-2.4,-5.4,-5.3c0,0,0,0,0,0v-7.1c0,-3,2.4,-5.3,5.3,-5.4c0,0,0,0,0,0h162.7l-26.9,-25.6c-2.1,-2,-2.2,-5.4,-0.2,-7.5c0.1,0,0.1,-0.1,0.2,-0.1z" /> </symbol> <symbol id="fa-arrow-right-narrow-asset" viewBox="0 0 60 100"> <path d="M57.5,46.2L14.1,2.8c0,0,0,0,0,0c-2.1-2.1-5.5-2.1-7.5,0l-5,5c0,0-0.1,0.1-0.1,0.1c-2,2.1-1.9,5.5,0.2,7.5l37,34.5l-37,34.5c0,0-0.1,0.1-0.1,0.1c-2.1,2.1-2.1,5.5,0,7.6l5,5c0,0,0,0,0,0c2.1,2.1,5.5,2.1,7.5,0l43.4-43.4c0,0,0,0,0,0C59.6,51.7,59.6,48.3,57.5,46.2z" /> </symbol> </svg> <h2>Svg inlined icon</h2> <p><svg class="svg-inline"> <use href="#fa-arrow-right-asset" /> </svg>No vertical adjustment. One morning, when <svg class="svg-inline svg-adjust"> <use href="#fa-arrow-right-asset" /> </svg> Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a <a href="#"><svg class="svg-inline svg-adjust" viewBox="0 0 200 100"> <use href="#fa-arrow-right-long-asset" /> </svg> little he could see his brown belly</a>, slightly domed and divided by arches into stiff sections. <svg class="svg-inline svg-adjust" viewBox="0 0 200 100"> <use href="#fa-arrow-right-long-offset-asset" /> </svg> Long arrow with offset. </p> <p>The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with <svg class="svg-inline svg-adjust" viewBox="0 0 60 100"> <use href="#fa-arrow-right-narrow-asset" /> </svg> the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream. </p> <p> <button class="button" type="button"> <svg class="svg-inline svg-adjust" viewBox="0 0 60 100"> <use href="#fa-arrow-right-narrow-asset" /> </svg> Button </button> <button class="button" type="button"> <svg class="svg-inline svg-adjust"> <use href="#fa-arrow-right-asset" /> </svg> </button> <button class="button" type="button"> <svg class="svg-inline svg-adjust" viewBox="0 0 200 100"> <use href="#fa-arrow-right-long-asset" /> </svg> </button> </p> </main>
You can try setting width and height for svg tag. Working link is here
add to svg transform="scale(1.7)" for zoon in <svg transform="scale(1.7)" width="16px" height="24px" version="1" viewBox="0 0 700 700" xmlns="http://www.w3.org/2000/svg" >
how to float an underlying div to a svg
I am trying to let float an underlying div to a svg. problem is: when i reduce the screenwidt, the distance between the svg and the underlying div increases. How can i achieve that the div under the svg always floats against the svg without whitespace? This is my code: <div class="svg"> <svg viewBox="0 0 1439 150" style="position:fixed; top:250px; left:0;" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Sell-on-FG-Flow" transform="translate(-1.000000, -2412.000000)" fill="#1e90ff"> <g id="Customer-Section" transform="translate(1.000000, 1026.000000)"> <g id="loading" transform="translate(0.000000, 1386.807849)"> -----pathes are here --- </g> </g> </g> </g> </svg> </div> <div class="under"> let the red div float against the waves </div> And the css: .svg { height: 400px; width: 100%; } .under { height: 40px; background: red; } Fiddle: https://jsfiddle.net/45b3n5q8/1/
Position fixed inline style in the SVG removes the element from the document flow and it will behave like an absolute position, remove the inline style from the svg and it should be ok, there's a small margin that can be removed with a negative margin top. .under { background: red; margin-top: -5px; } see pen