【发布时间】:2017-07-11 13:35:06
【问题描述】:
我现在正在玩 svg 和 flexbox,我想在居中的 svg 上堆叠一张图片。
图像应该在 svg 的中心,我还想实现图像与 svg 成比例地缩放。
是否可以使用 flexbox 来实现这一点,还是我应该考虑其他方法?
HTML:
<div class="container">
<div class="main">
<div class="spotlight">
<img src="https://www.stadiumgoods.com/media/catalog/product/cache/1/base/1000x600/9df78eab33525d08d6e5fb8d27136e95/3/6/365054_02_1.png" alt="sneaker" class="sneaker" />
<svg id="circle-bg" viewBox="0 0 100 100">
<circle fill="#F8F5F5" cx="50" cy="50" r="50"></circle>
</svg>
</div>
</div>
</div>
CSS:
body {
background-color: #EBEBED;
margin: 0;
}
.main {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.spotlight {
width: 50vw;
max-height: 75vh;
}
.sneaker {
position: absolute;
width: 50%;
}
#circle-bg {
height: 75vh;
}
JSFiddle:https://jsfiddle.net/hvgom8o3/
预期结果:
【问题讨论】:
标签: javascript html css svg