[Solved] vertical center svg in div container

Can you help me to understand why my svg refuse to resize the height for helping me to center vertically in a div container ?

How can I process for align vertical svg in a container ? I seem to svg behaviour is not standard like div…

The main idea is that center horizontally AND vertically svg into a div.

I try this : https://jsfiddle.net/gbz7rp7u/1/#&togetherjs=0n9iL62pHv

<div id="svg-container">
  <svg id="svg-1" height="50%" width="50%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1">
     <circle r="15" cx="350" cy="80"></circle>
  </svg>
</div>

#svg-container
{
  background-color: red;
}

#svg-1
{
  margin: auto auto;
  display: block;
  height: 30%;
}
Enquirer: darkomen

||

Solution #1:

html, body {
   height: 100%;  
}
#svg-container
{
  display: flex;
  align-items: center;
  background-color: red;
  height: 100%;
}

#svg-1
{
  margin: 0 auto;
  display: block;
}
<div id="svg-container">
  <svg id="svg-1" height="15px" width="15px" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" version="1.1">
     <circle r="15" cx="15" cy="15"></circle>
  </svg>
</div>

Respondent: Mehrad

Solution #2:

html, body {
   height: 100%;  
}

#svg-container {
  background-color: red;
  height: 100%;
}

#svg-1 {
  display: block;
  margin: auto;
  height: 100%;
}
<div id="svg-container">
  <svg id="svg-1" height="15px" width="15px" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" version="1.1">
     <circle r="15" cx="15" cy="15"></circle>
  </svg>
</div>

Respondent: Anton Novik

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.