【发布时间】:2017-11-07 21:25:24
【问题描述】:
我想在 position:fixed div 中显示 SVG 图像。我有
<div class="main">
<svg class="svg" viewBox="0 0 180 100">
<rect height="100%" width="100%" fill="#003300"></rect>
</svg>
</div>
风格
.main {
position:fixed;
left: 100px;
height: 100%;
width:100%;
background: #33AAAA;
}
.svg {
display: block;
height: 100%;
width: 100%;
position:static;
}
我想将 SVG 水平和垂直居中。我有一个奇怪的行为。更改浏览器窗口的大小,表明当 svg 小于可用宽度时,它被奇怪地放置。例如: 左边比右边多。
Codepen(包括 CSS 重置):Codepen
【问题讨论】:
-
你还剩:100px;在主课上。这就是为什么你的 svg 左边是空的。
-
这不是重点。我想将深绿色矩形放在浅色矩形的中心。也许左派有事可做……
-
答案可能就在那里https://stackoverflow.com/questions/41822510/center-an-svg-inside-a-div?rq=1 我正在测试它