Spacing between inline-block [duplicate] - html

This question already has answers here:
inline-block boxes not fitting in their container [duplicate]
(2 answers)
Closed 6 years ago.
Codepen here.
As the snippet shows, the first element and second one have no spacing between them, but the third one have, I don't know if it's a CSS problem or a SVG problem. I got same result on Chrome and MS Edge.
CSS here:
.controls-inline {
display: inline-block;
}
HTML here:
<div id="ctrl-panel">
<div class="controls-inline controls-btn" id="play-btn-wrapper">
<svg id="play-btn" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 58 58" xml:space="preserve" width="50px" height="50px">
<circle style="fill:#EBBA16;" cx="29" cy="29" r="29"></circle>
<g>
<polygon id="play-btn-polygon" style="fill:#FFFFFF;" points="44,29 22,44 22,29.273 22,14 "></polygon>
<path style="fill:#FFFFFF;" d="M22,45c-0.16,0-0.321-0.038-0.467-0.116C21.205,44.711,21,44.371,21,44V14
c0-0.371,0.205-0.711,0.533-0.884c0.328-0.174,0.724-0.15,1.031,0.058l22,15C44.836,28.36,45,28.669,45,29s-0.164,0.64-0.437,0.826
l-22,15C22.394,44.941,22.197,45,22,45z M23,15.893v26.215L42.225,29L23,15.893z"></path>
</g>
</svg>
</div>
<div class="controls-inline" id="progressbar-wrapper" style="margin-right: 0px;">
<svg id="progressbar" width="675" height="50" preserveAspectRatio="none">
<g>
<path d="M25,1 a23,23 0 1,0 0,48 l625,0 a23,23 0 0,0 0,-48 z" stroke="#EBBA16" stroke-width="2px" fill="white">
</path>
</g>
</svg>
</div>
<div class="controls-inline controls-btn">
<svg version="1.1" id="volumn-btn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="50px" height="50px" viewBox="0 0 58 58" style="enable-background:new 0 0 58 58;" xml:space="preserve">
<circle style="fill:#EBBA16;" cx="29" cy="29" r="29"></circle>
<path style="fill:white;" d="M16.427,20H8.104C6.942,20,6,20.942,6,22.104v12.793C6,36.058,6.942,37,8.104,37h8.323
c0.375,0,0.743,0.1,1.067,0.29L30.83,49.706C32.232,50.531,34,49.52,34,47.893V9.107c0-1.627-1.768-2.638-3.17-1.813L17.494,19.71
C17.17,19.9,16.802,20,16.427,20z"></path>
<path style="fill:white;" d="M41.541,42.042c-0.256,0-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414
c6.238-6.238,6.238-16.39,0-22.628c-0.391-0.391-0.391-1.023,0-1.414s1.023-0.391,1.414,0c7.018,7.019,7.018,18.438,0,25.456
C42.052,41.944,41.796,42.042,41.541,42.042z"></path>
<path style="fill:white;" d="M38,38c-0.256,0-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414
c4.297-4.297,4.297-11.289,0-15.586c-0.391-0.391-0.391-1.023,0-1.414s1.023-0.391,1.414,0c5.077,5.077,5.077,13.337,0,18.414
C38.512,37.902,38.256,38,38,38z"></path>
</svg>
</div>
</div>

Elements have by default some spacing inbetween them.
You can fix this when trying to make layouts through display: inline-block in at least a few different ways:
font-size: 0 on the parent .ctrl-panel in your case.
Negative margin-left on every inline block element (f.e. margin-left: -.25rem; seems to work on your layout on that third element)
Remove empty spaces on the html markup (this is why your first two elements are together and the third one is not, if your markup is like </div><div> there won't be any spacing).
Use an alternative method for layouts like float which will not take into account these in-between element spacings.

Remove the white space in the code between your divs. Inline elements are sensitive to that spacing.
</div><div
codepen example

Related

Why is there extra white space in this svg?

I how do I remove the extra whitespace in this svg? When I inspect the blue curve is is the path and the highlighted blue is the entire svg. I don't understand I tried adjusting the view box and a couple different properties it didn't work?
The .grey-curve-svg is just an empty div with no styles.
Here is the svg:
<div class="grey-curve-svg">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
<path fill="#0099ff"
fill-opacity="1"
style="--darkreader-inline-fill:#007acc;"
data-darkreader-inline-fill=""
d="M0,320L120,298.7C240,277,480,235,720,234.7C960,235,1201,277,1320,298.7L1440,320L1440,320L1320,320C1200,320,960,320,720,320C480,320,240,320,120,320L0,320Z"
></path>
</svg>
</div>
The viewBox determines the visible dimensions in the SVG.
Yours is 0 0 1440 320 (min-x, min-y, width and height). You can alter it to crop the contents of the svg. Something like viewBox="0 230 1440 100" looks like it fits better
<div class="grey-curve-svg">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 230 1440 100">
<path fill="#0099ff"
fill-opacity="1"
style="--darkreader-inline-fill:#007acc;"
data-darkreader-inline-fill=""
d="M0,320L120,298.7C240,277,480,235,720,234.7C960,235,1201,277,1320,298.7L1440,320L1440,320L1320,320C1200,320,960,320,720,320C480,320,240,320,120,320L0,320Z"
></path>
</svg>
</div>
The viewBox area has a lot of blank space in it at the top. Adjusting the viewBox dimensions can fix that...
<div class="grey-curve-svg">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 230 1440 320">
<path fill="#0099ff"
fill-opacity="1"
style="--darkreader-inline-fill:#007acc;"
data-darkreader-inline-fill=""
d="M0,320L120,298.7C240,277,480,235,720,234.7C960,235,1201,277,1320,298.7L1440,320L1440,320L1320,320C1200,320,960,320,720,320C480,320,240,320,120,320L0,320Z"
></path>
</svg>
</div>
Previous answers said to alter the viewBox, yet simply viewbox="0 0 1 1" worked for me as my child graphics superseded those dimensions.

How do you get HTML to adjust to SVG scaling

When I scale an SVG using the scale transform, the surrounding html does not respect this scale and fails to adjust its size.
I have the following SVG:
<div>
<svg height="300" width="300" viewbox="0 0 300 300" transform="scale(1.55)"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<circle r="150px" cx="150px" cy="150px" fill="orange"/>
</svg>
</div>
<div>
<svg height="300" width="300" viewbox="0 0 300 300" transform="scale(1.55)"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<circle r="150px" cx="150px" cy="150px" fill="green"/>
</svg>
</div>
For some reason the surrounding html doesn't adjust for the scaled up Svg.
All my testing so far has been on chrome and using primarily Svg declared in millimeter units.
When tested, the above example with the scale transform, the two circles overlap.
Without the transform they do not.
I want them NOT to overlap when scaled.
How can I get the Html to correctly adjust with the scaling of Svg?
Thanks in advance.
You have set fixed height and width and fixed pixels for your svg.
You have to change the properties of your svg and the actual circle path to correct it like in my example.
the transform property is something you don't need here in my opinion!
Try to change that and your HTML will surround like you want.
<div>
<svg height="100" width="100" viewbox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<circle r="100px" cx="100px" cy="100px" fill="orange"/>
</svg>
</div>
<div>
<svg height="100" width="100" viewbox="0 0 200 200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<circle r="100px" cx="100px" cy="100px" fill="green"/>
</svg>
</div>
That should do the job!
I think the problem is that, in SVG 1.1, I believe it wasn't properly defined how a transform attribute behaved when placed on a root <svg> element.
In SVG2 it has been. The behavior is defined in the CSS Transforms specification.
Chrome seems to have implemented that, but Firefox hasn't yet done so for SVGs. The behaviour in Chrome seems correct. transform on <svg> elements behaves the same as an HTML element (see example below).
<div>
<svg height="300" width="300" viewbox="0 0 300 300" transform="scale(1.55)"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xml="http://www.w3.org/XML/1998/namespace" version="1.1">
<circle r="150px" cx="150px" cy="150px" fill="orange"/>
</svg>
</div>
<div>
<div style="width:300px; height:300px; background-color:green; border-radius:50%; transform:scale(1.55)">
</div>
</div>

best way to implement anchor tag with an svg inside and text

I want to put together a button which has an svg and then some text.
I have implemented it as followed
<a class="btn btn-subtle-icon">
<div class="icon-archive">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="21px" height="21px" viewBox="0 0 21 21" enable-background="new 0 0 21 21" xml:space="preserve">
<g>
<path fill="#797979" d="M17.6,5.5c0-1-1-1-1-1H4.4c0,0-1,0-1,1v1h14.2V5.5z M14.6,2.5H6.4c0,0-1,0-1,1h10.2
C15.6,2.5,14.6,2.5,14.6,2.5z M19.6,6.5C19,5.9,19,5.9,19,5.9v1.6H2V5.9c0,0,0,0-0.6,0.6c-0.6,0.6-1,0.8-0.8,2
c0.2,1.2,1.4,8.1,1.6,9c0.2,1,1.2,1,1.2,1h14.2c0,0,1.1,0,1.2-1c0.2-0.9,1.3-7.8,1.6-9C20.7,7.3,20.2,7.1,19.6,6.5z M14.6,11.9
c0,0,0,1-1,1H7.5c-1,0-1-1-1-1v-2h1.4v1.6h5.3V9.9h1.4V11.9z"/>
</g>
</svg>
</div>
You can find some of the older CodeClub projects or Partner projects in the archives.
</a>
The div icon-archive is simply applying display: inline-block; and the btn and btn-subtle-icon are just expanded bootstrap classes.
The trouble I am having comes when I want to start moving up the image or the text to make them align better.
When I attempt to add margin to the svg it just moves the svg and the text down at the same time.
Can anyone point me in the direction of what I’m doing wrong or a better solution?
Much appreciated.
The first mistake you do is putting <div> inside <a>. Change it to:
<a class="btn btn-subtle-icon">
<span class="icon-archive">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg">
</svg>
</span>
</a>
Try separating them and make them float.
<a class="btn btn-subtle-icon">
<div class="icon-archive">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="21px" height="21px" viewBox="0 0 21 21" enable-background="new 0 0 21 21" xml:space="preserve">
<g>
<path fill="#797979" d="M17.6,5.5c0-1-1-1-1-1H4.4c0,0-1,0-1,1v1h14.2V5.5z M14.6,2.5H6.4c0,0-1,0-1,1h10.2
C15.6,2.5,14.6,2.5,14.6,2.5z M19.6,6.5C19,5.9,19,5.9,19,5.9v1.6H2V5.9c0,0,0,0-0.6,0.6c-0.6,0.6-1,0.8-0.8,2
c0.2,1.2,1.4,8.1,1.6,9c0.2,1,1.2,1,1.2,1h14.2c0,0,1.1,0,1.2-1c0.2-0.9,1.3-7.8,1.6-9C20.7,7.3,20.2,7.1,19.6,6.5z M14.6,11.9
c0,0,0,1-1,1H7.5c-1,0-1-1-1-1v-2h1.4v1.6h5.3V9.9h1.4V11.9z"/>
</g>
</svg>
</div>
<div class="text">
You can find some of the older CodeClub projects or Partner projects in the archives.
</div>
</a>
.icon-archive{
float:left;
}
.text{
float:left;
margin-left: 5px;
}
http://jsfiddle.net/Dhanck/zqn1b53e/1/

SVG not working properly in IE9

i'm having an issue with 3 SVG icons, and i don't know exactly why, because the same css is being apply in other icons, but they are working 100%.
The following problem is happening in IE9:
Chrome:
http://i.stack.imgur.com/gYfsb.png
IE9:
http://i.stack.imgur.com/q2220.png
In my search i found that i need add this metadata in the SVG tag:
xmlns="http://www.w3.org/2000/svg" version="1.1"
But didn't work.
The other icons is from fontastic
The codes:
1:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="20px" viewBox="0 0 512 512">
<path d="M340.377,292.154H227.178v-124.4h36v88.4h77.199V292.154z M389.404,378.858 c29.393-32.142,47.327-74.937,47.327-121.924c0-99.814-80.915-180.73-180.731-180.73c-99.815,0-180.73,80.916-180.73,180.73 c0,46.986,17.935,89.781,47.326,121.924c-9.047,22.51-20.913,52.037-28.938,72.002c-1.211,3.014-0.317,6.465,2.204,8.513 s6.086,2.219,8.786,0.413c18.391-12.305,45.747-30.606,65.463-43.797c25.548,13.824,54.801,21.677,85.889,21.677 s60.342-7.853,85.89-21.677l65.463,43.797c2.701,1.807,6.264,1.643,8.786-0.404c2.523-2.047,3.418-5.499,2.206-8.515 L389.404,378.858z M256,392.666c-75.013,0-135.73-60.707-135.73-135.731c0-75.013,60.706-135.73,135.73-135.73c75.013,0,135.731,60.704,135.731,135.73C391.731,331.945,331.026,392.666,256,392.666z M174.875,62.454c-12.251-7.292-26.556-11.491-41.848-11.491c-45.287,0-82,36.713-82,82c0,15.057,4.068,29.158,11.153,41.284C83.734,123.916,124.338,83.614,174.875,62.454z M449.82,174.246c7.085-12.126,11.152-26.227,11.152-41.283c0-45.287-36.713-82-82-82c-15.292,0-29.597,4.199-41.847,11.491C387.662,83.613,428.266,123.916,449.82,174.246z"></path>
</svg>
2:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 512 512" width="20px">
<path d="M407.448,360.474c-59.036-13.617-113.989-25.541-87.375-75.717c81.01-152.729,21.473-234.406-64.072-234.406c-87.231,0-145.303,84.812-64.072,234.406c27.412,50.482-29.608,62.393-87.375,75.717c-59.012,13.609-54.473,44.723-54.473,101.176h411.838C461.919,405.196,466.458,374.083,407.448,360.474z"></path>
</svg>
3:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="20px" viewBox="0 0 512 512">
<path d="M407.447,380.817c-50.919-11.622-112.919-41.622-94.652-80.682c11.732,19.236,48.084,30.361,76.4,13.736c-81.506-20.57,40.066-161.795-66.458-240.959c-38.877-29.041-95.209-29.373-133.474,0c-106.524,79.164,15.048,220.389-66.458,240.959c28.316,16.625,64.723,5,76.4-13.736c18.268,39.064-43.786,69.072-94.652,80.682c-59.041,13.475-54.473,52.025-54.473,80.176h411.838C461.919,432.843,466.489,394.294,407.447,380.817z"></path>
</svg>
I don't believe this is a problem with the CSS, because the other icons is with the same style.
Have you tried setting a height or at least a max-height? It's hard to say without seeing the code for the page, but it looks like the SVG element is taller than it needs to be (with the image itself scaling down into the center based on the width you've applied).

How to position an SVG canvas

I cannot figure out for the life of me how to position an SVG element on a page. I spent a good hour reading Sara Soueidan tutorial on positioning the inner contents of an SVG element inside the viewport of the SVG, but I cannot find anywhere how you would position the viewport on the page. I tried wrapping my SVG inside a div and floating the div (to no avail):
<div id="svg-left">
<svg id="angle-left" class="angle" xmlns="http://www.w3.org/2000/svg" width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<polygon points="352,115.4 331.3,96 160,256 331.3,416 352,396.7 201.5,256 "/>
</svg>
</div>
This seems like such a simple concept, but I cannot find an answer anywhere.
You can position an <svg> element the same as any other HTML element. You can float them, use absolute positioning, etc.
Here's a demo:
#angle-left
{
float: right;
}
#angle-left2
{
position: absolute;
left: 200px;
bottom: 100px;
}
<svg id="angle-left" class="angle" xmlns="http://www.w3.org/2000/svg" width="100px" height="100px" viewBox="0 0 512 512">
<polygon points="352,115.4 331.3,96 160,256 331.3,416 352,396.7 201.5,256 "/>
</svg>
<svg id="angle-left2" class="angle" xmlns="http://www.w3.org/2000/svg" width="100px" height="100px" viewBox="0 0 512 512">
<polygon points="352,115.4 331.3,96 160,256 331.3,416 352,396.7 201.5,256 "/>
</svg>
(I reduced the on screen size of the SVGs to make the positioning more obvious).