I am trying to display an SVG image inside a fixed-position div. Here is the HTML:
<div class="main">
<svg class="svg" viewBox="0 0 180 100">
<rect height="100%" width="100%" fill="#003300"></rect>
</svg>
</div>
and CSS styling for it:
.main {
position:fixed;
left: 100px;
height: 100%;
width:100%;
background: #33AAAA;
}
.svg {
display: block;
height: 100%;
width: 100%;
position:static;
}
I want the SVG to be centered both horizontally and vertically, but I am encountering some strange behavior. When the browser window size changes, the SVG is not properly centered, as shown here: https://i.stack.imgur.com/DdKo6.png there is more space on the left than on the right.
You can view the Codepen version (including CSS reset) here: Codepen