CSS - inline SVG interferes with line-height? - html
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>
Related
Flex space around does not respond
HTML CODES I cannot use 'space-around' property.It does not work even if I wrap tag 'a' and 'svg' with div.How can I solve this problem? .container { width: 300px; } .title { display: flex; flex-direction: space-around; } <div class="container"> <div class="title"> Library <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-bookmark"><path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"></path></svg> </div> </div>
As #Sfili mentioned in the comments, those styles correspond with justify-content and not flex-direction. space-around is supposed to give the elements equal spacing on both sides. So if you had a 300px container. space-around would look like so: space-between on the other hand will space the elements on both ends of the parent. So it would space both items to the start and end of their parent. See below. .container { width: 300px; outline: solid black 1px; } .title { display: flex; justify-content: space-between; } <div class="container"> <div class="title"> Library <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-bookmark"><path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"></path></svg> </div> </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" >
Extra pixels when element is inline
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?
CSS clip-path property having issues with SVG paths
I am trying to use the clip-path css property on a div. The below is a working example that I initially started with .contianer { height: 300px; width: 300px; background: red; display: flex; align-items: center; justify-content: center; } .box { height: 150px; width: 150px; background: white; clip-path: url(#clip); } <div class="contianer"> <div class="box"></div> </div> <svg height="210" width="400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <clipPath id="clip"> <path d="M150 0 L75 200 L225 200 Z" /> </clipPath> </defs> </svg> We now took this example to customize the path as per our needs, and tried making the path using Adobe Illustrator and ended up as below .contianer { height: 300px; width: 300px; background: red; display: flex; align-items: center; justify-content: center; } .box { height: 150px; width: 150px; background: white; clip-path: url(#clip); } <div class="contianer"> <div class="box"> </div> </div> <svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 1536"> <defs> <style xmlns="http://www.w3.org/2000/svg"> .cls-1 { fill: #e6e6e6; } </style> <clipPath id="clip"> <path class="cls-2" d="M1866.25984,246.41732V257.189l-.37795,18.74409s1.52362,14.06693,1.559,14.17323,2.941,11.76378,2.941,11.76378l4.88976,6.66142,4.21654,2.374,7.61811,1.66536,30.685,1.73622h6.30709l29.55118-.5315,1.03052,18.03543v826.22835l-2.19982,27.07087-61.08661.70866-17.43307,2.69291-10.60443,8.27169-3.71053,8.45272-.31669,50.32929-3.93528.69966-443.19685-.28879-1.6919-44.69979-2.7018-16.37188-6.36191-6.8181-19.29163-2.126-43.79528.56693-20.26772-.4252-1.98425-22.8189-.16708-831.685,4.986-34.72441,10.77165-22.96063,18-16.58268,25.38581-8.60007,25.52966-3.0522Z"/> </clipPath> </defs> </svg> The issue as you can see is, the second example does not clip the path. I assume that the d attribute formatting has something to do with the issue. Whenever the path is taken from web sources, the path value is something like this M150 0 L75... whereas from illustrator it becomes as M1866.7,245.9s-1.1.... with decimals and all. I am not sure about relative paths and absolute paths and if that is the cause. I am looking to render the second example correctly. This is the actual clipping path <svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 2048 1536"><defs><style>.cls-1{fill:#e6e6e6;}.cls-2{fill:#f2f2f2;stroke:red;stroke-miterlimit:10;stroke-width:0.5px;}</style></defs><path class="cls-2" d="M1866.25984,246.41732V257.189l-.37795,18.74409s1.52362,14.06693,1.559,14.17323,2.941,11.76378,2.941,11.76378l4.88976,6.66142,4.21654,2.374,7.61811,1.66536,30.685,1.73622h6.30709l29.55118-.5315,1.03052,18.03543v826.22835l-2.19982,27.07087-61.08661.70866-17.43307,2.69291-10.60443,8.27169-3.71053,8.45272-.31669,50.32929-3.93528.69966-443.19685-.28879-1.6919-44.69979-2.7018-16.37188-6.36191-6.8181-19.29163-2.126-43.79528.56693-20.26772-.4252-1.98425-22.8189-.16708-831.685,4.986-34.72441,10.77165-22.96063,18-16.58268,25.38581-8.60007,25.52966-3.0522Z"/></svg>
Your second example does in fact clip the path, but the problem is that the svg path is much larger than the box or even the container. You need to transform (scale) the clipping path to the same dimensions as your html elements. In the svg, you can see that viewBox="0 0 2048 1536" I Don't know what the clipping path should really look like, but if make the following change to your svg file it might start to make sense: <clipPath id="clip" transform="scale(0.1 0.1)"> You probably want to play around with the values of the viewbox and the dimensions of your css to get the correct factors for the clipPath transformation.
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